public static class BTraceUtils.Strings
extends java.lang.Object
Constructor and Description |
---|
Strings() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Appendable |
append(java.lang.Appendable buffer,
java.lang.String strToAppend)
Appends a string to an appendable buffer created by newStringBuilder()
|
static int |
compareTo(java.lang.String str1,
java.lang.String str2)
Compares two strings lexicographically.
|
static int |
compareToIgnoreCase(java.lang.String str1,
java.lang.String str2)
Compares two strings lexicographically, ignoring case
differences.
|
static java.lang.String |
concat(java.lang.String str1,
java.lang.String str2)
Concatenates the specified strings together.
|
static boolean |
endsWith(java.lang.String s,
java.lang.String end) |
static int |
indexOf(java.lang.String str1,
java.lang.String str2) |
static int |
lastIndexOf(java.lang.String str1,
java.lang.String str2) |
static int |
length(java.lang.Appendable buffer)
Checks the length of an appendable buffer created by newStringBuilder()
|
static int |
length(java.lang.String str)
Returns the length of the given string.
|
static boolean |
matches(java.util.regex.Pattern regex,
java.lang.String input)
Matches the given (precompiled) regular expression and attempts
to match the given input against it.
|
static boolean |
matches(java.lang.String regex,
java.lang.String input)
Compiles the given regular expression and attempts to match the given
input against it.
|
static java.lang.Appendable |
newStringBuilder()
Safely creates a new instance of an appendable string buffer
The buffer will not be thread safe. |
static java.lang.Appendable |
newStringBuilder(boolean threadSafe)
Safely creates a new instance of an appendable string buffer
|
static java.util.regex.Pattern |
pattern(java.lang.String regex)
This is synonym for "regexp".
|
static java.util.regex.Pattern |
pattern(java.lang.String regex,
int flags)
This is synonym for "regexp".
|
static java.util.regex.Pattern |
regexp(java.lang.String regex)
Compiles the given regular expression into a pattern.
|
static java.util.regex.Pattern |
regexp(java.lang.String regex,
int flags)
Compiles the given regular expression into a pattern with the given
flags.
|
static boolean |
startsWith(java.lang.String s,
java.lang.String start) |
static java.lang.String |
str(boolean b)
Returns a String object representing the specified
boolean.
|
static java.lang.String |
str(char c)
Returns a
String object representing the
specified char . |
static java.lang.String |
str(double d)
Returns a string representation of the
double
argument. |
static java.lang.String |
str(float f)
Returns a string representation of the
float
argument. |
static java.lang.String |
str(int i)
Returns a
String object representing the
specified integer. |
static java.lang.String |
str(long l)
Returns a
String object representing the specified
long . |
static java.lang.String |
str(java.lang.Object obj)
Returns a string representation of the object.
|
static java.lang.String |
strcat(java.lang.String str1,
java.lang.String str2)
This is synonym to "concat".
|
static int |
strcmp(java.lang.String str1,
java.lang.String str2)
This is synonym to "compareTo" method.
|
static int |
stricmp(java.lang.String str1,
java.lang.String str2)
This is synonym to "compareToIgnoreCase".
|
static int |
strlen(java.lang.String str)
This is synonym for "length".
|
static int |
strstr(java.lang.String str1,
java.lang.String str2)
Find String within String
|
static java.lang.String |
substr(java.lang.String str,
int start) |
static java.lang.String |
substr(java.lang.String str,
int start,
int length)
Substring
|
static java.lang.String |
toHexString(int i)
Returns a string representation of the integer argument as an
unsigned integer in base 16.
|
static java.lang.String |
toHexString(long l)
Returns a string representation of the
long
argument as an unsigned integer in base 16. |
public static boolean startsWith(java.lang.String s, java.lang.String start)
public static boolean endsWith(java.lang.String s, java.lang.String end)
public static java.lang.String strcat(java.lang.String str1, java.lang.String str2)
concat(String, String)
public static java.lang.String concat(java.lang.String str1, java.lang.String str2)
public static int compareTo(java.lang.String str1, java.lang.String str2)
String
object is compared lexicographically to the
character sequence represented by the second string. The result is
a negative integer if the first String
object
lexicographically precedes the second string. The result is a
positive integer if the first String
object lexicographically
follows the second string. The result is zero if the strings
are equal; compareTo
returns 0
exactly when
the String.equals(Object)
method would return true
.public static int strcmp(java.lang.String str1, java.lang.String str2)
public static int compareToIgnoreCase(java.lang.String str1, java.lang.String str2)
compareTo
with normalized versions of the strings
where case differences have been eliminated by calling
Character.toLowerCase(Character.toUpperCase(character))
on
each character.public static int stricmp(java.lang.String str1, java.lang.String str2)
public static int strstr(java.lang.String str1, java.lang.String str2)
public static int indexOf(java.lang.String str1, java.lang.String str2)
public static int lastIndexOf(java.lang.String str1, java.lang.String str2)
public static java.lang.String substr(java.lang.String str, int start, int length)
public static java.lang.String substr(java.lang.String str, int start)
public static int length(java.lang.String str)
str
- String whose length is calculated.public static int strlen(java.lang.String str)
length(String)
public static java.util.regex.Pattern regexp(java.lang.String regex)
regex
- The expression to be compiledjava.util.regex.PatternSyntaxException
- If the expression's syntax is invalidpublic static java.util.regex.Pattern pattern(java.lang.String regex)
regexp(String)
public static java.util.regex.Pattern regexp(java.lang.String regex, int flags)
regex
- The expression to be compiledflags
- Match flags, a bit mask that may include
Pattern.CASE_INSENSITIVE
, Pattern.MULTILINE
, Pattern.DOTALL
,
Pattern.UNICODE_CASE
, Pattern.CANON_EQ
, Pattern.UNIX_LINES
,
Pattern.LITERAL
and Pattern.COMMENTS
java.lang.IllegalArgumentException
- If bit values other than those corresponding to the defined
match flags are set in flagsjava.util.regex.PatternSyntaxException
- If the expression's syntax is invalidpublic static java.util.regex.Pattern pattern(java.lang.String regex, int flags)
regexp(String, int)
public static boolean matches(java.util.regex.Pattern regex, java.lang.String input)
public static boolean matches(java.lang.String regex, java.lang.String input)
An invocation of this convenience method of the form
behaves in exactly the same way as the expressionPattern.matches(regex, input);
Pattern.compile(regex).matcher(input).matches()
If a pattern is to be used multiple times, compiling it once and reusing it will be more efficient than invoking this method each time.
regex
- The expression to be compiledinput
- The character sequence to be matchedjava.util.regex.PatternSyntaxException
- If the expression's syntax is invalidpublic static java.lang.String str(boolean b)
true
, then
the string "true"
will be returned, otherwise the
string "false"
will be returned.b
- the boolean to be convertedboolean
public static java.lang.String str(char c)
String
object representing the
specified char
. The result is a string of length
1 consisting solely of the specified char
.c
- the char
to be convertedchar
public static java.lang.String str(int i)
String
object representing the
specified integer. The argument is converted to signed decimal
representation and returned as a string.i
- an integer to be converted.public static java.lang.String toHexString(int i)
The unsigned integer value is the argument plus 232
if the argument is negative; otherwise, it is equal to the
argument. This value is converted to a string of ASCII digits
in hexadecimal (base 16) with no extra leading
0
s. If the unsigned magnitude is zero, it is
represented by a single zero character '0'
('\u0030'
); otherwise, the first character of
the representation of the unsigned magnitude will not be the
zero character. The following characters are used as
hexadecimal digits:
These are the characters0123456789abcdef
'\u0030'
through
'\u0039'
and '\u0061'
through
'\u0066'
.i
- an integer to be converted to a string.public static java.lang.String str(long l)
String
object representing the specified
long
. The argument is converted to signed decimal
representation and returned as a string.l
- a long
to be converted.public static java.lang.String str(java.lang.Object obj)
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read. For bootstrap classes, returns the result of
calling Object.toString() override. For non-bootstrap classes,
default toString() value [className@hashCode] is returned.obj
- the object whose string representation is returnedpublic static java.lang.String toHexString(long l)
long
argument as an unsigned integer in base 16.
The unsigned long
value is the argument plus
264 if the argument is negative; otherwise, it is
equal to the argument. This value is converted to a string of
ASCII digits in hexadecimal (base 16) with no extra
leading 0
s. If the unsigned magnitude is zero, it
is represented by a single zero character '0'
('\u0030'
); otherwise, the first character of
the representation of the unsigned magnitude will not be the
zero character. The following characters are used as
hexadecimal digits:
These are the characters0123456789abcdef
'\u0030'
through
'\u0039'
and '\u0061'
through
'\u0066'
.l
- a long
to be converted to a string.long
value represented by the argument in hexadecimal
(base 16).public static java.lang.String str(float f)
float
argument. All characters mentioned below are ASCII characters.
NaN
".
-
' ('\u002D'
); if the sign is
positive, no sign character appears in the result. As for
the magnitude m:
"Infinity"
; thus, positive infinity produces
the result "Infinity"
and negative infinity
produces the result "-Infinity"
.
"0.0"
; thus, negative zero produces the result
"-0.0"
and positive zero produces the result
"0.0"
.
.
'
('\u002E'
), followed by one or more
decimal digits representing the fractional part of
m.
.
' ('\u002E'
), followed by
decimal digits representing the fractional part of
a, followed by the letter 'E
'
('\u0045'
), followed by a representation
of n as a decimal integer, as produced by the
method Integer.toString(int)
.
float
. That is, suppose that x is the
exact mathematical value represented by the decimal
representation produced by this method for a finite nonzero
argument f. Then f must be the float
value nearest to x; or, if two float
values are
equally close to x, then f must be one of
them and the least significant bit of the significand of
f must be 0
.
f
- the float to be converted.public static java.lang.String str(double d)
double
argument. All characters mentioned below are ASCII characters.
NaN
".
-
'
('\u002D'
); if the sign is positive, no sign character
appears in the result. As for the magnitude m:
"Infinity"
; thus, positive infinity produces the result
"Infinity"
and negative infinity produces the result
"-Infinity"
.
"0.0"
; thus, negative zero produces the result
"-0.0"
and positive zero produces the result
"0.0"
.
.
' ('\u002E'
), followed by one or
more decimal digits representing the fractional part of m.
.
'
('\u002E'
), followed by decimal digits
representing the fractional part of a, followed by the
letter 'E
' ('\u0045'
), followed
by a representation of n as a decimal integer, as
produced by the method Integer.toString(int)
.
double
. That is, suppose that
x is the exact mathematical value represented by the decimal
representation produced by this method for a finite nonzero argument
d. Then d must be the double
value nearest
to x; or if two double
values are equally close
to x, then d must be one of them and the least
significant bit of the significand of d must be 0
.
d
- the double
to be converted.public static java.lang.Appendable newStringBuilder(boolean threadSafe)
threadSafe
- Specifies whether the buffer should be thread safepublic static java.lang.Appendable newStringBuilder()
public static java.lang.Appendable append(java.lang.Appendable buffer, java.lang.String strToAppend)
buffer
- The appendable buffer to append tostrToAppend
- The string to appendpublic static int length(java.lang.Appendable buffer)
buffer
- The appendable buffer instance