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 float |
parseFloat(java.lang.CharSequence src,
int pos,
int sizeP,
char decimalpoint,
int[] parsedCharsP)
Parses a given String and convert it to the float number.
|
static float |
parseFloat(java.lang.CharSequence src,
int pos,
int sizeP,
int[] parsedChars) |
static int |
parseIntRadix(java.lang.CharSequence srcP,
int pos,
int sizeP,
int radix,
int[] parsedChars) |
static int |
parseIntRadix(java.lang.CharSequence srcP,
int pos,
int sizeP,
int radix,
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 pos,
int sizeP,
int radix,
int[] parsedChars,
java.lang.String separatorChars)
Adequate method for long values, see
#parseIntRadix(String, int, int, int, int[], String) . |
static long |
parseUlong(java.lang.CharSequence src,
int pos,
int size,
int radix,
int[] parsedChars,
java.lang.String separatorChars) |
(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
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 radix, 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.
One can use Integer.MAX_VALUE
to parse till the end of the Stringradix
- The radix of the number, typical 2, 10 or 16, max 36.parsedChars
- number of chars which is used to parse the integer. The pointer may be null if not necessary. @pjava2c=simpleVariableRef.spaceChars
- maybe null, some characters which are skipped by reading the digits. It is especially ". '" to skip over a dot, or spaces or '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)
parsedChars
- number of chars which is used to parse. The pointer may be null if not necessary. @pjava2c=simpleVariableRef.public static long parseLong(java.lang.CharSequence srcP, int pos, int sizeP, int radix, int[] parsedChars, java.lang.String separatorChars)
#parseIntRadix(String, int, int, int, int[], String)
.parsedChars
- number of chars which is used to parse. The pointer may be null if not necessary. @pjava2c=simpleVariableRef.separatorChars
- Any character are accept inside the number as a separation character. For Example _ or ' or , to write:
12'345 12,234 12_345
which is parsed as 12345 in any case. Usual such as "'"public static long parseUlong(java.lang.CharSequence src, int pos, int size, int radix, int[] parsedChars, java.lang.String separatorChars)
src
- Any CharSequence which should start on pos with a digit representation.pos
- start position in src.size
- max number of chars from src. The given size should not exceed the size of src. Note: other than in parseLong(CharSequence, int, int, int, int[], String)
.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]. The position [0] returns the number of the digits.separatorChars
- Any character are accept inside the number as a separation character. For Example _ or ' or , to write:
12'345 12,234 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.size
- 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)
src
- pos
- sizeP
- parsedChars
- number of chars which is 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)
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
- it is possible to use a ',' for german numbers.parsedCharsP
- 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
static 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