Package com.day.text
Class TextUtils
java.lang.Object
com.day.text.TextUtils
Simple text manipulation tasks - these aren't optimized, and are intended
primarily to be used by test code. (eg. to compare returned values from
functions with the values expected).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcountOccurences(String big, String small) static booleanisTextSimilar(String docOne, String docTwo) Compare two strings, and determine whether they are approximately "similar" - by this we mean whether they have the same numbers of each character in (barring whitespace).static booleannoisyIsTextSimilar(String docOne, String docTwo) static booleanoccursExactlyNTimes(String big, String small, int n) static booleanoccursOnceOnly(String big, String small) static StringremoveControlCharacters(String characters) static StringremoveWhitespace(String characters) static StringSearch and replacestatic StringThese are characters not allowed in a text string in a CQ any file - they require escaping.Remove all whitespace from a string - most useful for test purposes (where you compare two strings, but whitespace isn't syntactically significant)static StringtrimLastSlashLevel(String input) Removes last level from a "slashy string" representaion of a hierarchical path.static StringtrimLeadingSlashes(String input) static StringtrimTrailingSlashes(String input)
-
Constructor Details
-
TextUtils
public TextUtils()
-
-
Method Details
-
removeControlCharacters
-
removeWhitespace
-
isTextSimilar
Compare two strings, and determine whether they are approximately "similar" - by this we mean whether they have the same numbers of each character in (barring whitespace). We do this by sorting the strings as a character array and stripping whitespace.This will generate false positives on some text - for example anagrams.
For example, the text "Watch the carthorse" and "Watch the orchestra" will both be converted to "aacceehhhorrstttw" and compared - so they will be identical.
This method is mostly useful as a simple way of comparing data which can be differently ordered but still functionally equivalent - for example DTDs.
-
noisyIsTextSimilar
-
stripWhitespace
Remove all whitespace from a string - most useful for test purposes (where you compare two strings, but whitespace isn't syntactically significant) -
sanitizeForCommunique
These are characters not allowed in a text string in a CQ any file - they require escaping. -
replace
Search and replace -
trimTrailingSlashes
-
trimLeadingSlashes
-
occursOnceOnly
-
occursExactlyNTimes
-
countOccurences
-
trimLastSlashLevel
Removes last level from a "slashy string" representaion of a hierarchical path. For example, '/a/b/c' becomes '/a/b' with the exception that '/' and '' remain unchanged
-