com.neeve.util
Class UtlText

java.lang.Object
  extended by com.neeve.util.UtlText

public class UtlText
extends Object

Utilities for manipulating Text.

This class IS NOT intended to be used by end users.


Constructor Summary
UtlText()
           
 
Method Summary
static String bytesToHexString(byte[] bytes)
          Encodes input byte array as String of hexadecimal digits.
static String deCamelCase(String camelCase)
          Takes a camel case string and splits into to a space separated string
static byte[] hexToBytes(String hexString)
          Converts a hexadecimal string to a byte array after first stripping an spaces from the provided text.
static boolean isNullOrEmpty(String text)
           
static String quoteAndEscape(String string)
          If the given string contains spaces quote it and escape an inner quotes in the sting.
static String readFully(InputStream input, String charset)
          Reads an InputStream fully as a string.
static String removeLineBreaks(String text)
          Removes line breaks for the given text, replacing breaks with a single space.
static String[] retokenizeWithQuotes(StringTokenizer tokenizer, boolean preserveInnerEscapes)
          Given a StringTokenizer this method concatenates all tokens into a string delimited by a single space.
static LinkedList<String> splitCamelCaseString(String s)
          accept a string, like aCamelString and return a list containing strings, in this case, [a, Camel, String]
static boolean startsWithIgnoreCase(String text, String prefix)
          Indicates whether the provided text begins with the prefix, without regard for capitalization.
static String stripQuotesAndUnescape(String string)
          Strips leading and trailing quotes from the given string, if the String starts with a leading '"' character, and unescapes any escaped '"' within the quoted string.
static String toCamelCase(String text, boolean includeFirstLetter)
          Converts text to camel case.
static String toFirstLetterLowercase(String str)
          Returns a string with lowercase first letter.
static String toFirstLetterUppercase(String str)
          Returns a string with uppercases first letter.
static double uniformMetric(String text)
          Map a string to it's location in a uniform distribution of text, with resulting value between 0.0 and 1.0, excluding 1.0 itself.
static String upperCaseFirstLetters(String str)
          Changes the first letter of each word in the provided string to uppercase.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtlText

public UtlText()
Method Detail

uniformMetric

public static double uniformMetric(String text)
Map a string to it's location in a uniform distribution of text, with resulting value between 0.0 and 1.0, excluding 1.0 itself. Hence "a" maps to 0.0, while "zzzzzzzzz" maps to 0.9999999999999 (or so). This method is not suitable for unicode, and only handles the English alphabet, ignoring all numbers, whitespace and punctuation.

Parameters:
text - The text to examine.
Returns:
[0.0, 1.0)

toFirstLetterUppercase

public static String toFirstLetterUppercase(String str)
Returns a string with uppercases first letter.

Parameters:
str - The string
Returns:
The uppercased string.

toFirstLetterLowercase

public static String toFirstLetterLowercase(String str)
Returns a string with lowercase first letter.

Parameters:
str - The string
Returns:
The lowercase string.

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(String text,
                                           String prefix)
Indicates whether the provided text begins with the prefix, without regard for capitalization.

Parameters:
text - The text to examine.
prefix - The prefix to check for.
Returns:
true if the text starts with the prefix.

isNullOrEmpty

public static boolean isNullOrEmpty(String text)
Parameters:
text - to check.
Returns:
True if the provided text or all whitespace.

removeLineBreaks

public static String removeLineBreaks(String text)
Removes line breaks for the given text, replacing breaks with a single space.

Parameters:
text - The text from which to remove line breaks.
Returns:
The single line text.

toCamelCase

public static String toCamelCase(String text,
                                 boolean includeFirstLetter)
Converts text to camel case.

Parameters:
text - the text to be camelcased.
includeFirstLetter - Whether or not to uppercase the first letter or leave it as is.
Returns:
the camel cased text.

deCamelCase

public static final String deCamelCase(String camelCase)
Takes a camel case string and splits into to a space separated string

Parameters:
camelCase - The camel case input
Returns:
The split string.

upperCaseFirstLetters

public static String upperCaseFirstLetters(String str)
Changes the first letter of each word in the provided string to uppercase.

Parameters:
str - The str to augment.
Returns:
The uppercase string.

splitCamelCaseString

public static LinkedList<String> splitCamelCaseString(String s)
accept a string, like aCamelString and return a list containing strings, in this case, [a, Camel, String]

Parameters:
s - The str to split.
Returns:
The split string

hexToBytes

public static final byte[] hexToBytes(String hexString)
Converts a hexadecimal string to a byte array after first stripping an spaces from the provided text.

Parameters:
hexString - The hex encoded string.
Returns:
The decoded hex bytes.

bytesToHexString

public static final String bytesToHexString(byte[] bytes)
Encodes input byte array as String of hexadecimal digits.

Parameters:
bytes - Array to convert.
Returns:
Converted string value.

retokenizeWithQuotes

public static final String[] retokenizeWithQuotes(StringTokenizer tokenizer,
                                                  boolean preserveInnerEscapes)
Given a StringTokenizer this method concatenates all tokens into a string delimited by a single space. It then retokenizes the resulting string honoring quoted String -- i.e. returning text within single or double quotes blocks as a single token

'"' or ''' encountered within quotes can be escaped by prefixing them with a '\'. When in a quote block such tokens are either converted represented in the resulting token either with the escape preserved or removed accoring to the value of preserverInnerEscapes.

Parameters:
tokenizer - The tokenizer to retokenize.
preserveInnerEscapes - If true escape characters inside of quotes are preserved
Returns:
The retokenized string components.

quoteAndEscape

public static final String quoteAndEscape(String string)
If the given string contains spaces quote it and escape an inner quotes in the sting.

Parameters:
string - The string to quote.
Returns:
The passed in string if there are no spaces, or a quoted string.

stripQuotesAndUnescape

public static final String stripQuotesAndUnescape(String string)
Strips leading and trailing quotes from the given string, if the String starts with a leading '"' character, and unescapes any escaped '"' within the quoted string.

Parameters:
string - The string to strip.
Returns:
The stripped string or null if null was passed in.

readFully

public static final String readFully(InputStream input,
                                     String charset)
                              throws IOException
Reads an InputStream fully as a string.

Parameters:
input - The InputStream
charset - The character set to use for file content
Returns:
The file contents as a String.
Throws:
IOException - If there is an error reading the file


Copyright © 2016 Neeve Research, LLC. All Rights Reserved.