aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-04-05 12:31:16 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2022-04-05 12:31:16 +0200
commitee806dbf2e9240a255271ccb890d80468a7b05f1 (patch)
tree83fa3812bf5e7f91fdd288cf3783b3ba5da265d0 /vespajlib/src
parenta25ada23f00262c55a4283293f8e58a30c9c9b10 (diff)
Use a primitive to see if that makes the JIT compiler more predictable.
Diffstat (limited to 'vespajlib/src')
-rw-r--r--vespajlib/src/main/java/com/yahoo/text/Text.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/text/Text.java b/vespajlib/src/main/java/com/yahoo/text/Text.java
index 662100aa8ea..be34a9e3ab0 100644
--- a/vespajlib/src/main/java/com/yahoo/text/Text.java
+++ b/vespajlib/src/main/java/com/yahoo/text/Text.java
@@ -110,6 +110,23 @@ public final class Text {
return OptionalInt.empty();
}
+ /**
+ * Validates that the given string value only contains text characters.
+ */
+ public static boolean isValidTextString(String string) {
+ for (int i = 0; i < string.length(); ) {
+ int codePoint = string.codePointAt(i);
+ if ( ! Text.isTextCharacter(codePoint)) return false;
+
+ int charCount = Character.charCount(codePoint);
+ if (Character.isHighSurrogate(string.charAt(i))) {
+ if ( (charCount == 1) || !Character.isLowSurrogate(string.charAt(i+1))) return false;
+ }
+ i += charCount;
+ }
+ return true;
+ }
+
/** Returns whether the given code point is displayable. */
public static boolean isDisplayable(int codePoint) {
switch (Character.getType(codePoint)) {