Novell exteNd
Director 5.2 API

com.sssw.fw.util
Class EboStringMisc

java.lang.Object
 |
 +--com.sssw.fw.util.EboStringMisc

public class EboStringMisc
extends Object

Provides miscellaneous routines that manipulate Strings.


Field Summary
static String DOT
          A constant for "." (the 'dot' character as a String).
static String m_emptyStr
          An empty String.
static String[] m_emptyStrArray
          An empty String array.
static String NULL
          A constant for "null".
 
Constructor Summary
EboStringMisc()
           
 
Method Summary
static String[] clone(String[] strArray)
          Fully clones a String array.
static String collectionToString(Collection coll, String delim)
          Converts the passed in Collection of objects to a delimited String.
static int containsAnyChar(String s, String characters)
          The index of the first occurrance of any character of one string in another.
static boolean containsIgnoreCase(String[] sa, String string)
          Returns true if the string array contains the specified string, ignoring case.
static String createPath(String base, String relative, String separator)
          Creates a path, given the base and the relative path.
static String createPath(String base, String relative, String ext, String separator, boolean useExtInRelative)
          Creates a path, given a base path, a relative path, and an extension.
static boolean endsWithIgnoreCase(String s, String suffix)
          Checks whether the specified String ends with the specified suffix, in a case-insensitive manner.
static boolean equalsIgnoreCase(String[] sa1, String[] sa2)
          Compares two String arrays and returns true if the two arrays have the same length and contain the same String values.
static String escape(String in, String escapeCharacters)
          Escapes special characters with backslashes in the specified String.
static String filePathToPackageName(String filePath)
          Converts a java file path string with either '\' or '/' to a package syntax ('.')
static int findMatchingChar(String str, int offset, int ch)
          Finds a matching character in the specified String.
static int[] findNextJavaToken(String str, int offset)
          A helper routine to find the next Java token in a String.
static int[] findNextJavaWord(String str, int offset)
          A helper routine to find the next Java ID in a String.
static int[] findPrevJavaToken(String str, int offset)
          Finds the previous Java token in a String.
static int[] findPrevJavaWord(String str, int offset)
          A helper routine to find the previous Java ID in a String.
static int findWhitespace(String str, int offset)
          Searches for the next character in the specified string that is whitespace, starting with the given offset.
static int findWord(String in, int offset, String word, String wordChars)
          Finds whole words in a String.
static String firstPart(String string, char c)
          Returns the part of the string before the first occurrence of the specified character.
static String getBaseName(String fullyQualifiedName)
          Returns a new string with the extension (last .*) chopped off.
static String getEncoding(String val)
          Return a character string representing the encoding of the characters in this buffer.
