summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java38
1 files changed, 30 insertions, 8 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
index a35253a..540fb39 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
@@ -1,5 +1,7 @@
package bjc.utils.funcutils;
+import com.ibm.icu.text.BreakIterator;
+
import java.util.Deque;
/**
@@ -22,9 +24,9 @@ public class StringUtils {
* of the provided regex
*/
public static boolean containsOnly(String input, String regex) {
- if (input == null)
+ if(input == null)
throw new NullPointerException("Input must not be null");
- else if (regex == null) throw new NullPointerException("Regex must not be null");
+ else if(regex == null) throw new NullPointerException("Regex must not be null");
/*
* This regular expression is fairly simple.
@@ -46,7 +48,7 @@ public class StringUtils {
* The number of levels to indent
*/
public static void indentNLevels(StringBuilder builder, int levels) {
- for (int i = 0; i < levels; i++) {
+ for(int i = 0; i < levels; i++) {
builder.append("\t");
}
}
@@ -80,7 +82,7 @@ public class StringUtils {
* @return The sequence as an English list.
*/
public static String toEnglishList(Object[] objects, String join, String comma) {
- if (objects == null) {
+ if(objects == null) {
throw new NullPointerException("Sequence must not be null");
}
@@ -89,7 +91,7 @@ public class StringUtils {
String joiner = join;
String coma = comma;
- switch (objects.length) {
+ switch(objects.length) {
case 0:
/*
* Empty list.
@@ -113,7 +115,7 @@ public class StringUtils {
/*
* Three or more items.
*/
- for (int i = 0; i < objects.length - 1; i++) {
+ for(int i = 0; i < objects.length - 1; i++) {
sb.append(objects[i].toString());
sb.append(coma + " ");
}
@@ -157,10 +159,30 @@ public class StringUtils {
* @return The sequence as an English list.
*/
public static String toEnglishList(Object[] objects, boolean and) {
- if (and) {
+ if(and) {
return toEnglishList(objects, "and");
} else {
return toEnglishList(objects, "or");
}
}
-}
+
+ /**
+ * Count the number of graphemes in a string.
+ *
+ * @param value
+ * The string to check.
+ *
+ * @return The number of graphemes in the string.
+ */
+ public static int graphemeCount(String value) {
+ BreakIterator it = BreakIterator.getCharacterInstance();
+ it.setText(value);
+
+ int count = 0;
+ while(it.next() != BreakIterator.DONE) {
+ count++;
+ }
+
+ return count;
+ }
+} \ No newline at end of file