| Modifier and Type | Field and Description |
|---|---|
protected static double |
adjustement
holds the base adjustment for fuzzy matching
|
static char[] |
HEX_CHARS
Holds the chars for hex encoding
|
static NSDictionary<String,String> |
HTML_SAFE_UNESCAPES
Safe HTML entities to unescape (SYMBOL+ISO).
|
static NSDictionary<String,String> |
HTML_UNESCAPES
HTML entities to unescape (XML+SYMBOL+ISO).
|
static NSDictionary<String,String> |
ISO_UNESCAPES
ISO entities to unescape.
|
static NSArray |
SORT_ASCENDING
Holds the ascending
EOSortOrderings |
static NSArray |
SORT_DESCENDING
Holds the ascending
EOSortOrderings |
static String |
SpecialRegexCharacters
Holds characters that have special meaning for regex
|
static NSDictionary<String,String> |
SYMBOL_UNESCAPES
Symbol entities to unescape.
|
static NSDictionary<String,String> |
XML_UNESCAPES
XML entities to unescape.
|
| Constructor and Description |
|---|
ERXStringUtilities() |
| Modifier and Type | Method and Description |
|---|---|
static void |
appendSeparatorIfLastNot(char separator,
char not,
StringBuffer sb)
Utility method to append a character to a
StringBuffer if the last character is not
a certain character.
|
static void |
appendSeparatorIfLastNot(char separator,
char not,
StringBuilder sb)
Utility method to append a character to a
StringBuilder if the last character is not
a certain character.
|
static Object |
attributeCustomValueFromString(EOAttribute attr,
String strVal,
String encoding)
Attempts to convert string values for attributes into the appropriate
value class for the attribute.
|
static Number |
attributeNumberValueFromString(EOAttribute attr,
String strVal)
Attempts to convert string values for attributes into the appropriate
value class for the attribute.
|
static Object |
attributeValueFromString(EOAttribute attr,
String strVal,
String encoding,
Format formatter)
Attempts to convert string values for attributes into the appropriate
value class for the attribute.
|
static String |
byteArrayToHexString(byte[] block)
Converts a byte array to hex string.
|
static String |
camelCaseToUnderscore(String camelString,
boolean lowercase)
Converts a string in camel case to an underscore representation.
|
static String |
capitalize(String value)
Capitalizes a given string.
|
static String |
capitalizeAllWords(String value)
Capitalizes all the strings in a given string.
|
static boolean |
caseInsensitiveStartsWith(String stringToSearch,
String prefix)
Tests if the string starts with the specified prefix ignoring case.
|
static boolean |
caseInsensitiveStartsWith(String stringToSearch,
String prefix,
int toffset)
Tests if the string starts with the specified prefix starting at the specified index ignoring case.
|
static String |
cleanString(String newString,
NSArray<String> toBeCleaneds)
Given an initial string and an array of substrings,
Removes any occurrences of any of the substrings
from the initial string.
|
static boolean |
containsAnyCharacter(String source,
String characters)
Checks if any of the characters specified in characters is contained in the string
specified by source.
|
static String |
displayNameForKey(String key)
Calculates a default display name for a given
key path.
|
static String |
dumpObject(Object object)
Creates a readable debug string for some data types (dicts, arrays, adaptorOperations, databaseOperations).
|
static String |
emptyStringForNull(String s)
Simple utility method that will return the
string "" if the string passed in is null
otherwise it will return the passed in
string.
|
static String |
escape(char[] _escapeChars,
char _escapeWith,
String _sourceString)
Escapes the given characters with the given escape character in _sourceString.
|
static String |
escapeJavascriptApostrophes(String sourceString)
Escapes the apostrophes in a Javascript string with a backslash.
|
static String |
escapeNonBasicLatinChars(char c) |
static String |
escapeNonBasicLatinChars(String str) |
static String |
escapeNonXMLChars(String str) |
static String |
escapePCData(String pcdata)
Escapes the given PCDATA string as CDATA.
|
static String |
excelSafeCsvString(String s)
Removes line breaks and quotes the string if necessary
|
static String |
firstPropertyKeyInKeyPath(String keyPath) |
static String |
fromBytes(byte[] bytes,
String encoding)
Utility to convert from bytes without the try/catch.
|
static String |
fromUTF8Bytes(byte[] bytes)
Utility to convert from UTF-8 bytes without the try/catch.
|
static NSArray |
fuzzyMatch(String name,
String entityName,
String propertyKey,
String synonymsKey,
com.webobjects.eocontrol.EOEditingContext ec,
ERXFuzzyMatchCleaner cleaner,
NSArray sortOrderings)
Fuzzy matching is useful for catching user entered typos.
|
static String |
getSimpleClassName(Class clazz)
"Borrowed" from 1.5's Class.getSimpleClassName
|
static byte[] |
hexStringToByteArray(String hexString)
Converts a even-length, hex-encoded String to a byte array.
|
static void |
indent(PrintWriter writer,
int level) |
static void |
indent(StringBuffer sb,
int level) |
static int |
indexOfNumericInString(String str)
Locate the the first numeric character in the given string.
|
static int |
indexOfNumericInString(String str,
int fromIndex)
Locate the the first numeric character
after
fromIndex in the given string. |
static String |
insertString(String destinationString,
String contentToInsert,
int insertOffset)
Inserts the a string into another string at a particular offset.
|
static Integer |
integerWithString(String s)
Calculates an Integer for a given string.
|
static boolean |
isBlank(String value) |
static boolean |
isNotBlank(String value) |
static boolean |
isValueInRange(int value,
String rangeString)
Returns whether the given value falls in a range defined by the given string, which is
in the format "1-5,100,500,800-1000".
|
static String |
keyPathWithoutFirstProperty(String keyPath) |
static String |
keyPathWithoutLastProperty(String keyPath) |
static String |
lastPropertyKeyInKeyPath(String keyPath) |
static String |
leftPad(String string,
char padChar,
int paddedLength)
Pads a string to the specified number of chars by adding the the given pad char on the left side.
|
static String |
localizedStringForKey(String key)
Gets a localized string for a given key in the application's
Localizable strings file for the default language (English).
|
static String |
localizedStringForKey(String key,
String framework)
Gets a localized string for a given key in a given framework's
Localizable strings file for the default language (English).
|
static String |
localizedStringForKey(String key,
String framework,
NSArray languages)
Gets a localized string for a given key in a given framework's
Localizable strings file using the array of languages as the
search order for the key.
|
static String |
localizedTemplateStringWithObjectForKey(Object o,
String key,
String framework,
NSArray languages)
Uses the method
localizedStringForKey to retreive
a template that is then parsed using the passed in object to
produce a resulting string. |
static boolean |
luhnCheck(String value)
A fast Luhn algorithm check.
|
static String |
maskStringWithCharacter(String arg,
char mask,
int beginIndex,
int endIndex)
Masks a given string with a single character in the substring specified by the
begin and end indexes.
|
static String |
matchCase(String originalString,
String newString)
Returns a string case-matched against the original string.
|
static byte[] |
md5(String str,
String encoding)
Generate an MD5 hash from a String.
|
static String |
md5Hex(String str,
String encoding)
Generate an MD5 hash as hex from a String.
|
static String |
nullForEmptyString(String s)
Simple utility method that will return null
if the string passed in is equal to ""
otherwise it will return the passed in
string.
|
static int |
numberOfOccurrencesOfCharInString(char c,
String s)
Counts the number of occurrences of a particular
char in a given string. |
static boolean |
quicksilverContains(String _str,
String _searchString)
Matches strings like Quicksilver (NullPointerException is matched by "NPE").
|
static String |
quote(String s,
String quoteSymbol)
Quote the given string with the provided quote symbols
|
static boolean |
regionMatches(StringBuffer str,
int toffset,
String other,
int ooffset,
int len)
It's ridiculous that StringBuffer doesn't have a .regionMatches like String.
|
static String |
removeCharacters(String source,
String characters)
Removes any character which is in characters from the source string.
|
static String |
removeExceptCharacters(String source,
String characters)
Removes any character which is not in characters from the source string.
|
static String |
removeExtraDotsFromVersionString(String version)
Cleans up the given version string by removing extra
dots(.), for example, 5.1.3 becomes 5.13, so that
the string can be converted to a double or BigDecimal
type easily.
|
static String |
removeHTMLTagsFromString(String s)
Removes all of the HTML tags from a given string.
|
static String |
removeSpaces(String aString)
Removes the spaces in a given string.
|
static String |
rightPad(String string,
char padChar,
int paddedLength)
Pads a string to the specified number of chars by adding the the given pad char on the right side.
|
static String |
safeIdentifierName(String source)
Convenience method to call safeIdentifierName(source, "_", '_')
|
static String |
safeIdentifierName(String source,
String prefix)
Convenience method to call safeIdentifierName(source, prefix, '_')
|
static String |
safeIdentifierName(String source,
String prefix,
char replacement)
Converts source to be suitable for use as an identifier in JavaScript.
|
static Integer |
safeInteger(String s)
Wrapper for
Integer.valueOf(String) that catches
the NumberFormatException. |
static Long |
safeLong(String s)
Wrapper for
Long.valueOf(String) that catches
the NumberFormatException. |
static void |
setAdjustement(double newAdjustement)
Sets the base adjustment used for fuzzy matching
|
static String |
stringByAppendingCSSClass(String originalString,
String cssClass)
Appends a CSS class to an existing (possibly null) CSS class string.
|
static String |
stringByTruncatingStringToByteLengthInEncoding(String inputString,
int byteLength,
String encoding)
This method takes a string and returns a string which is the first string such that the
result byte length in the specified encoding does not exceed the byte limit.
|
static boolean |
stringContainsSpecialRegexCharacters(String s)
checks if the String contains a character that has a special meaning
in regex.
|
static boolean |
stringEqualsString(String s1,
String s2) |
static String |
stringFromDictionary(NSDictionary dict)
Same as NSPropertySerialization except it sorts on keys first.
|
static String |
stringFromInputStream(InputStream in)
Returns a string from the input stream using the default
encoding.
|
static String |
stringFromInputStream(InputStream in,
String encoding)
Returns a string from the input stream using the default
encoding.
|
static String |
stringFromResource(String name,
String extension,
com.webobjects.foundation.NSBundle bundle)
Retrieves a given string for a given name, extension
and bundle.
|
static String |
stringFromURL(URL url)
Returns a string from the contents of the given URL.
|
static String |
stringFromURL(URL url,
String encoding)
Returns a string from the contents of the given URL.
|
static boolean |
stringIsNullOrEmpty(String s)
Simple test if the string is either null or
equal to "".
|
static boolean |
stringIsParseableInteger(String s)
Tests if a given string object can be parsed into
an integer.
|
static String |
stringWithContentsOfFile(File file)
Reads the contents of a file given by a path
into a string.
|
static String |
stringWithContentsOfFile(String path)
Reads the contents of a file given by a path
into a string.
|
static String |
stringWithNtimesString(int n,
String s)
String multiplication.
|
static String |
stripHtml(String str,
boolean convertChars)
Removes HTML characters from the given string.
|
static String |
strippedValue(String value,
int length)
Returns the value stripped from HTML tags if escapeHTML is false.
|
static byte[] |
toBytes(String string,
String encoding)
Utility to convert to bytes without the try/catch.
|
static String |
toHexString(char c) |
static String |
toHexString(String str) |
static String |
toLowerCase(String str)
This method runs about 20 times faster than
java.lang.String.toLowerCase (and doesn't waste any storage
when the result is equal to the input).
|
static String |
toString(Object[] array,
String separator)
Returns a String by invoking toString() on each object from the array.
|
static byte[] |
toUTF8Bytes(String string)
Utility to convert to UTF-8 bytes without the try/catch.
|
static String |
trimString(String s)
Null-safe wrapper for java.lang.String.trim
|
static String |
trimZeroInFrontOfNumbers(String str)
trim leading 0 from a (Number) String
|
static String |
uncapitalize(String value)
Uncapitalizes a given string.
|
static String |
underscoreToCamelCase(String underscoreString,
boolean capitalize)
Converts this_is_a_test to ThisIsATest
|
static String |
unescapeEntities(String string,
Map<String,String> map)
Util to unescape entities.
|
static String |
unquote(String s,
String quoteSymbol)
Remove the quote symbols from the given string
|
static String |
urlDecode(String string)
Utility to decode an URL without the try/catch.
|
static String |
urlEncode(String string)
Utility to encode an URL without the try/catch.
|
static String |
wordSafeTrimmedString(String trimmingString,
int maxLenght)
Returns a string trimmed about at the max length you define without truncating the last word and adding "..." (if necessary)
|
public static final char[] HEX_CHARS
public static final NSArray SORT_ASCENDING
EOSortOrderingspublic static final NSArray SORT_DESCENDING
EOSortOrderingspublic static final String SpecialRegexCharacters
protected static double adjustement
public static final NSDictionary<String,String> XML_UNESCAPES
public static final NSDictionary<String,String> ISO_UNESCAPES
public static final NSDictionary<String,String> SYMBOL_UNESCAPES
public static final NSDictionary<String,String> HTML_SAFE_UNESCAPES
public static final NSDictionary<String,String> HTML_UNESCAPES
public static void setAdjustement(double newAdjustement)
newAdjustement - factor to be used.public static NSArray fuzzyMatch(String name, String entityName, String propertyKey, String synonymsKey, com.webobjects.eocontrol.EOEditingContext ec, ERXFuzzyMatchCleaner cleaner, NSArray sortOrderings)
name - to be matched againstentityName - name of the entity to perform the match against.propertyKey - to be matched againstsynonymsKey - allows objects to have additional values to be matched
against in addition to just the value of the propertyKeyec - context to fetch data incleaner - object used to clean a string, for example the cleaner might
strip out the words 'The' and 'Inc.'sortOrderings - can be either SORT_ASCENDING or SORT_DESCENDING
to tell how the results should be sorted.public static String localizedStringForKey(String key)
key - to be lookup in the strings filepublic static String localizedStringForKey(String key, String framework)
key - to be lookup in the strings fileframework - name, specify app or null to perform the
lookup in the application's resources.public static String localizedStringForKey(String key, String framework, NSArray languages)
key - to be lookup in the strings fileframework - name, specify app or null to perform the
lookup in the application's resources.languages - array to search for the key inpublic static String localizedTemplateStringWithObjectForKey(Object o, String key, String framework, NSArray languages)
localizedStringForKey to retreive
a template that is then parsed using the passed in object to
produce a resulting string. The template parser used is
ERXSimpleTemplateParser.o - object used to resolve keys in the localized templatekey - to be lookup in the strings fileframework - name, specify app or null to perform the
lookup in the application's resources.languages - array to search for the key inpublic static String stringWithContentsOfFile(File file)
file - path to the file in the file systempublic static String stringWithContentsOfFile(String path)
path - to the file in the file systempublic static Integer integerWithString(String s)
s - string to caclulate an Integer fromer.extensions.eof.ERXConstant#integerForString(String)public static boolean stringIsParseableInteger(String s)
s - string to be parsedtrue if the string is not null
and can be parsed to an intpublic static Integer safeInteger(String s)
Integer.valueOf(String) that catches
the NumberFormatException.s - string to convert to an Integernull if the string could
not be parsedpublic static Long safeLong(String s)
Long.valueOf(String) that catches
the NumberFormatException.s - string to convert to a Longnull if the string could
not be parsedpublic static String stringFromResource(String name, String extension, com.webobjects.foundation.NSBundle bundle)
name - of the resourceextension - of the resource, example: txt or rtfbundle - to look for the resource inpublic static String displayNameForKey(String key)
key - to calculate the display namepublic static int indexOfNumericInString(String str)
str - string to scanpublic static int indexOfNumericInString(String str, int fromIndex)
fromIndex in the given string.str - string to scanfromIndex - index position from where to startpublic static void appendSeparatorIfLastNot(char separator,
char not,
StringBuffer sb)
separator - character to potentially
add to the StringBuffer.not - character to test if the given
StringBuffer ends in it.sb - StringBuffer to test and potentially
append to.public static void appendSeparatorIfLastNot(char separator,
char not,
StringBuilder sb)
separator - character to potentially
add to the StringBuilder.not - character to test if the given
StringBuilder ends in it.sb - StringBuilder to test and potentially
append to.public static String removeSpaces(String aString)
aString - string to remove spaces frompublic static String toLowerCase(String str)
public static String stringWithNtimesString(int n, String s)
n - the number of times to concatenate a given strings - string to be multipliedpublic static int numberOfOccurrencesOfCharInString(char c,
String s)
char in a given string.c - char to count in strings - string to look for specified char in.public static boolean stringIsNullOrEmpty(String s)
s - string to testpublic static String nullForEmptyString(String s)
s - string to testpublic static String emptyStringForNull(String s)
s - string to testpublic static String unescapeEntities(String string, Map<String,String> map)
string - string to unescapemap - map of entitiespublic static String escapePCData(String pcdata)
pcdata - The string to escapepublic static String escapeNonBasicLatinChars(char c)
public static String escapeJavascriptApostrophes(String sourceString)
sourceString - the source string to escapepublic static String escape(char[] _escapeChars, char _escapeWith, String _sourceString)
_escapeChars - the list of characters to escape_escapeWith - the escape character to use_sourceString - the string to escape the characters in.public static String toHexString(char c)
public static String byteArrayToHexString(byte[] block)
block - byte arraypublic static byte[] hexStringToByteArray(String hexString)
hexString - hex string to convertpublic static String removeExtraDotsFromVersionString(String version)
version - stringpublic static String capitalize(String value)
you have a dog", this method would
return "You have a dog".value - to be capitalizedpublic static String uncapitalize(String value)
value - to be uncapitalizedpublic static String capitalizeAllWords(String value)
you have a dog" (with two spaces between each word), this
method would return "You Have A Dog".value - to be capitalizedpublic static String underscoreToCamelCase(String underscoreString, boolean capitalize)
underscoreString - the string_with_underscorescapitalize - if true, the first letter is capitalizedpublic static String camelCaseToUnderscore(String camelString, boolean lowercase)
camelString - string to convertlowercase - if all uppercase characters should be converted to lowercasepublic static boolean caseInsensitiveStartsWith(String stringToSearch, String prefix)
stringToSearch - string to checkprefix - prefix to look forpublic static boolean caseInsensitiveStartsWith(String stringToSearch, String prefix, int toffset)
stringToSearch - string to checkprefix - prefix to look fortoffset - starting offset to perform the searchpublic static String stringByTruncatingStringToByteLengthInEncoding(String inputString, int byteLength, String encoding)
This method is optimized for the UTF-8 case. If encoding is either "UTF-8" or "UTF8",
the optimized case will kick in.
inputString - string to truncatebyteLength - maximum byte lengthencoding - encoding to usepublic static boolean stringContainsSpecialRegexCharacters(String s)
s - the string to checktrue if s contains one or multiple characters that have special
meanings in regex.public static String stringFromURL(URL url) throws IOException
url - the URL to read fromIOException - if the connection failspublic static String stringFromURL(URL url, String encoding) throws IOException
url - the URL to read fromencoding - the string encoding to read withIOException - if the connection failspublic static String stringFromInputStream(InputStream in) throws IOException
in - stream to readIOException - if things go wrongpublic static String stringFromInputStream(InputStream in, String encoding) throws IOException
in - stream to readencoding - to be used, null will use the defaultIOException - if things go wrongpublic static String toString(Object[] array, String separator)
array - an object array from which to get a nice String representationseparator - a separator which is displayed between the objects toString() valuepublic static String dumpObject(Object object)
object - the object to dumppublic static boolean containsAnyCharacter(String source, String characters)
source - the String which might contain characterscharacters - the characters to checkpublic static String removeExceptCharacters(String source, String characters)
source - the string which will be modifiedcharacters - the characters that are allowed to be in sourcepublic static String removeCharacters(String source, String characters)
source - the string which will be modifiedcharacters - the characters that are not allowed to be in sourcepublic static boolean quicksilverContains(String _str, String _searchString)
_str - the string to search in_searchString - the search string to look forpublic static byte[] md5(String str, String encoding)
str - the string to hashencoding - MD5 operates on byte arrays, so we need to know the encoding to getBytes aspublic static String md5Hex(String str, String encoding)
str - the string to hashencoding - MD5 operates on byte arrays, so we need to know the encoding to getBytes aspublic static String matchCase(String originalString, String newString)
originalString - the original string to analyze the case ofnewString - the new stringpublic static void indent(PrintWriter writer, int level)
public static void indent(StringBuffer sb, int level)
public static String getSimpleClassName(Class clazz)
public static String stringFromDictionary(NSDictionary dict)
dict - public static boolean regionMatches(StringBuffer str, int toffset, String other, int ooffset, int len)
str - the StringBuffer to compare a region oftoffset - the starting offset of the sub-region in this string.other - the string argument.ooffset - the starting offset of the sub-region in the string argument.len - the number of characters to compare.true if the specified sub-region of this string
exactly matches the specified sub-region of the string argument;
false otherwise.public static String safeIdentifierName(String source, String prefix, char replacement)
source - String to make into a identifier nameprefix - String to prefix source with to make it a valid identifier namereplacement - character to use to replace characters in source that are no allowed in an identifier nameCharacter.isJavaIdentifierStart(char),
Character.isJavaIdentifierPart(char)public static String safeIdentifierName(String source, String prefix)
source - String to make into a identifier nameprefix - String to prefix source with to make it a valid identifier namesafeIdentifierName(String, String, char)public static String safeIdentifierName(String source)
source - String to make into a identifier namesafeIdentifierName(String, String, char)public static String urlEncode(String string)
string - public static String urlDecode(String string)
string - public static byte[] toUTF8Bytes(String string)
string - string to convertpublic static byte[] toBytes(String string, String encoding)
string - string to convertencoding - public static String fromUTF8Bytes(byte[] bytes)
bytes - string to convertpublic static String fromBytes(byte[] bytes, String encoding)
bytes - string to convertencoding - public static String rightPad(String string, char padChar, int paddedLength)
string - the string to padpadChar - the character to pad withpaddedLength - the length to pad topublic static String leftPad(String string, char padChar, int paddedLength)
string - the string to padpadChar - the character to pad withpaddedLength - the length to pad topublic static String insertString(String destinationString, String contentToInsert, int insertOffset)
destinationString - the string to insert intocontentToInsert - the string to insertinsertOffset - the offset in destinationString to insertpublic static String trimString(String s)
s - string to trimpublic static String excelSafeCsvString(String s)
s - public static String unquote(String s, String quoteSymbol)
s - quoteSymbol - public static String quote(String s, String quoteSymbol)
s - the string to quotequoteSymbol - - the quote symbolpublic static String stringByAppendingCSSClass(String originalString, String cssClass)
originalString - the original stringcssClass - the new CSS class to appendpublic static String stripHtml(String str, boolean convertChars)
str - the string to remove HTML fromconvertChars - set to true if you want html special chars to be converted ( ex. © to (C) ), false otherwisepublic static String removeHTMLTagsFromString(String s)
ERXSimpleHTMLFormatters - html stringpublic static String strippedValue(String value, int length)
public static Object attributeValueFromString(EOAttribute attr, String strVal, String encoding, Format formatter)
attr - The attribute for the value in question.strVal - The string value to be coerced.encoding - The encoding used if the attribute value class is custom
and the factory method does not accept a string.formatter - The formatter used if the value class is NSTimestamp.public static Number attributeNumberValueFromString(EOAttribute attr, String strVal)
attr - The attribute for the value in question.strVal - The string value to be coerced.public static Object attributeCustomValueFromString(EOAttribute attr, String strVal, String encoding)
attr - The attribute for the value in question.strVal - The string value to be coerced.encoding - The encoding used if the attribute value class is custom
and the factory method does not accept a string.public static boolean isValueInRange(int value,
String rangeString)
value - the value to check forrangeString - the range string to parsepublic static String maskStringWithCharacter(String arg, char mask, int beginIndex, int endIndex)
maskStringWithCharacter("Visa 4111111111111111", '*', 5, -4); will
result in a string value of "Visa ************1111"arg - The string value to maskmask - The character maskbeginIndex - The string index where masking begins.
Negative numbers count down from the end of the string.endIndex - The index where masking ends.
Negative numbers count down from the end of the stringpublic static boolean luhnCheck(String value)
value - A string value consisting of numeric digits between 0-9. If
the number contains hyphens, spaces, or anything other than a
string of digits between 0-9 the method returns false.public static String wordSafeTrimmedString(String trimmingString, int maxLenght)
trimmingString - the string you would like to trimmaxLenght - the max length you needpublic static String trimZeroInFrontOfNumbers(String str)
str - - the Stringstr - - 処理対象の文字列public static String cleanString(String newString, NSArray<String> toBeCleaneds)
newString - initial string from which to remove other stringstoBeCleaneds - array of substrings to be removed from the initial string.public static boolean isBlank(String value)
public static boolean isNotBlank(String value)
Copyright © 2002 – 2020 Project Wonder.