Package javajs.util
Class PT
java.lang.Object
javajs.util.PT
a combination of Parsing and Text-related utility classes
- Author:
- hansonr
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatstatic final float[]static final floatstatic final float[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic floatapprox(float f, float n) static StringbyteArrayToJSON(byte[] data) static booleancheckTrailingText(String str, int ich, int ichMax) static Stringstatic intstatic intcountTokens(String line, int ich) static doublestatic Stringstatic Stringstatic StringescF(float f) ensures that a float turned to string has a decimal pointstatic StringescUnicode(String str) static Stringfdup duplicates p or q formats for formatCheck and the format() function.static doublefixDouble(double d, double f) static floatfixFloat(float d, double f) static voidfixPtFloats(T3 pt, float f) static StringformatCheck(String strFormat) formatCheck checks p and q formats and duplicates if necessary "%10.5p xxxx" ==> "%10.5p%10.5p%10.5p xxxx"static StringformatD(double value, int width, int precision, boolean alignLeft, boolean zeroPad) static StringformatF(float value, int width, int precision, boolean alignLeft, boolean zeroPad) static Stringstatic StringformatStringF(String strFormat, String key, float floatT) static StringformatStringI(String strFormat, String key, int intT) static StringformatStringS(String strFormat, String key, String strT) static floatstatic StringgetCSVString(String line, int[] next) CSV format -- escaped quote is "" WITHIN "..."static ObjectgetMapValueNoCase(Map<String, ?> h, String key) static StringgetQuotedAttribute(String info, String name) static StringgetQuotedOrUnquotedAttribute(String line, String key) single- or double-quoted string or up to the first space -- like HTML5 not case-sensitivestatic StringgetQuotedStringAt(String line, int ipt0) static StringgetQuotedStringNext(String line, int[] next) static String[]static String[]getTokensAt(String line, int ich) static booleanisDigit(char ch) static booleanisLetter(char ch) static booleanisLetterOrDigit(char ch) static booleana LIKE "x" a is a string and equals x a LIKE "*x" a is a string and ends with x a LIKE "x*" a is a string and starts with x a LIKE "*x*" a is a string and contains xstatic booleanisLowerCase(char ch) static booleanA general non-regex (for performance) text matcher that utilizes ? and *.static booleanisNonStringPrimitive(Object info) static booleanstatic booleanisUpperCase(char ch) static booleanisWhitespace(char ch) static booleanisWhiteSpace(String str, int ich) static booleanstatic Stringstatic voidleftJustify(SB s, String s1, String s2) static StringChecks to see if an object is an array (including typed arrays), and if it is, returns null; otherwise it returns the string equivalent of that object.static StringpackageJSON(String infoType, String info) static floatparseFloat(String str) static float[]parseFloatArray(String str) static voidparseFloatArrayData(String[] tokens, float[] data) parses a string array for floats.static voidparseFloatArrayDataN(String[] tokens, float[] data, int nData) parses a string array for floats.static intparseFloatArrayInfested(String[] tokens, float[] data) static float[]parseFloatArrayNext(String str, int[] next, float[] f, String strStart, String strEnd) static floatparseFloatChecked(String str, int ichMax, int[] next, boolean isStrict) A float parser that is 30% faster than Float.parseFloat(x) and also accepts x.yD+-nstatic floatparse a float or "float/float"static floatparseFloatNext(String str, int[] next) static floatparseFloatRange(String str, int ichMax, int[] next) static floatparseFloatStrict(String str) static intstatic intparseIntChecked(String str, int ichMax, int[] next) static intparseIntNext(String str, int[] next) static intparseIntRadix(String s, int i) static intparseIntRange(String str, int ichMax, int[] next) static StringparseToken(String str) static StringparseTokenChecked(String str, int ichMax, int[] next) static StringparseTokenNext(String str, int[] next) static StringparseTokenRange(String str, int ichMax, int[] next) static StringparseTrimmed(String str) static StringparseTrimmedAt(String str, int ichStart) static StringparseTrimmedChecked(String str, int ich, int ichMax) static StringparseTrimmedRange(String str, int ichStart, int ichMax) static StringDoes a clean ITERATIVE replace of strFrom in str with strTo.static StringreplaceAllCharacters(String str, String strFrom, String strTo) Does a clean replace of any of the characters in str with strTo If strTo contains strFrom, then only a single pass is done.static Stringstatic Stringstatic StringreplaceWithCharacter(String str, String strFrom, char chTo) Does a clean replace of any of the characters in str with chrTo If strTo contains strFrom, then only a single pass is done.static voidrightJustify(SB s, String s1, String s2) static StringsafeTruncate(float f, int n) static String[]proper splitting, even for Java 1.3 -- if the text ends in the run, no new line is appended.static Stringsprintf emulation uses (almost) c++ standard string formats 's' string 'i' or 'd' integer, 'e' double, 'f' float, 'p' point3f 'q' quaternion/plane/axisangle with added "i" (equal to the insipid "d" -- digits?)static Stringstatic Stringstatic StringtrimQuotes(String value)
-
Field Details
-
tensScale
public static final float[] tensScale -
decimalScale
public static final float[] decimalScale -
FRACTIONAL_PRECISION
public static final float FRACTIONAL_PRECISION- See Also:
-
CARTESIAN_PRECISION
public static final float CARTESIAN_PRECISION- See Also:
-
-
Constructor Details
-
PT
public PT()
-
-
Method Details
-
parseInt
-
parseIntNext
-
parseIntChecked
-
isWhiteSpace
-
parseFloatChecked
A float parser that is 30% faster than Float.parseFloat(x) and also accepts x.yD+-n- Parameters:
str-ichMax-next- pointer; incrementedisStrict-- Returns:
- value or Float.NaN
-
checkTrailingText
-
parseFloatArray
-
parseFloatArrayInfested
-
parseFloatArrayNext
public static float[] parseFloatArrayNext(String str, int[] next, float[] f, String strStart, String strEnd) - Parameters:
str-next-f-strStart- or nullstrEnd- or null- Returns:
- array of float values
-
parseFloatRange
-
parseFloatNext
-
parseFloatStrict
-
parseFloat
-
parseIntRadix
- Throws:
NumberFormatException
-
getTokens
-
parseToken
-
parseTrimmed
-
parseTrimmedAt
-
parseTrimmedRange
-
getTokensAt
-
countChar
-
countTokens
-
parseTokenNext
-
parseTokenRange
-
parseTokenChecked
-
parseTrimmedChecked
-
dVal
- Throws:
NumberFormatException
-
fVal
- Throws:
NumberFormatException
-
parseIntRange
-
parseFloatArrayData
parses a string array for floats. Returns NaN for nonfloats.- Parameters:
tokens- the strings to parsedata- the array to fill
-
parseFloatArrayDataN
parses a string array for floats. Returns NaN for nonfloats or missing data.- Parameters:
tokens- the strings to parsedata- the array to fillnData- the number of elements
-
split
proper splitting, even for Java 1.3 -- if the text ends in the run, no new line is appended.- Parameters:
text-run-- Returns:
- String array
-
getQuotedStringAt
-
getQuotedStringNext
- Parameters:
line-next- passes [current pointer]- Returns:
- quoted string -- does NOT unescape characters
-
getQuotedOrUnquotedAttribute
single- or double-quoted string or up to the first space -- like HTML5 not case-sensitive- Parameters:
line-key-- Returns:
- attribute
-
getCSVString
CSV format -- escaped quote is "" WITHIN "..."- Parameters:
line-next- int[2] filled with [ptrQuote1, ptrAfterQuote2] next[1] will be -1 if unmatched quotes are found (continuation on next line)- Returns:
- unescaped string or null
-
isOneOf
-
getQuotedAttribute
-
approx
public static float approx(float f, float n) -
rep
Does a clean ITERATIVE replace of strFrom in str with strTo. Thus, rep("Testttt", "tt","t") becomes "Test".- Parameters:
str-strFrom-strTo-- Returns:
- replaced string
-
formatF
public static String formatF(float value, int width, int precision, boolean alignLeft, boolean zeroPad) -
formatD
public static String formatD(double value, int width, int precision, boolean alignLeft, boolean zeroPad) - Parameters:
value-width-precision-alignLeft-zeroPad-- Returns:
- formatted string
-
formatS
public static String formatS(String value, int width, int precision, boolean alignLeft, boolean zeroPad) - Parameters:
value-width- number of columnsprecision- precision > 0 ==> precision = number of characters max from left precision invalid input: '<' 0 ==> -1 - precision = number of char. max from rightalignLeft-zeroPad- generally for numbers turned strings- Returns:
- formatted string
-
replaceWithCharacter
Does a clean replace of any of the characters in str with chrTo If strTo contains strFrom, then only a single pass is done. Otherwise, multiple passes are made until no more replacements can be made.- Parameters:
str-strFrom-chTo-- Returns:
- replaced string
-
replaceAllCharacters
Does a clean replace of any of the characters in str with strTo If strTo contains strFrom, then only a single pass is done. Otherwise, multiple passes are made until no more replacements can be made.- Parameters:
str-strFrom-strTo-- Returns:
- replaced string
-
trim
-
trimQuotes
-
isNonStringPrimitive
-
toJSON
-
nonArrayString
Checks to see if an object is an array (including typed arrays), and if it is, returns null; otherwise it returns the string equivalent of that object.- Parameters:
x-- Returns:
- String or null
-
byteArrayToJSON
-
packageJSON
-
escapeUrl
-
esc
-
escUnicode
-
escF
ensures that a float turned to string has a decimal point- Parameters:
f-- Returns:
- string version of float
-
join
-
isLike
a LIKE "x" a is a string and equals x a LIKE "*x" a is a string and ends with x a LIKE "x*" a is a string and starts with x a LIKE "*x*" a is a string and contains x- Parameters:
a-b-- Returns:
- a LIKE b
-
getMapValueNoCase
-
clean
-
fdup
fdup duplicates p or q formats for formatCheck and the format() function.- Parameters:
f-pt-n-- Returns:
- %3.5q%3.5q%3.5q%3.5q or %3.5p%3.5p%3.5p
-
formatStringS
-
formatStringF
-
formatStringI
-
sprintf
sprintf emulation uses (almost) c++ standard string formats 's' string 'i' or 'd' integer, 'e' double, 'f' float, 'p' point3f 'q' quaternion/plane/axisangle with added "i" (equal to the insipid "d" -- digits?)- Parameters:
strFormat-list- a listing of what sort of data will be found in Object[] values, in order: s string, f float, i integer, d double, p point3f, q quaternion/point4f, S String[], F float[], I int[], and D double[]values- Object[] containing above types- Returns:
- formatted string
-
formatCheck
formatCheck checks p and q formats and duplicates if necessary "%10.5p xxxx" ==> "%10.5p%10.5p%10.5p xxxx"- Parameters:
strFormat-- Returns:
- f or dupicated format
-
leftJustify
-
rightJustify
-
safeTruncate
-
isWild
-
isMatch
public static boolean isMatch(String search, String match, boolean checkStar, boolean allowInitialStar) A general non-regex (for performance) text matcher that utilizes ? and *. ??? means "at most three" characters if at beginning or end; "exactly three" otherwise \1 in search is a stand-in for actual ?- Parameters:
search- the string to searchmatch- the match stringcheckStar-allowInitialStar-- Returns:
- true if found
-
replaceQuotedStrings
-
replaceStrings
-
isDigit
public static boolean isDigit(char ch) -
isUpperCase
public static boolean isUpperCase(char ch) -
isLowerCase
public static boolean isLowerCase(char ch) -
isLetter
public static boolean isLetter(char ch) -
isLetterOrDigit
public static boolean isLetterOrDigit(char ch) -
isWhitespace
public static boolean isWhitespace(char ch) -
fixPtFloats
-
fixFloat
public static float fixFloat(float d, double f) -
fixDouble
public static double fixDouble(double d, double f) -
parseFloatFraction
parse a float or "float/float"- Parameters:
s-- Returns:
- a/b
-