}
// Check that e-tag is quoted-string
if (!eTag.startsWith("\"") || !eTag.endsWith("\"")) {
if ("*".equals(eTag)) {
return new EntityTag("*");
}
throw new IllegalArgumentException("Entity Tag " + eTag + " is not quoted properly");
}
// Remove quotes
eTag = eTag.substring(1, eTag.length() - 1);
// Un-escape the e-tag
StringBuilder builder = null;
for (int i = 0; i < eTag.length(); i++) {
if (eTag.charAt(i) == '\\' && i + 1 < eTag.length()) {
// each '\' (which is not the last one) escapes the next
// character
if (builder == null) {
builder = new StringBuilder(eTag.length());
builder.append(eTag, 0, i);
}
// don't append the '\'
} else {
// append the character
if (builder != null) {
builder.append(eTag.charAt(i));
}
}
}
if (builder != null) {
eTag = builder.toString();
}
return new EntityTag(eTag, weak);
}