static String getEncodingName(String name)
          The names of the encodings used in java are not well defined The current ones in use are, worse still, not named with the correct IANA name (see http://www.iana.org/ or specifically http://www.isi.edu/in-notes/iana/assignments/character-sets) This routine will take a name of an encoding and return a string that can be used in various java APIs (like String.getBytes(String enc)).
static String getExtension(String fullyQualifiedName)
          Returns the extension of the name or null if no extension was found
static boolean isAsciiChar(char c)
          Checks if the specified character is an ASCII one.
static boolean isAsciiString(String s)
          Checks for non-ASCII characters in the specified String.
static boolean isEmpty(String s)
          Checks to see whether the specified String is null or empty.
static boolean isWhitespace(String str)
          Check to see if the specified String contains nothing but whitespace characters.
static boolean isWideChar(char c)
          Checks for characters with the high byte set.
static boolean isWideCharIncluded(String s)
          Checks if the specified String includes characters with the high byte set.
static String javaEscape(String in)
          Escapes a string for inclusion in generated Java code.
static String lastPart(String string, char c)
          Returns the part of the string after the last occurrence of the specified character.
static String packageNameToFilePath(String packageName, char separatorChar)
          Converts a java package name string with '.'s to a file path syntax using the given directory separator char.
static int prevSkipWhite(String str, int offset)
          Returns the index of the previous character in the string that is not whitespace or -1 if no more whitespace
static String readLongString(com.sssw.fw.util.DataInput in)
          No information available
static String removeBadCharacters(String s, String okCharacters)
          Removes "bad" characters from a String.
static String removeExtension(String string)
          Returns the part of the string before the last occurrence of '.'.
static String removeTrailingFileSeparator(String str)
          Returns a new string with a trailing "/" or "\" removed or the original string if no trailing "/" or "\" exists.
static String removeTrailingSlash(String str)
          Returns a new string with a trailing "/" removed or the original string if no trailing "/" exists.
static String replaceString(String in, String find, String replace)
          Replaces all occurrences of one String with another String in the specified master String.
static String replaceStringIgnoreCase(String in, String find, String replace)
          Finds occurrences of one String in another and replaces them with the specified replacement String.
static String replaceWord(String in, String word, String replace, String wordChars)
          Finds/replaces whole words.
static int safeCompare(String s1, String s2)
          Safely compares two strings.
static boolean safeEquals(String s1, String s2, boolean ignoreCase)
          Safely tests two strings for equality.
static String safeToString(Object obj)
          Return a non-null String representation of the passed-in object.
static int skipWhite(String str, int offset)
          Skips the whitespace characters, if any, in the given string, starting from the specified offset.
static String[] split(String str, String seps)
          Breaks up the specified String into tokens, given a delimiter String.
static String[] splitPath(String path)
          Splits the passed in path into a filename and an extension.
static boolean startsWithIgnoreCase(String string, String start)
          Checks in a case-insensitive manner whether the string begins with the text of 'start'
static String stringArrayToString(String[] ar, String delim)
          Converts a string array into a single string.
static Vector stringArrayToVector(String[] ar)
          Converts a String array to Vector.
static Collection stringToCollection(String s, String delim)
          Given a String and a delimiter sequence, parses the String out into a Collection of tokens that are separated by the delimiter within the String.
static Vector stringToVector(String s)
          Parses the passed in String (containing newline characters) into a Vector of Strings.
static Vector stringToVector(String s, String delim)
          Tokenizes the specified String using the passed in delimiter.
static String stripChars(String s, String strippedChars)
          Returns a new string with the given characters stripped from the orginal string.
static String[] toStringArray(String str)
          Wraps a given String in an array.
static String toUnicodeEscapeString(String str)
          Gets a unicode-escape String.
static String translateString(String in, String[] args)
          Translates the specified String.
static String translateStringEx(String in, Object[] args)
          Translates a String.
static String unescape(String in, String escapeCharacters)
          Undoes the effects of the escape method.
static String unsignedHexString(int value)
          Returns an unsigned Hex String corresponding to the passed in integer value.
static void writeLongString(String str, com.sssw.fw.util.DataOutput out)
          No information available
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_emptyStrArray

public static String[] m_emptyStrArray
An empty String array.

m_emptyStr

public static String m_emptyStr
An empty String.

DOT

public static String DOT
A constant for "." (the 'dot' character as a String).

NULL

public static String NULL
A constant for "null".
Constructor Detail

EboStringMisc

public EboStringMisc()
Method Detail

firstPart

public static String firstPart(String string,
                               char c)
Returns the part of the string before the first occurrence of the specified character. If the character does not exist in the string, returns an empty string. E.g. firstPart("com.sssw.fw.util.EboStringMisc", '.') returns "com".
Parameters:
string - the string to search in
c - the character to search for
Returns:
the part of the string before the first occurrence of c

lastPart

public static String lastPart(String string,
                              char c)
Returns the part of the string after the last occurrence of the specified character. If the character does not exist in the string, returns an empty string. E.g. lastPart("com.sssw.fw.util.EboStringMisc", '.') returns "EboStringMisc".
Parameters:
string - the string to search in
c - the character to search for
Returns:
the part of the string after the last occurrence of the specified character, or an empty string if not found

removeExtension

public static String removeExtension(String string)
Returns the part of the string before the last occurrence of '.'. E.g. removeExtension("image.gif") returns "image". E.g. removeExtension("xxx") returns "xxx".
Parameters:
string - the string to process
Returns:
the part of the string before the last occurrence of '.'

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(String string,
                                           String start)
Checks in a case-insensitive manner whether the string begins with the text of 'start'
Parameters:
string - the string to test
start - the string to test for
Returns:
true if the string begins with the text of 'start', disregarding the case

containsIgnoreCase

public static boolean containsIgnoreCase(String[] sa,
                                         String string)
Returns true if the string array contains the specified string, ignoring case.
Parameters:
sa - the string array
string - the string to search for
Returns:
true if the string array contains the specified string, ignoring case, false otherwise

equalsIgnoreCase

public static boolean equalsIgnoreCase(String[] sa1,
                                       String[] sa2)
Compares two String arrays and returns true if the two arrays have the same length and contain the same String values. Note: the String values do not have to be in the same order. This is a case insensitive comparison.
Parameters:
sa1 - the first String array
sa2 - the second String array
Returns:
true if the two arrays have the same length and contain the same String values

endsWithIgnoreCase

public static boolean endsWithIgnoreCase(String s,
                                         String suffix)
Checks whether the specified String ends with the specified suffix, in a case-insensitive manner.
Parameters:
s - the string
suffix - the suffix
Returns:
true if the specified String ends with the specified suffix, in a case-insensitive manner

removeTrailingSlash

public static String removeTrailingSlash(String str)
Returns a new string with a trailing "/" removed or the original string if no trailing "/" exists.
Parameters:
str - the string to process
Returns:
the processed string

removeTrailingFileSeparator

public static String removeTrailingFileSeparator(String str)
Returns a new string with a trailing "/" or "\" removed or the original string if no trailing "/" or "\" exists.
Parameters:
str - the string to process
Returns:
the processed string

clone

public static String[] clone(String[] strArray)
Fully clones a String array.
Parameters:
strArray - the String array to copy
Returns:
clone of the String Array

isEmpty

public static boolean isEmpty(String s)
Checks to see whether the specified String is null or empty.
Parameters:
s - the String to check
Returns:
true if the specified String is null or empty, false otherwise

replaceString

public static String replaceString(String in,
                                   String find,
                                   String replace)
Replaces all occurrences of one String with another String in the specified master String.
Parameters:
in - the String to replace occurrences in
find - the String to find in the master String
replace - the String to replace the occurrences of 'find' with
Returns:
the resulting String

replaceStringIgnoreCase

public static String replaceStringIgnoreCase(String in,
                                             String find,
                                             String replace)
Finds occurrences of one String in another and replaces them with the specified replacement String. The search is done in a case-insensitive manner.
Parameters:
in - the String to replace in
find - the String to find
replace - the String to replace with
Returns:
the resulting String

replaceWord

public static String replaceWord(String in,
                                 String word,
                                 String replace,
                                 String wordChars)
Finds/replaces whole words.
Parameters:
in - the input string.
word - the word to find and replace in the input string.
replace - the string to replace each occurrance of "word" with.
wordChars - the characters (outside of alphabetic range) that can be considered part of a word. For example for replacing words in Java source one might pass "_0123456789"
Returns:
the resulting String
See Also:
EboEditBuffer, replaceString

findWord

public static int findWord(String in,
                           int offset,
                           String word,
                           String wordChars)
Finds whole words in a String.
Parameters:
in - the input string.
offset - the offset to start the search from.
word - the word to find in the input string.
wordChars - the characters (outside of alphabetic range) that can be considered part of a word. For example for replacing words in Java source one might pass "_0123456789"
Returns:
the index of the first occurrance of the word or -1 if not found
See Also:
EboEditBuffer, replaceString, replaceWord

findPrevJavaToken

public static int[] findPrevJavaToken(String str,
                                      int offset)
Finds the previous Java token in a String. A token is either a Java ID or a number. If offset is within a java string, finds the previous ID, not this one.
Parameters:
str - the input string.
offset - the offset to start the search from.
Returns:
an array of indecies where ary[0] is the starting index of the Java identifier, ary[1] is the ending index. If a Java identifier was not found then both entires will be -1.
See Also:
EboEditBuffer, findWord, replaceString, replaceWord, findNextJavaToken, findPrevJavaWord, findNextJavaWord

findPrevJavaWord

public static int[] findPrevJavaWord(String str,
                                     int offset)
A helper routine to find the previous Java ID in a String. If offset is within a java string we find the previous ID, not this one.
Parameters:
str - the input string.
offset - the offset to start the search from.
Returns:
an array of indecies where ary[0] is the starting index of the Java identifier, ary[1] is the ending index. If a Java identifier was not found then both entires will be -1.
See Also:
EboEditBuffer, findWord, replaceString, replaceWord

findNextJavaToken

public static int[] findNextJavaToken(String str,
                                      int offset)
A helper routine to find the next Java token in a String. A token is either a Java ID or number. If offset is within a java string we find the next ID, not this one.
Parameters:
str - the input string.
offset - the offset to start the search from.
Returns:
an array of indecies where ary[0] is the starting index of the Java identifier, ary[1] is the ending index. If a Java identifier was not found then both entires will be -1.
See Also:
EboEditBuffer, findWord, replaceString, replaceWord, findPrevJavaToken, findPrevJavaWord, findNextJavaToken, findNextJavaWord

findNextJavaWord

public static int[] findNextJavaWord(String str,
                                     int offset)
A helper routine to find the next Java ID in a String. If offset is within a Java string then get the next one.
Parameters:
str - the input string.
offset - the offset to start the search from.
Returns:
an array of indecies where ary[0] is the starting index of the Java identifier, ary[1] is the ending index. If a Java identifier was not found then both entires will be -1.
See Also:
EboEditBuffer, findWord, replaceString, replaceWord

skipWhite

public static int skipWhite(String str,
                            int offset)
Skips the whitespace characters, if any, in the given string, starting from the specified offset.
Parameters:
str - the string to search
offset - the offset to start the search from
Returns:
the index of the next character in the string that is not whitespace or -1 if no more whitespace

findWhitespace

public static int findWhitespace(String str,
                                 int offset)
Searches for the next character in the specified string that is whitespace, starting with the given offset.
Parameters:
str - - the string to search
offset - - the offset to start the search from
Returns:
the index of the next character in the string that is whitespace or -1 if no more whitespace

isWhitespace

public static boolean isWhitespace(String str)
Check to see if the specified String contains nothing but whitespace characters.
Parameters:
str - the string to test
Returns:
true if the string contains nothing but whitespace

prevSkipWhite

public static int prevSkipWhite(String str,
                                int offset)
Returns the index of the previous character in the string that is not whitespace or -1 if no more whitespace
Parameters:
str - the string to search
offset - the offset to start the search from
Returns:
the index of the previous character in the string that is not whitespace or -1 if no more whitespace

findMatchingChar

public static int findMatchingChar(String str,
                                   int offset,
                                   int ch)
Finds a matching character in the specified String.
Parameters:
str - the string to search
offset - the offset to start the search from
ch - the character to whose match should be search for, can be one of the following:
  • '(' - search forward, filtering out nested ()'s
  • ')' - search backward, filtering out nested ()'s
  • '[' - search forward, filtering out nested []'s
  • ']' - search backward, filtering out nested []'s
  • '{' - search forward, filtering out nested {}'s
  • '}' - search backward, filtering out nested {}'s
Returns:
the index of the matching character to the one given or -1 if no match or unrecognized character was given. The character at offset is assumed to be within the matching pair. It should not be one of the end characters

translateString

public static String translateString(String in,
                                     String[] args)
Translates the specified String.
See Also:
EboEditBuffer

translateStringEx

public static String translateStringEx(String in,
                                       Object[] args)
Translates a String. This method is like translateString. There are two differences. 1. args is an Object[] rather than a String[] 2. replacement tokens in the string must be in the for of %xxx% rather than %x.

escape

public static String escape(String in,
                            String escapeCharacters)
Escapes special characters with backslashes in the specified String. E.g. escape("1234", "24") => "1\23\4"
Parameters:
in - The string to be modified
escapeCharacters - The list of escape characters
Returns:
escaped String

unescape

public static String unescape(String in,
                              String escapeCharacters)
Undoes the effects of the escape method.
Parameters:
in - the string to be modified
escapeCharacters - the list of escape characters
Returns:
the unescaped String

javaEscape

public static String javaEscape(String in)
Escapes a string for inclusion in generated Java code. Escapes double-quotes and backslashes with backslashes. Also changes all characters where the high byte is set, to the Unicode escape sequence \\uXXXX

unsignedHexString

public static String unsignedHexString(int value)
Returns an unsigned Hex String corresponding to the passed in integer value.
Parameters:
value - the integer value
Returns:
the unsinged Hex String value

containsAnyChar

public static int containsAnyChar(String s,
                                  String characters)
The index of the first occurrance of any character of one string in another.
Parameters:
s - the string to search.
characters - the characters to search for in 's'.
Returns:
the index of the first occurrance of any character of 'characters' string in 's' or -1 if none found

removeBadCharacters

public static String removeBadCharacters(String s,
                                         String okCharacters)
Removes "bad" characters from a String. Replaces "bad" characters with underscores, but only where it would look nice. For example: removeBadCharacters("ab$*^ab#%##ab", "%.,") yields "ab_ab_%_ab". Note: all letters, digits, and underscores are always assumed to be "OK" characters.
Parameters:
s - the String to process
okCharacters - the "OK" characters
Returns:
the resulting String

stripChars

public static String stripChars(String s,
                                String strippedChars)
Returns a new string with the given characters stripped from the orginal string.
Parameters:
s - the String to process
strippedChars - the characters that are to be stripped from the specified String
Returns:
a new string with the given characters stripped from the orginal string

getEncoding

public static String getEncoding(String val)
Return a character string representing the encoding of the characters in this buffer. As a performance optimization for sending Strings across the wire, we check to see whether the entire String is Latin-1 (ISO-8859-1), and if so, return that. Otherwise, we return "unicode", since that's what we are.

getEncodingName

public static String getEncodingName(String name)
The names of the encodings used in java are not well defined The current ones in use are, worse still, not named with the correct IANA name (see http://www.iana.org/ or specifically http://www.isi.edu/in-notes/iana/assignments/character-sets) This routine will take a name of an encoding and return a string that can be used in various java APIs (like String.getBytes(String enc)). It will translate what it knows and otherwise return the input string. No guarantee is made that the encoder is actually installed IANA character set names are case insensitive and limited to 40 characters. It's unclear if java encoding names have any limitations or descriptions. The built in table was generated by taking all the IANA names and aliases of each charset listed in the JDK 1.1 i18n documention. If this list is too large trim it to only the 19 preferred MIME names listed in the comment as MIME

stringToVector

public static Vector stringToVector(String s)
Parses the passed in String (containing newline characters) into a Vector of Strings.
Parameters:
s - the String to process
Returns:
a Vector of lines extracted from the String

stringToVector

public static Vector stringToVector(String s,
                                    String delim)
Tokenizes the specified String using the passed in delimiter.
Parameters:
s - the String to tokenize
delim - the delimiter to use
Returns:
a Vector filled with tokens

stringToCollection

public static Collection stringToCollection(String s,
                                            String delim)
Given a String and a delimiter sequence, parses the String out into a Collection of tokens that are separated by the delimiter within the String.
Parameters:
s - the String to parse
delim - the delimiter String
Returns:
a Collection of tokens, or empty Collection if none

stringArrayToVector

public static Vector stringArrayToVector(String[] ar)
Converts a String array to Vector. If the array is null, returns an empty Vector.
Parameters:
ar - the array to convert
Returns:
the resulting Vector

stringArrayToString

public static String stringArrayToString(String[] ar,
                                         String delim)
Converts a string array into a single string. E.g. if the array contains "A", "B", and "C" and the delimiter is ", ", then the resulting string will be "A, B, C".
Parameters:
ar - the array to convert
delim - the delimiter to use
Returns:
converted string

collectionToString

public static String collectionToString(Collection coll,
                                        String delim)
Converts the passed in Collection of objects to a delimited String. The toString methods of the Collection member objects are used to get the String representation of the objects.
Parameters:
coll - the Collection to convert
delim - the delimiter to use
Returns:
the resulting String

toStringArray

public static String[] toStringArray(String str)
Wraps a given String in an array.
Parameters:
str - the String to wrap as a String array
Returns:
a String array whose 0-th and only element is the specified String

split

public static String[] split(String str,
                             String seps)
Breaks up the specified String into tokens, given a delimiter String.
Parameters:
str - the String to split
seps - the delimiter String
Returns:
an array of String tokens

filePathToPackageName

public static String filePathToPackageName(String filePath)
Converts a java file path string with either '\' or '/' to a package syntax ('.')
Parameters:
filePath - the file path to convert.
Returns:
a Java file path string with either '\' or '/' replaced with '.'s

packageNameToFilePath

public static String packageNameToFilePath(String packageName,
                                           char separatorChar)
Converts a java package name string with '.'s to a file path syntax using the given directory separator char.
Parameters:
packageName - the string to convert to file path syntax
separatorChar - the separator character to use when replacing '.'s in the package name

getBaseName

public static String getBaseName(String fullyQualifiedName)
Returns a new string with the extension (last .*) chopped off. If no '.' is found then the original string is returned.

getExtension

public static String getExtension(String fullyQualifiedName)
Returns the extension of the name or null if no extension was found
Parameters:
fullyQualifiedName - the filename to get extension from
Returns:
the file extension or null if none

splitPath

public static String[] splitPath(String path)
Splits the passed in path into a filename and an extension. The extension has to be one of the file extensions registered in the Director Framework Service subsystem's config.xml file.
Parameters:
path - the path to split
Returns:
a String array where the 0-the element is the base filename and the first element is the extension, if any (null if no registered extension was matched)

createPath

public static String createPath(String base,
                                String relative,
                                String ext,
                                String separator,
                                boolean useExtInRelative)
Creates a path, given a base path, a relative path, and an extension.
Parameters:
base - the base path, if any (null may be passed in)
relative - the relative path, if any (null may be passed in)
ext - extension, if any
separator - the path separator; if null, the system-dependent default name-separator character (java.io.File.separator) is used
useExtInRelative - if true, any extension found in the relative path, is used as the extension in the returned path, otherwise the value of the ext parameter is used
Returns:
the resulting path

createPath

public static String createPath(String base,
                                String relative,
                                String separator)
Creates a path, given the base and the relative path.
Parameters:
base - the base path
relative - the relative path
separator - separator, if any (defaults to java.io.File.separator)
Returns:
the resulting path

readLongString

public static String readLongString(com.sssw.fw.util.DataInput in)
                             throws com.sssw.fw.util.IOException
No information available

writeLongString

public static void writeLongString(String str,
                                   com.sssw.fw.util.DataOutput out)
                            throws com.sssw.fw.util.IOException
No information available

isAsciiChar

public static boolean isAsciiChar(char c)
Checks if the specified character is an ASCII one.
Parameters:
c - the character to check
Returns:
true if ASCII character, false otherwise

isAsciiString

public static boolean isAsciiString(String s)
Checks for non-ASCII characters in the specified String.
Parameters:
s - the String to check
Returns:
boolean true if all characters are ASCII, false if at least one character is non-ASCII

isWideChar

public static boolean isWideChar(char c)
Checks for characters with the high byte set.
Parameters:
c - the character to check
Returns:
true if the character's high byte is set, false otherwise

isWideCharIncluded

public static boolean isWideCharIncluded(String s)
Checks if the specified String includes characters with the high byte set.
Parameters:
s - the String to check
Returns:
true if the string includes characters with the high byte set, false otherwise

safeEquals

public static boolean safeEquals(String s1,
                                 String s2,
                                 boolean ignoreCase)
Safely tests two strings for equality. The passed in strings may be null.
Parameters:
s1 - the first string
s2 - the second string
ignoreCase - if true, ignore case, otherwise, compare in the case-sensitive manner
Returns:
true if the two String's are equal

safeCompare

public static int safeCompare(String s1,
                              String s2)
Safely compares two strings. The passed in strings may be null.
Parameters:
s1 - the first string
s2 - the second string
Returns:
the result of comparison; 0 if equal, a value less than 0 if s1 precedes s2, and a value more than 0 if s2 precedes s1

toUnicodeEscapeString

public static String toUnicodeEscapeString(String str)
Gets a unicode-escape String.

safeToString

public static String safeToString(Object obj)
Return a non-null String representation of the passed-in object.
Parameters:
obj - the object
Returns:
the result of calling toString on the passed-in object, or EboStringMisc.NULL if the object is null

Novell exteNd
Director 5.2 API