|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectto.etc.util.StringTool
public class StringTool
This static utility class contains a load of string functions. And some other stuff I could not quickly find a place for ;-)
Constructor Summary | |
---|---|
StringTool()
|
Method Summary | |
---|---|
static void |
addPathToVector(java.util.List<java.lang.String> v,
java.lang.String p)
Adds a path to the vector specified, if the path is an existing file or directory, and it doesn't already exist in the vector. |
static void |
addSearchEnvToVector(java.util.List<java.lang.String> v,
java.lang.String envvar)
Adds the value of a "search path environment variable" to the vector. |
static void |
addSearchPathToVector(java.util.List<java.lang.String> v,
java.lang.String searchpath)
Takes a search path, i.e. |
static void |
arrayToAsciiStr(java.lang.Appendable sb,
byte[] ar,
int bi,
int nc)
Returns a string containing only printable chars for the given bytes. |
static void |
arrayToDumpLine(java.lang.Appendable sb,
byte[] ar,
int bi,
int nc)
Returns a dumpstring containing the offset, the hex bytes, and the ascii representation of a given dump buffer. |
static void |
arrayToHexStr(java.lang.Appendable sb,
byte[] ar,
int bi,
int nc,
boolean fillout)
Returns a string of hex bytes for a given thing. |
static void |
createInsertStatement(java.lang.StringBuilder sb,
java.lang.String table,
java.lang.String pkname,
java.lang.String pkexpr,
java.lang.String[] fields)
|
static void |
createUpdateStatement(java.lang.StringBuilder sb,
java.lang.String table,
java.lang.String pkname,
java.lang.String[] fields)
|
static boolean |
dbGetBool(java.lang.String fv)
Returns a boolean value from some database field. |
static java.lang.String |
dbSetBool(boolean v)
Returns a char(1) value to store in a database for booleans. |
static byte[] |
decodeBase64(byte[] data)
This method decodes the given byte[] using the base64-encoding specified in RFC-2045 (Section 6.8). |
static byte[] |
decodeBase64(java.lang.String str)
This method decodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8). |
static java.lang.String |
decodeBase64ToString(java.lang.String str)
This method decodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8). |
static java.lang.String |
decodeURLEncoded(java.lang.String encoded)
Decode the URLEncoded string passed to a real string. |
static void |
dumpData(java.lang.Appendable sb,
byte[] ar,
int off,
int len)
Dump the data as a formatted multiline buffer: like |
static void |
dumpLocation(java.lang.String msg)
|
static byte[] |
encodeBase64(byte[] data)
This method encodes the given byte[] using the base64-encoding specified in RFC-2045 (Section 6.8). |
static java.lang.String |
encodeBase64(java.lang.String str)
This method encodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8). |
static java.lang.String |
encodeBase64ToString(byte[] data)
|
static void |
encodeURLEncoded(java.lang.Appendable sb,
java.lang.String str)
Encode the string passed to URLEncoded format. |
static java.lang.String |
encodeURLEncoded(java.lang.String str)
|
static void |
entitiesToUnicode(java.lang.Appendable sb,
java.lang.String str,
boolean ignoremarkers)
Scans the input string for entities and replaces all entities that are actually found with their Unicode character code. |
static int |
entityToUnicode(java.lang.String ename)
Translates an entity name to unicode. |
static boolean |
equalStringList(java.util.List<java.lang.String> inl,
java.util.List<java.lang.String> al,
boolean caseindependent)
|
static java.lang.String |
extractSingleLine(java.lang.String in)
Tries to extract a single line of max. |
static java.io.File |
findFileOnEnv(java.lang.String pname,
java.lang.String env)
Finds a filename along the classpath.. |
static java.io.File |
findFileOnPath(java.lang.String fname,
java.lang.String path)
Returns the complete filename of the first file that is found along the path specified. |
static java.lang.String |
fixFileURL(java.lang.String fileurl)
|
static byte[] |
fromHex(java.lang.String s)
Decodes a hex string into a byte array. |
static java.lang.String |
generateGUID()
Generate an unique identifier with reasonable expectations that it will be globally unique. |
static byte[] |
getBase64Map()
|
static java.util.List<java.lang.String> |
getEnvironment()
Returns the list of environment variables of the supported OS's. |
static java.lang.String |
getExceptionMessage(java.lang.Throwable t)
If the throwable passed as a message then return it verbatim, else return the exception's classname. |
static java.lang.String |
getFileExtension(java.lang.String fn)
Deprecated. |
static java.lang.String |
getFinalFrom(java.lang.Class<?> cl,
long sval)
|
static java.lang.String |
getFinalFrom(java.lang.Class<?> cl,
long sval,
java.lang.String part)
Traverses a given class and tries to find a public |
static java.lang.String |
getFinalFrom(java.lang.Class<?> cl,
long sval,
java.lang.String part,
java.lang.String ign)
Traverses a given class and tries to find a public |
static int |
getJreVersion()
|
static int |
getLevenshteinDistance(java.lang.String s,
java.lang.String t,
boolean ignorecase)
This returns the Levenshtein distance between two strings, which is the number of changes (adds, removes) that are needed to convert source into target. |
static java.lang.String |
getLocation()
|
static void |
getLocation(java.lang.StringBuffer sb)
|
static java.lang.String |
getNextPathComponent(int ix,
java.lang.String s,
boolean includeslash)
Find the 1st part of the path passed, i.e. |
static java.lang.String |
getNextPathComponent(java.lang.String s,
boolean includeslash)
|
static void |
htmlStringize(java.lang.Appendable o,
java.lang.String is)
Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent. |
static java.lang.String |
htmlStringize(java.lang.String is)
Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent. |
static void |
htmlStringize(java.lang.StringBuilder sb,
java.lang.String is)
Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent. |
static java.lang.String |
intToStr(int val,
int radix,
int npos)
Returns a number in the specified base, and with the specified #of positions. |
static boolean |
isAllSpaces(java.lang.String s)
|
static boolean |
isDomainChar(char c)
|
static boolean |
isEqual(java.lang.Object a,
java.lang.Object b)
|
static boolean |
isNumber(java.lang.String s)
|
static boolean |
isValidDbFieldName(java.lang.String s)
Field name must start with ascii letter, then letters, digits or _. |
static boolean |
isValidDomainName(java.lang.String s)
Checks if the name is a valid domain name. |
static boolean |
isValidDottedName(java.lang.String s)
|
static boolean |
isValidEmail(java.lang.String em)
|
static boolean |
isValidJavaIdentifier(java.lang.String s)
|
static boolean |
isWhiteSpaceOrNbsp(char c)
|
static void |
main(java.lang.String[] args)
|
static java.lang.String |
makeSearchPath(java.util.List<java.lang.String> v)
Returns a string buffer containing a search path variable from the vector passed. |
static java.lang.String |
makeSearchPath(java.lang.String[] v)
Returns a string buffer containing a search path variable from the vector passed. |
static void |
makeSearchPath(java.lang.StringBuffer sb,
java.lang.String[] v)
Returns a string buffer containing a search path variable from the vector passed. |
static void |
makeSearchPath(java.lang.StringBuilder sb,
java.util.List<java.lang.String> v)
Returns a string buffer containing a search path variable from the vector passed. |
static java.lang.String |
makeURL(java.io.File f)
Workaround for Java bug delivering file:// instead of file:/// for file.toURL().toString(). |
static java.lang.String |
normalizeConcat(java.lang.String current,
java.lang.String tpl)
Called when generate() is called with a string. |
static java.lang.String |
normalizeUndot(java.lang.String ins)
Takes an input URL and handles all '.' and '..' replacements. |
static java.lang.String |
normalizeURL(java.lang.String current,
java.lang.String tpl)
Called when generate() is called with a string. |
static void |
parseString(java.lang.StringBuffer sb,
java.lang.String s)
Takes a java string, without quotes, and replaces all escape sequences in there with their actual character representation. |
static void |
printHex(java.io.PrintStream pw,
byte[] arr)
|
static void |
printHex(java.io.PrintStream pw,
byte[] arr,
int start,
int end)
|
static void |
printHex(java.io.PrintWriter pw,
byte[] arr)
|
static void |
printHex(java.io.PrintWriter pw,
byte[] arr,
int start,
int end)
|
static java.lang.String |
removeRepeatingCharacters(java.lang.String in)
Replaces long character sequences without space like ---- and ===== with a way shorter version. |
static void |
strAddIntFixed(java.lang.Appendable sb,
int val,
int radix,
int len)
Converts the integer to a string with a fixed length, adding leading zeroes if needed. |
static java.lang.String |
strBackslashToSlash(java.lang.String s)
Takes an input string and replaces all occurences of the backslash with a forward slash. |
static java.lang.String |
strCommad(long val)
Returns a properly formatted commad string for a number [english only]. |
static java.lang.String |
strDuration(long dlt)
|
static java.lang.String |
strDurationMillis(long dlt)
|
static boolean |
strEndsWithIgnoreCase(java.lang.String st,
java.lang.String with)
Returns T if the string ends with the specified string, while ignoring case. |
static int |
strIndexOfIgnoreCase(java.lang.String txt,
java.lang.String match)
Tries to locate a substring in a string while ignoring case. |
static java.lang.StringBuffer |
stringize(java.lang.String s)
Converts a string into a java-compilable version of a string, i.e. |
static void |
stringize(java.lang.StringBuffer sb,
java.lang.String s)
|
static java.lang.StringBuffer |
stringizeNQ(java.lang.String s)
|
static java.lang.String |
strNanoTime(long ns)
Return a nanotime timestamp with 2 thousands of precision max. |
static java.lang.String |
strOracleTruncate(java.lang.String in,
int nchars)
Handles Oracle truncation rules: If the string is > nchars truncate to nchars Convert the string to bytes in UTF-8 encoding If the string length, in bytes, is > 4000 bytes (the max stupid size of Oracle's stupid varchar2 column, stupid) remove characters until the string fits the stupidly limited Oracle column |
static java.lang.String |
strReplace(java.lang.String src,
java.lang.String old,
java.lang.String nw)
Case-sensitive replace of all occurences of [old] with [new]. |
static java.lang.String |
strSize(long sz)
Returns a string representing some size, in bytes. |
static void |
strStacktrace(java.lang.Appendable sb,
java.lang.Throwable t)
|
static java.lang.String |
strStacktrace(java.lang.Throwable t)
|
static void |
strStacktraceFiltered(java.lang.Appendable sb,
java.lang.Throwable t,
java.lang.String[] skipbefore,
java.lang.String[] skipafter,
int linelimit)
Report a filtered location stack trace, where the start of the stack trace and the end can be removed. |
static boolean |
strStartsWithIgnoreCase(java.lang.String st,
java.lang.String with)
Returns T if the string starts with the specified string, while ignoring case. |
static java.lang.String |
strToFixedLength(java.lang.String s,
char c,
int l)
Returns a string with the specified length. |
static java.lang.String |
strToFixedLength(java.lang.String s,
int l)
Returns a string with the specified length. |
static int |
strToInt(java.lang.String v,
int defval)
|
static void |
strToJavascriptString(java.lang.Appendable w,
java.lang.String cs,
boolean dblquote)
|
static java.lang.String |
strToJavascriptString(java.lang.String cs,
boolean dblquote)
|
static long |
strToLong(java.lang.String v,
int six,
int eix,
int defval)
|
static long |
strToLong(java.lang.String v,
long defval)
|
static java.lang.String |
strTrunc(java.lang.String s,
int len)
|
static java.lang.String |
strUnquote(java.lang.String s)
|
static java.lang.String |
strUnspace(java.lang.String s)
Removes all whitespace from a string. |
static java.lang.String |
toHex(byte[] arr)
Converts the byte array to a hex string. |
static java.lang.String |
toHex(byte[] arr,
int start,
int end)
Converts the byte array passed to a hex string. |
static java.lang.String |
toHexSp(byte[] arr)
Converts the byte array to a hex string. |
static java.lang.String |
toHexSp(byte[] arr,
int start,
int end)
Converts the byte array passed to a hex string. |
static java.lang.String |
toXY(int x,
int y)
Returns a coordinate pair as a string. |
static java.lang.String |
truncLength(java.lang.String s,
int maxlen)
If the input string is too long, returns a substring containing at most maxlen characters. |
static void |
unicodeToEntities(java.lang.StringBuffer sb,
java.lang.String str)
Replaces all non-ascii stuff with their entities. |
static java.lang.String |
urlLastPart(java.lang.String url)
Returns the last element (document name?) from the url passed. |
static java.lang.String |
xmlStringize(java.lang.String is)
Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent. |
static void |
xmlStringize(java.lang.StringBuffer sb,
java.lang.String is)
Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StringTool()
Method Detail |
---|
public static boolean isValidJavaIdentifier(java.lang.String s)
public static boolean isValidDomainName(java.lang.String s)
s
-
public static boolean isNumber(java.lang.String s)
public static boolean isDomainChar(char c)
public static boolean isWhiteSpaceOrNbsp(char c)
public static boolean isAllSpaces(java.lang.String s)
public static boolean isValidEmail(java.lang.String em)
public static boolean isValidDbFieldName(java.lang.String s)
s
-
public static boolean isValidDottedName(java.lang.String s)
public static boolean isEqual(java.lang.Object a, java.lang.Object b)
public static void stringize(java.lang.StringBuffer sb, java.lang.String s)
public static java.lang.StringBuffer stringize(java.lang.String s)
public static java.lang.StringBuffer stringizeNQ(java.lang.String s)
public static java.lang.String strBackslashToSlash(java.lang.String s)
public static java.lang.String strSize(long sz)
public static void parseString(java.lang.StringBuffer sb, java.lang.String s)
public static java.lang.String truncLength(java.lang.String s, int maxlen)
public static java.lang.String strToFixedLength(java.lang.String s, int l)
public static java.lang.String strToFixedLength(java.lang.String s, char c, int l)
public static java.lang.String toXY(int x, int y)
public static int getLevenshteinDistance(java.lang.String s, java.lang.String t, boolean ignorecase)
public static boolean strStartsWithIgnoreCase(java.lang.String st, java.lang.String with)
st
- the string whose start is to be checkedwith
- the start string
public static boolean strEndsWithIgnoreCase(java.lang.String st, java.lang.String with)
st
- the string whose end is to be checkedwith
- the end string
public static int strIndexOfIgnoreCase(java.lang.String txt, java.lang.String match)
txt
- match
-
public static java.lang.String intToStr(int val, int radix, int npos)
public static void strAddIntFixed(java.lang.Appendable sb, int val, int radix, int len)
sb
- val
- radix
- len
- public static java.lang.String strCommad(long val)
val
-
public static java.lang.String strDuration(long dlt)
public static java.lang.String strDurationMillis(long dlt)
public static java.lang.String strTrunc(java.lang.String s, int len)
public static void arrayToHexStr(java.lang.Appendable sb, byte[] ar, int bi, int nc, boolean fillout) throws java.io.IOException
java.io.IOException
public static void arrayToAsciiStr(java.lang.Appendable sb, byte[] ar, int bi, int nc) throws java.io.IOException
java.io.IOException
public static void arrayToDumpLine(java.lang.Appendable sb, byte[] ar, int bi, int nc) throws java.io.IOException
java.io.IOException
public static void dumpData(java.lang.Appendable sb, byte[] ar, int off, int len) throws java.io.IOException
0000 ff ef aa bb cc dd 99 88 ff ef aa bb cc dd 99 88 sgdfkajse
sb
- ar
- off
- len
-
java.io.IOException
public static void printHex(java.io.PrintWriter pw, byte[] arr)
public static void printHex(java.io.PrintWriter pw, byte[] arr, int start, int end)
public static void printHex(java.io.PrintStream pw, byte[] arr)
public static void printHex(java.io.PrintStream pw, byte[] arr, int start, int end)
public static java.lang.String toHex(byte[] arr, int start, int end)
arr
- the array containing the data to convertstart
- the first byte in the array to convertend
- the exclusive end of the region to convert
public static java.lang.String toHex(byte[] arr)
arr
-
public static java.lang.String toHexSp(byte[] arr, int start, int end)
arr
- the array containing the data to convertstart
- the first byte in the array to convertend
- the exclusive end of the region to convert
public static java.lang.String toHexSp(byte[] arr)
arr
-
public static byte[] fromHex(java.lang.String s) throws java.lang.Exception
s
- the string
java.lang.Exception
- if the array is malformed.public static java.io.File findFileOnPath(java.lang.String fname, java.lang.String path)
public static java.io.File findFileOnEnv(java.lang.String pname, java.lang.String env)
@Deprecated public static java.lang.String getFileExtension(java.lang.String fn)
FileTool.getFileExtension(String)
public static void addPathToVector(java.util.List<java.lang.String> v, java.lang.String p)
public static void addSearchPathToVector(java.util.List<java.lang.String> v, java.lang.String searchpath)
public static void addSearchEnvToVector(java.util.List<java.lang.String> v, java.lang.String envvar)
addSearchPathToVector()
public static void makeSearchPath(java.lang.StringBuilder sb, java.util.List<java.lang.String> v)
public static java.lang.String makeSearchPath(java.util.List<java.lang.String> v)
public static void makeSearchPath(java.lang.StringBuffer sb, java.lang.String[] v)
public static java.lang.String makeSearchPath(java.lang.String[] v)
public static java.lang.String getFinalFrom(java.lang.Class<?> cl, long sval)
public static java.lang.String getFinalFrom(java.lang.Class<?> cl, long sval, java.lang.String part)
public static java.lang.String getFinalFrom(java.lang.Class<?> cl, long sval, java.lang.String part, java.lang.String ign)
public static java.lang.String urlLastPart(java.lang.String url)
public static java.lang.String htmlStringize(java.lang.String is)
public static void htmlStringize(java.lang.StringBuilder sb, java.lang.String is)
public static void htmlStringize(java.lang.Appendable o, java.lang.String is) throws java.lang.Exception
java.lang.Exception
public static java.lang.String xmlStringize(java.lang.String is)
public static void xmlStringize(java.lang.StringBuffer sb, java.lang.String is)
public static void entitiesToUnicode(java.lang.Appendable sb, java.lang.String str, boolean ignoremarkers) throws java.io.IOException
sb
- the buffer to append the string tostr
- the string to copy while replacing entities.
java.io.IOException
public static void unicodeToEntities(java.lang.StringBuffer sb, java.lang.String str)
sb
- str
- public static int entityToUnicode(java.lang.String ename)
ename
-
public static java.lang.String strToJavascriptString(java.lang.String cs, boolean dblquote)
public static void strToJavascriptString(java.lang.Appendable w, java.lang.String cs, boolean dblquote) throws java.io.IOException
java.io.IOException
public static boolean dbGetBool(java.lang.String fv)
public static java.lang.String dbSetBool(boolean v)
public static void main(java.lang.String[] args)
public static java.util.List<java.lang.String> getEnvironment()
public static final byte[] getBase64Map()
public static final java.lang.String encodeBase64(java.lang.String str)
str
- the string
public static final byte[] encodeBase64(byte[] data)
data
- the data
public static final java.lang.String decodeBase64ToString(java.lang.String str)
str
- the base64-encoded string.
public static final byte[] decodeBase64(java.lang.String str)
str
- the base64-encoded string.
public static final byte[] decodeBase64(byte[] data)
data
- the base64-encoded data.
public static final java.lang.String encodeBase64ToString(byte[] data)
public static java.lang.String strStacktrace(java.lang.Throwable t)
public static void strStacktrace(java.lang.Appendable sb, java.lang.Throwable t)
public static void strStacktraceFiltered(java.lang.Appendable sb, java.lang.Throwable t, java.lang.String[] skipbefore, java.lang.String[] skipafter, int linelimit)
sb
- t
- skipbefore
- skipafter
- public static final java.lang.String normalizeURL(java.lang.String current, java.lang.String tpl) throws java.lang.Exception
Called when generate() is called with a string. This must decode the string into a key object that can be used by the decodeInputURL key to determine a resource provider and a provider-relative key.
This default implementation assumes that the key is to be a normal URL string, and uses path semantics to create the actual key from the string passed: if it contains a host name it is stripped; if it is relative then the complete path is appended.
java.lang.Exception
public static final java.lang.String normalizeConcat(java.lang.String current, java.lang.String tpl) throws java.lang.Exception
Called when generate() is called with a string. This must decode the string into a key object that can be used by the decodeInputURL key to determine a resource provider and a provider-relative key.
This default implementation assumes that the key is to be a normal URL string, and uses path semantics to create the actual key from the string passed: if it contains a host name it is stripped; if it is relative then the complete path is appended.
java.lang.Exception
public static final java.lang.String normalizeUndot(java.lang.String ins)
ins
- the input URL
public static int strToInt(java.lang.String v, int defval)
public static long strToLong(java.lang.String v, long defval)
public static long strToLong(java.lang.String v, int six, int eix, int defval)
public static java.lang.String getNextPathComponent(int ix, java.lang.String s, boolean includeslash)
s
-
public static java.lang.String getNextPathComponent(java.lang.String s, boolean includeslash)
public static boolean equalStringList(java.util.List<java.lang.String> inl, java.util.List<java.lang.String> al, boolean caseindependent)
public static java.lang.String makeURL(java.io.File f)
f
-
public static java.lang.String fixFileURL(java.lang.String fileurl)
public static void encodeURLEncoded(java.lang.Appendable sb, java.lang.String str)
sb
- data
- public static java.lang.String encodeURLEncoded(java.lang.String str)
public static java.lang.String decodeURLEncoded(java.lang.String encoded)
encoded
-
public static final java.lang.String getLocation()
public static final void getLocation(java.lang.StringBuffer sb)
public static final void dumpLocation(java.lang.String msg)
public static java.lang.String strUnquote(java.lang.String s)
public static java.lang.String strUnspace(java.lang.String s)
s
-
public static java.lang.String strOracleTruncate(java.lang.String in, int nchars)
in
- nchars
-
public static java.lang.String strNanoTime(long ns)
ns
-
public static java.lang.String strReplace(java.lang.String src, java.lang.String old, java.lang.String nw)
src
- old
- nw
-
public static java.lang.String getExceptionMessage(java.lang.Throwable t)
t
-
public static int getJreVersion()
public static java.lang.String removeRepeatingCharacters(java.lang.String in)
in
- maxlen
-
public static java.lang.String extractSingleLine(java.lang.String in)
in
-
public static java.lang.String generateGUID()
public static void createInsertStatement(java.lang.StringBuilder sb, java.lang.String table, java.lang.String pkname, java.lang.String pkexpr, java.lang.String[] fields)
public static void createUpdateStatement(java.lang.StringBuilder sb, java.lang.String table, java.lang.String pkname, java.lang.String[] fields)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |