mirror of https://github.com/apache/jclouds.git
Merge pull request #982 from andrewgaul/simplify-regex-replace
Simplify regular expression replacement
This commit is contained in:
commit
528eda3e93
|
@ -36,7 +36,7 @@ import com.google.common.base.Function;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ETagFromHttpResponseViaRegex implements Function<HttpResponse, String> {
|
public class ETagFromHttpResponseViaRegex implements Function<HttpResponse, String> {
|
||||||
private static Pattern pattern = Pattern.compile("<ETag>([\\S&&[^<]]+)</ETag>");
|
private static Pattern pattern = Pattern.compile("<ETag>([\\S&&[^<]]+)</ETag>");
|
||||||
private static Pattern quotPattern = Pattern.compile("(")");
|
private static String ESCAPED_QUOTE = """;
|
||||||
private final ReturnStringIf2xx returnStringIf200;
|
private final ReturnStringIf2xx returnStringIf200;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -52,16 +52,8 @@ public class ETagFromHttpResponseViaRegex implements Function<HttpResponse, Stri
|
||||||
Matcher matcher = pattern.matcher(content);
|
Matcher matcher = pattern.matcher(content);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
value = matcher.group(1);
|
value = matcher.group(1);
|
||||||
Matcher quotMatcher = quotPattern.matcher(value);
|
if (value.indexOf(ESCAPED_QUOTE) != -1) {
|
||||||
StringBuffer quotBuffer = new StringBuffer();
|
value = value.replace(ESCAPED_QUOTE, "\"");
|
||||||
boolean foundUnescapedQuote = false;
|
|
||||||
while (quotMatcher.find()) {
|
|
||||||
quotMatcher.appendReplacement(quotBuffer, "\"");
|
|
||||||
foundUnescapedQuote = true;
|
|
||||||
}
|
|
||||||
if (foundUnescapedQuote) {
|
|
||||||
quotMatcher.appendTail(quotBuffer);
|
|
||||||
value = quotBuffer.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue