private static void validateTextString(String id) { OptionalInt illegalCodePoint = Text.validateTextString(id); if (illegalCodePoint.isPresent()) { throw new IllegalArgumentException("Unparseable id '" + id + "': Contains illegal code point 0x" + Integer.toHexString(illegalCodePoint.getAsInt()).toUpperCase()); } }
int codePoint = string.codePointAt(i); int charCount = Character.charCount(codePoint); if ( ! Text.isTextCharacter(codePoint)) { stripped = lazy(stripped, string, i); } else { if (Character.isHighSurrogate(string.charAt(i))) { if (charCount == 1) { stripped = lazy(stripped, string, i); } else if (!Character.isLowSurrogate(string.charAt(i+1))) { stripped = lazy(stripped, string, i); } else { if (stripped != null) {
/** * Validates that the given string value only contains text characters and * returns the first illegal code point if one is found. */ public static OptionalInt validateTextString(String string) { for (int i = 0; i < string.length(); ) { int codePoint = string.codePointAt(i); if ( ! Text.isTextCharacter(codePoint)) return OptionalInt.of(codePoint); int charCount = Character.charCount(codePoint); if (Character.isHighSurrogate(string.charAt(i))) { if ( charCount == 1) { return OptionalInt.of(string.codePointAt(i)); } else if ( !Character.isLowSurrogate(string.charAt(i+1))) { return OptionalInt.of(string.codePointAt(i+1)); } } i += charCount; } return OptionalInt.empty(); }
private static void validateTextString(String value) { OptionalInt illegalCodePoint = Text.validateTextString(value); if (illegalCodePoint.isPresent()) { throw new IllegalArgumentException("The string field value contains illegal code point 0x" + Integer.toHexString(illegalCodePoint.getAsInt()).toUpperCase()); } }
private static String validateAndBuildLocationSubExpression(RestUri.Group group) { if (group.name == 'n') { return String.format("id.user==%d", parseAndValidateVisitNumericId(group.value)); } else { // Cannot feed documents with groups that don't pass this test, so it makes sense // to enforce this symmetry when trying to retrieve them as well. Text.validateTextString(group.value).ifPresent(codepoint -> { throw new BadRequestParameterException(SELECTION, String.format( "Failed to parse group part of selection URI; contains invalid text code point U%04X", codepoint)); }); return String.format("id.group=='%s'", singleQuoteEscapedString(group.value)); } }