public class StringFunctions_C
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
StringFunctions_C.PrepareAppendablePos
Implementation of the
StringFunctions_C.PrepareBufferPos for a simple Appendable |
static interface |
StringFunctions_C.PrepareBufferPos
This interface is used also for
StringFormatter
to use similar approaches for setCharAt and append. |
Modifier and Type | Field and Description |
---|---|
private static long[] |
n10a
Array with power of 10 to detect the exponent size of a long value.
|
(package private) static java.lang.String |
sNeg |
static java.lang.String |
version
Version, history and license.
|
Constructor and Description |
---|
StringFunctions_C() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Appendable |
appendHex(java.lang.Appendable out,
long value,
int nrofDigits)
Append a value in hexa with given number of digits.
|
static java.lang.Appendable |
appendHexLine(java.lang.Appendable out,
int[] data,
int from,
int to,
int nrofDigits,
int nrFirstLine,
int nrWordsPerLine)
Appends some lines with hex numbers
|
static java.lang.Appendable |
appendIntPict(java.lang.Appendable appendable,
long src,
java.lang.String pict)
Appends a long value with a dedicated outfit
|
static java.lang.CharSequence |
doubleToStringTruncated(double v1,
double v2)
Converts the given double to a String representation, whereby the number of digits is minimized,
so that the resulting String is a value >=v1 and <= v2 with the minimum of representing digits.
|
static float |
parseFloat(java.lang.CharSequence src,
int pos,
int sizeP,
char decimalpoint,
int[] parsedCharsP,
java.lang.String separationChars)
Parses a given String and convert it to the float number.
|
static float |
parseFloat(java.lang.CharSequence src,
int pos,
int sizeP,
int[] parsedChars)
Parsed the given part of a a given charSequence to a float number with dot '.' as decimal point.
|
static int |
parseIntRadix(java.lang.CharSequence srcP,
int pos,
int sizeP,
int radix,
int[] parsedChars)
Parses an integer value.
|
static int |
parseIntRadix(java.lang.CharSequence srcP,
int pos,
int sizeP,
int radixArg,
int[] parsedChars,
java.lang.String spaceChars)
Parses a given String and convert it to the integer number.
|
static int |
parseIntRadixBack(java.lang.CharSequence srcP,
int pos,
int sizeP,
int radix,
int[] parsedChars)
Parses a given String backward and convert it to the integer number.
|
static long |
parseLong(java.lang.CharSequence srcP,
int posArg,
int sizeP,
int radix,
int[] parsedChars,
java.lang.String separatorChars)
Parses a given String and convert it to the long number.
|
static long |
parseUlong(java.lang.CharSequence src,
int pos,
int sizeP,
int radixArg,
int[] parsedChars,
java.lang.String separatorChars)
Adequate method for long values, see
#parseIntRadix(String, int, int, int, int[], String) . |
(package private) static boolean |
strPicture(long src,
java.lang.String pict,
java.lang.String posNegPointExp,
char cFracSep,
StringFunctions_C.PrepareBufferPos bufferPos)
This algorithm is taken over from C++ routines in strpict.cpp written by JcHartmut in 1993..1999.
|
public static final java.lang.String version
parseIntRadix(CharSequence, int, int, int, int[], String)
:
If the number is too long then an overflow has occurred.
Now only the max number of characters are parsed without int 32 bit overflow.
If the digit is too long, some digits remain after parsing.
This is used in #parseFloat(CharSequence, int, int, char, int[])
.
Before it was fixed, a too long fractional part has caused undefined result.
Now the fractional part is converted only with max 31 bit (only 24 are relevant),
but possible with more digits for example to recognize "0.00000012345678".
appendIntPict(Appendable, long, String)
, for that
the strPicture(long, String, String, char, PrepareBufferPos)
was moved and adapted from StringFormatter
to here,
the internal interface StringFunctions_C.PrepareBufferPos
allows the adaption (it is simple).
That is the basic to append a number in a specific outfit, TODO use also for float and double.
appendHex(Appendable, long, int)
Algorithm copied from StringFormatter.addHex(long, int)
parseUlong(CharSequence, int, int, int, int[], String)
and adaption of the adequate using routines.
Note: It is a base routine now used in StringPartScan.scanDigits(int, int, String)
. It is done because gardening, adequate code unified.
#parseFloat(CharSequence, int, int, char, int[])
has had a problem with 1 digit after decimal point.
This bug was not present in older versions. maybe forced with the last change on 2016-02-07.
#parseFloat(String, int, int, char, int[])
has had a problem with negative numbers.
StringFunctions_C
.
Reason: Dispersing the content because for some embedded applications a fine tuning of used sources is necessary.
#parseFloat(String, int, int, char, int[])
with choiceable separator (123,45, german decimal point)
#parseIntRadix(String, int, int, int, int[], String)
now can skip
over some characters. In this kind a number like 2"123'456.1 is able to read.
#parseLong(String, int, int, int, int[], String)
as counterpart to parseInt
#parseIntRadix(String, int, int, int, int[])
etc.
taken from C-Sources CRunntimeJavalike/source/Fwc/fw_Simple.c
private static final long[] n10a
static java.lang.String sNeg
public static int parseIntRadix(java.lang.CharSequence srcP, int pos, int sizeP, int radixArg, int[] parsedChars, java.lang.String spaceChars)
srcP
- The String, non 0-terminated, see ,,size,,.pos
- The position in src to start.sizeP
- The maximal number of chars to parse. If it is more as the length of the String, no error.
Negative: length of srcP shortened, -1 is till end, -2 is till end-1 etc.
One can use -1 or Integer.MAX_VALUE
to parse till the end of the StringradixArg
- The radix of the number, typical 2, 10 or 16, max 36.parsedChars
- maybe null, if not null it should be intialized with int[1] or int[2].
separatorChars
- Any character are accept inside the number as a separation character. For Example _ or ' or , to write:
12'345
or 12,234
or 12_345
which is parsed as 12345 in any case. Usual such as "'"never.
- All possible digits where scanned, the rest of non-scanable digits are returned.
For example the String contains "-123.45" it returns -123, and the retSize is 3.public static int parseIntRadix(java.lang.CharSequence srcP, int pos, int sizeP, int radix, int[] parsedChars)
parseIntRadix(CharSequence, int, int, int, int[], String)
sizeP
- The number of chars to regard at maximum. A value of -1 means: use the whole String till end.
sizeP = 0 is possible, then nothing should be parsed and paredCharsP[0] is set to 0. It may be possible
that the number of characters to parse will be calculated outside, and 0 is a valid result.
If sizeP is > the length, then the whole String is used.
You can set both sizeP = -1 or sizeP = Integer.MAXVALUE to deactivate this argument.parsedChars
- maybe null, if not null it should be intialized with int[1] or int[2].
separatorChars
- Any character are accept inside the number as a separation character. For Example _ or ' or , to write:
12'345
or 12,234
or 12_345
which is parsed as 12345 in any case. Usual such as "'"public static long parseLong(java.lang.CharSequence srcP, int posArg, int sizeP, int radix, int[] parsedChars, java.lang.String separatorChars)
parseIntRadix(CharSequence, int, int, int, int[], String)
.
The String may start with a negative sign ('-') and should contain digits after them.
The digits for radix > 10 are 'A'..'Z' respectively 'a'..'z', known as hexa numbers A..F or a..f.
srcP
- The String, non 0-terminated, see ,,size,,.pos
- The position in src to start.sizeP
- The maximal number of chars to parse. If it is more as the length of the String, no error.
Negative: length of srcP shortened, -1 is till end, -2 is till end-1 etc.
One can use -1 or Integer.MAX_VALUE
to parse till the end of the StringradixArg
- The radix of the number, typical 2, 10 or 16, max 36.parsedChars
- maybe null, if not null it should be intialized with int[1] or int[2].
separatorChars
- Any character are accept inside the number as a separation character. For Example _ or ' or , to write:
12'345
or 12,234
or 12_345
which is parsed as 12345 in any case. Usual such as "'"never.
- All possible digits where scanned, the rest of non-scanable digits are returned.
For example the String contains "-123.45" it returns -123, and the retSize is 3.public static long parseUlong(java.lang.CharSequence src, int pos, int sizeP, int radixArg, int[] parsedChars, java.lang.String separatorChars)
#parseIntRadix(String, int, int, int, int[], String)
.src
- Any CharSequence which should start on pos with a digit representation.pos
- start position in src.sizeP
- The number of chars to regard at maximum. A value of -1 means: use the whole String till end.
sizeP = 0 is possible, then nothing should be parsed and paredCharsP[0] is set to 0. It may be possible
that the number of characters to parse will be calculated outside, and 0 is a valid result.
If sizeP is > the length, then the whole String is used.
You can set both sizeP = -1 or sizeP = Integer.MAXVALUE to deactivate this argument.radix
- of the number, it can be any value 0..36- If >10 then characters A..Z or a..z are used for digits.
Usually 16 for hex numbers.parsedChars
- maybe null, if not null it should be intialized with int[1] or int[2].
separatorChars
- Any character are accept inside the number as a separation character. For Example _ or ' or , to write:
12'345
or 12,234
or 12_345
which is parsed as 12345 in any case. Usual such as "'"public static int parseIntRadixBack(java.lang.CharSequence srcP, int pos, int sizeP, int radix, int[] parsedChars)
srcP
- The String.pos
- The position in src to the last digit.sizeP
- The maximum of chars to parse. Should be less or equal pos.radix
- The radix of the number, typical 2, 10 or 16, max 36.parsedChars
- number of chars which is used to parse. The pointer may be null if not necessary. @pjava2c=simpleVariableRef.never.
- All possible digits where scanned, the rest of non-scanable digits are returned.
At example the String contains "-123.45" it returns -123, and the retSize is 3.public static float parseFloat(java.lang.CharSequence src, int pos, int sizeP, int[] parsedChars)
#parseFloat(CharSequence, int, int, char, int[])
src
- given Stringpos
- left start posititionsizeP
- -1 for whole string, max number of chars to useparsedChars
- number of chars which was used to parse. The pointer may be null if not necessary. @pjava2c=simpleVariableRef.public static float parseFloat(java.lang.CharSequence src, int pos, int sizeP, char decimalpoint, int[] parsedCharsP, java.lang.String separationChars)
src
- The String, see ,,size,,.pos
- The position in src to start.sizeP
- The number of chars to regard at maximum. A value of -1 means: use the whole String till end.
sizeP = 0 is possible, then no float was parsed and paredCharsP[0] is set to 0. It may be possible
that the number of characters to parse will be calculated outside, and 0 is a valid result.
If sizeP is > the length, then the whole String is used.
You can set both sizeP = -1 or sizeP = Integer.MAXVALUE to deactivate this argument.decimalpoint
- preferred '.', it is possible to use a ',' for german numbers.parsedCharsP
- [0] number of chars which is used to parse. The pointer may be null if not necessary. @pjava2c=simpleVariableRef.public static java.lang.Appendable appendHex(java.lang.Appendable out, long value, int nrofDigits) throws java.io.IOException
out
- to appendvalue
- nrofDigits
- if <0 then upper case digits A..F are used, else a..fjava.io.IOException
public static final java.lang.Appendable appendHexLine(java.lang.Appendable out, int[] data, int from, int to, int nrofDigits, int nrFirstLine, int nrWordsPerLine) throws java.io.IOException
out
- to this Appendabledata
- contains the datafrom
- start index in datato
- end index in datanrofDigits
- number of digits to present the integer. It is for example 4 to write 16 bit words.
Then also only 16 bits are used from data[ix].nrFirstLine
- number of words in the first line before a line break.
This allows structuring if data starts with some defined head data.
Use same value as nrWordsPerLine to write the full line.nrWordsPerLine
- number of words in a line, usual 16java.io.IOException
public static final java.lang.CharSequence doubleToStringTruncated(double v1, double v2)
v1
- should be < v2, it is the lower presentation of the exact valuev2
- It is the higher presentation of the value. returned value should be < v2static boolean strPicture(long src, java.lang.String pict, java.lang.String posNegPointExp, char cFracSep, StringFunctions_C.PrepareBufferPos bufferPos) throws java.io.IOException
src
- The number to showpict
- picture or outfit, for example "+33221.11"
posNegPointExp
- String with 4 character which are contained in the pict, usual "+-.E", can be null
or lesser if the function is not used.
This arguments clarifies the meaning of this special characters.
If the character is in the pict and is also found here, it has the following meaning
depending on the position where it is found:
cFracSep
- Character which is used instead a exponent charjava.io.IOException
public static java.lang.Appendable appendIntPict(java.lang.Appendable appendable, long src, java.lang.String pict) throws java.io.IOException
appendable
- append heresrc
- the numberpict
- picture or outfit, for example "+33221.11"
java.io.IOException
- not expected