# Class PT

java.lang.Object
javajs.util.PT

public class PT extends Object
a combination of Parsing and Text-related utility classes

Author:
  hansonr

## Field Summary

Fields
Modifier and Type
Field
Description
`static final float`
`CARTESIAN_PRECISION`
`static final float[]`
`decimalScale`
`static final float`
`FRACTIONAL_PRECISION`
`static final float[]`
`tensScale`

## Constructor Summary

Constructors
Constructor
Description
`PT()`

## Method Summary

Modifier and Type
Method
Description
`static float`
`approx(float f, float n)`
`static String`
`byteArrayToJSON(byte[] data)`
`static boolean`
`checkTrailingText(String str, int ich, int ichMax)`
`static String`
`clean(String s)`
`static int`
`countChar(String line, char c)`
`static int`
`countTokens(String line, int ich)`
`static double`
`dVal(String s)`
`static String`
`esc(String str)`
`static String`
`escapeUrl(String url)`
`static String`
`escF(float f)`
ensures that a float turned to string has a decimal point
`static String`
`escUnicode(String str)`
`static String`
`fdup(String f, int pt, int n)`
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`
`formatS(String value, int width, int precision, boolean alignLeft, boolean zeroPad)`
`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`
`fVal(String s)`
`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-sensitive
`static String`
`getQuotedStringAt(String line, int ipt0)`
general static string-parsing class ///
`static String`
`getQuotedStringNext(String line, int[] next)`
`static String[]`
`getTokens(String line)`
`static String[]`
`getTokensAt(String line, int ich)`
`static boolean`
`isDigit(char ch)`
`static boolean`
`isLetter(char ch)`
`static boolean`
`isLetterOrDigit(char ch)`
`static boolean`
`isLike(String a, String b)`
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
`static boolean`
`isLowerCase(char ch)`
`static boolean`
`isMatch(String search, String match, boolean checkStar, boolean allowInitialStar)`
A general non-regex (for performance) text matcher that utilizes ? and *.
`static boolean`
`isNonStringPrimitive(Object info)`
`static boolean`
`isOneOf(String key, String semiList)`
`static boolean`
`isUpperCase(char ch)`
`static boolean`
`isWhitespace(char ch)`
`static boolean`
`isWhiteSpace(String str, int ich)`
`static boolean`
`isWild(String s)`
`static String`
`join(String[] s, char c, int i0)`
`static void`
`leftJustify(SB s, String s1, String s2)`
`static String`
`nonArrayString(Object x)`
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+-n
`static float`
`parseFloatFraction(String s)`
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`
`parseInt(String str)`
`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`
`rep(String str, String strFrom, String strTo)`
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`
`replaceQuotedStrings(String s, Lst<String> list, Lst<String> newList)`
`static String`
`replaceStrings(String s, Lst<String> list, Lst<String> newList)`
`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[]`
`split(String text, String run)`
proper splitting, even for Java 1.3 -- if the text ends in the run, no new line is appended.
`static String`
`sprintf(String strFormat, String list, Object[] values)`
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`
`toJSON(String infoType, Object info)`
`static String`
`trim(String str, String chars)`
`static String`
`trimQuotes(String value)`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### tensScale

public static final float[] tensScale

### decimalScale

public static final float[] decimalScale

### FRACTIONAL_PRECISION

public static final float FRACTIONAL_PRECISION

See Also:
  - Constant Field Values

### CARTESIAN_PRECISION

public static final float CARTESIAN_PRECISION

See Also:
  - Constant Field Values

## Constructor Details

### PT

public PT()

## Method Details

### parseInt

public static int parseInt(String str)

### parseIntNext

public static int parseIntNext(String str, int[] next)

### parseIntChecked

public static int parseIntChecked(String str, int ichMax, int[] next)

### isWhiteSpace

public static boolean isWhiteSpace(String str, int ich)

### parseFloatChecked

public 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+-n

Parameters:
  `str` -
  `ichMax` -
  `next` - pointer; incremented
  `isStrict` -
Returns:
  value or Float.NaN

### checkTrailingText

public static boolean checkTrailingText(String str, int ich, int ichMax)

### parseFloatArray

public static float[] parseFloatArray(String str)

### parseFloatArrayInfested

public static int parseFloatArrayInfested(String[] tokens, float[] data)

### parseFloatArrayNext

public static float[] parseFloatArrayNext(String str, int[] next, float[] f, String strStart, String strEnd)

Parameters:
  `str` -
  `next` -
  `f` -
  `strStart` - or null
  `strEnd` - or null
Returns:
  array of float values

### parseFloatRange

public static float parseFloatRange(String str, int ichMax, int[] next)

### parseFloatNext

public static float parseFloatNext(String str, int[] next)

### parseFloatStrict

public static float parseFloatStrict(String str)

### parseFloat

public static float parseFloat(String str)

### parseIntRadix

public static int parseIntRadix(String s, int i) throws NumberFormatException

Throws:
  `NumberFormatException`

### getTokens

public static String[] getTokens(String line)

### parseToken

public static String parseToken(String str)

### parseTrimmed

public static String parseTrimmed(String str)

### parseTrimmedAt

public static String parseTrimmedAt(String str, int ichStart)

### parseTrimmedRange

public static String parseTrimmedRange(String str, int ichStart, int ichMax)

### getTokensAt

public static String[] getTokensAt(String line, int ich)

### countChar

public static int countChar(String line, char c)

### countTokens

public static int countTokens(String line, int ich)

### parseTokenNext

public static String parseTokenNext(String str, int[] next)

### parseTokenRange

public static String parseTokenRange(String str, int ichMax, int[] next)

### parseTokenChecked

public static String parseTokenChecked(String str, int ichMax, int[] next)

### parseTrimmedChecked

public static String parseTrimmedChecked(String str, int ich, int ichMax)

### dVal

public static double dVal(String s) throws NumberFormatException

Throws:
  `NumberFormatException`

### fVal

public static float fVal(String s) throws NumberFormatException

Throws:
  `NumberFormatException`

### parseIntRange

public static int parseIntRange(String str, int ichMax, int[] next)

### parseFloatArrayData

public static void parseFloatArrayData(String[] tokens, float[] data)
parses a string array for floats. Returns NaN for nonfloats.

Parameters:
  `tokens` - the strings to parse
  `data` - the array to fill

### parseFloatArrayDataN

public static void parseFloatArrayDataN(String[] tokens, float[] data, int nData)
parses a string array for floats. Returns NaN for nonfloats or missing data.

Parameters:
  `tokens` - the strings to parse
  `data` - the array to fill
  `nData` - the number of elements

### split

public static String[] split(String text, String run)
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

public static String getQuotedStringAt(String line, int ipt0)
general static string-parsing class ///

### getQuotedStringNext

public static String getQuotedStringNext(String line, int[] next)

Parameters:
  `line` -
  `next` - passes [current pointer]
Returns:
  quoted string -- does NOT unescape characters

### getQuotedOrUnquotedAttribute

public static String getQuotedOrUnquotedAttribute(String line, String key)
single- or double-quoted string or up to the first space -- like HTML5 not case-sensitive

Parameters:
  `line` -
  `key` -
Returns:
  attribute

### getCSVString

public static String getCSVString(String line, int[] next)
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

public static boolean isOneOf(String key, String semiList)

### getQuotedAttribute

public static String getQuotedAttribute(String info, String name)

### approx

public static float approx(float f, float n)

### rep

public static String rep(String str, String strFrom, String strTo)
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 columns
  `precision` - precision > 0 ==> precision = number of characters max from left precision invalid input: '<' 0 ==> -1 - precision = number of char. max from right
  `alignLeft` -
  `zeroPad` - generally for numbers turned strings
Returns:
  formatted string

### replaceWithCharacter

public 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. Otherwise, multiple passes are made until no more replacements can be made.

Parameters:
  `str` -
  `strFrom` -
  `chTo` -
Returns:
  replaced string

### replaceAllCharacters

public 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. Otherwise, multiple passes are made until no more replacements can be made.

Parameters:
  `str` -
  `strFrom` -
  `strTo` -
Returns:
  replaced string

### trim

public static String trim(String str, String chars)

### trimQuotes

public static String trimQuotes(String value)

### isNonStringPrimitive

public static boolean isNonStringPrimitive(Object info)

### toJSON

public static String toJSON(String infoType, Object info)

### nonArrayString

public static String nonArrayString(Object x)
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

public static String byteArrayToJSON(byte[] data)

### packageJSON

public static String packageJSON(String infoType, String info)

### escapeUrl

public static String escapeUrl(String url)

### esc

public static String esc(String str)

### escUnicode

public static String escUnicode(String str)

### escF

public static String escF(float f)
ensures that a float turned to string has a decimal point

Parameters:
  `f` -
Returns:
  string version of float

### join

public static String join(String[] s, char c, int i0)

### isLike

public static boolean isLike(String a, String b)
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

public static Object getMapValueNoCase(Map<String,?> h, String key)

### clean

public static String clean(String s)

### fdup

public static String fdup(String f, int pt, int n)
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

public static String formatStringS(String strFormat, String key, String strT)

### formatStringF

public static String formatStringF(String strFormat, String key, float floatT)

### formatStringI

public static String formatStringI(String strFormat, String key, int intT)

### sprintf

public static String sprintf(String strFormat, String list, Object[] values)
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

public 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"

Parameters:
  `strFormat` -
Returns:
  f or dupicated format

### leftJustify

public static void leftJustify(SB s, String s1, String s2)

### rightJustify

public static void rightJustify(SB s, String s1, String s2)

### safeTruncate

public static String safeTruncate(float f, int n)

### isWild

public static boolean isWild(String s)

### 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 search
  `match` - the match string
  `checkStar` -
  `allowInitialStar` -
Returns:
  true if found

### replaceQuotedStrings

public static String replaceQuotedStrings(String s, Lst<String> list, Lst<String> newList)

### replaceStrings

public static String replaceStrings(String s, Lst<String> list, Lst<String> newList)

### 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

public static void fixPtFloats(T3 pt, float f)

### fixFloat

public static float fixFloat(float d, double f)

### fixDouble

public static double fixDouble(double d, double f)

### parseFloatFraction

public static float parseFloatFraction(String s)
parse a float or "float/float"

Parameters:
  `s` -
Returns:
  a/b