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 float
static final float[]
static final float
static final float[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic float
approx
(float f, float n) static String
byteArrayToJSON
(byte[] data) static boolean
checkTrailingText
(String str, int ich, int ichMax) static String
static int
static int
countTokens
(String line, int ich) static double
static String
static String
static String
escF
(float f) ensures that a float turned to string has a decimal pointstatic String
escUnicode
(String str) static String
fdup duplicates p or q formats for formatCheck and the format() function.static double
fixDouble
(double d, double f) static float
fixFloat
(float d, double f) static void
fixPtFloats
(T3 pt, float f) static String
formatCheck
(String strFormat) formatCheck checks p and q formats and duplicates if necessary "%10.5p xxxx" ==> "%10.5p%10.5p%10.5p xxxx"static String
formatD
(double value, int width, int precision, boolean alignLeft, boolean zeroPad) static String
formatF
(float value, int width, int precision, boolean alignLeft, boolean zeroPad) static String
static String
formatStringF
(String strFormat, String key, float floatT) static String
formatStringI
(String strFormat, String key, int intT) static String
formatStringS
(String strFormat, String key, String strT) static float
static String
getCSVString
(String line, int[] next) CSV format -- escaped quote is "" WITHIN "..."static Object
getMapValueNoCase
(Map<String, ?> h, String key) static String
getQuotedAttribute
(String info, String name) static String
getQuotedOrUnquotedAttribute
(String line, String key) single- or double-quoted string or up to the first space -- like HTML5 not case-sensitivestatic String
getQuotedStringAt
(String line, int ipt0) static String
getQuotedStringNext
(String line, int[] next) static String[]
static String[]
getTokensAt
(String line, int ich) static boolean
isDigit
(char ch) static boolean
isLetter
(char ch) static boolean
isLetterOrDigit
(char ch) static boolean
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 xstatic boolean
isLowerCase
(char ch) static boolean
A general non-regex (for performance) text matcher that utilizes ? and *.static boolean
isNonStringPrimitive
(Object info) static boolean
static boolean
isUpperCase
(char ch) static boolean
isWhitespace
(char ch) static boolean
isWhiteSpace
(String str, int ich) static boolean
static String
static void
leftJustify
(SB s, String s1, String s2) static String
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.static String
packageJSON
(String infoType, String info) static float
parseFloat
(String str) static float[]
parseFloatArray
(String str) static void
parseFloatArrayData
(String[] tokens, float[] data) parses a string array for floats.static void
parseFloatArrayDataN
(String[] tokens, float[] data, int nData) parses a string array for floats.static int
parseFloatArrayInfested
(String[] tokens, float[] data) static float[]
parseFloatArrayNext
(String str, int[] next, float[] f, String strStart, String strEnd) static float
parseFloatChecked
(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 float
parse a float or "float/float"static float
parseFloatNext
(String str, int[] next) static float
parseFloatRange
(String str, int ichMax, int[] next) static float
parseFloatStrict
(String str) static int
static int
parseIntChecked
(String str, int ichMax, int[] next) static int
parseIntNext
(String str, int[] next) static int
parseIntRadix
(String s, int i) static int
parseIntRange
(String str, int ichMax, int[] next) static String
parseToken
(String str) static String
parseTokenChecked
(String str, int ichMax, int[] next) static String
parseTokenNext
(String str, int[] next) static String
parseTokenRange
(String str, int ichMax, int[] next) static String
parseTrimmed
(String str) static String
parseTrimmedAt
(String str, int ichStart) static String
parseTrimmedChecked
(String str, int ich, int ichMax) static String
parseTrimmedRange
(String str, int ichStart, int ichMax) static String
Does a clean ITERATIVE replace of strFrom in str with strTo.static String
replaceAllCharacters
(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 String
static String
static String
replaceWithCharacter
(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 void
rightJustify
(SB s, String s1, String s2) static String
safeTruncate
(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 String
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?)static String
static String
static String
trimQuotes
(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 < 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
-