com.moneydance.util
Class StringUtils

java.lang.Object
  extended by com.moneydance.util.StringUtils

public class StringUtils
extends java.lang.Object

Useful string manipulation functions


Constructor Summary
StringUtils()
           
 
Method Summary
static java.lang.String base64Encode(java.lang.String str)
          Encode the given string as a (utf8) byte array and then encode that using base64 and return the result as a string.
static java.lang.String convertToFileName(java.lang.String str)
          Performs a conversion from the given string to an encoded version that can be used as a file/URL name.
static int countFields(java.lang.String str, char delimiter)
           
static java.lang.String decode(java.lang.String str)
           
static byte[] decodeHex(java.lang.String s)
           
static java.lang.String decodeURL(java.lang.String str)
          This method decodes a URL parameter that has special characters %encoded
static void doNothing()
           
static java.lang.String encode(java.lang.String str)
           
static java.lang.String encodeHex(byte[] buf, boolean breaklines)
           
static java.lang.String fieldIndex(java.lang.String str, char delimiter, int n)
           
static java.lang.String fillLeft(java.lang.String str, int width, char fillChar)
           
static java.lang.String fillRight(java.lang.String str, int width, char fillChar)
           
static java.lang.String formatFixedDecimals(java.lang.String value, char decimalChar, int numDecimals)
          Formats the given double [0..1.00] as a percentage with the specified number of decimal digits showing.
static java.lang.String formatMinDecimals(java.lang.String value, char decimalChar, int numDecimals)
          Formats the given double [0..1.00] as a percentage with the specified number of decimal digits showing as a minimum, there could be more.
static java.lang.String formatPercentage(double value, char decimalChar)
          Formats the given double [0..1.00] as a percentage with either zero (if an even percentage) or two decimal digits showing.
static java.lang.String formatPercentage(double value, char decimalChar, boolean forceDecimal)
          Formats the given double [0..1.00] as a percentage with either zero (if an even percentage) or two decimal digits showing.
static java.lang.String formatRate(double rate, char decimalChar)
           
static java.lang.String formatShortRate(double rate, char decimalChar)
           
static java.lang.String getGMTDateStr(java.util.Date dt)
           
static java.lang.String getNLengthString(int width, char fillChar)
           
static char guessDecimalType(java.lang.String currencyString)
           
static boolean isAllNumber(java.lang.String str)
           
static boolean isBlank(java.lang.String candidate)
          Null safe check for a String with nothing but whitespace characters.
static boolean isEmpty(java.lang.String candidate)
          Null safe check for "" (empty string).
static boolean isInteger(java.lang.String str)
           
static boolean isNumeric(java.lang.String str)
           
static boolean looksLikeFormula(java.lang.String expr)
           
static void main(java.lang.String[] argv)
           
static long parseCurrencyExpression(java.lang.String str, char dec, CurrencyType toCurr, CurrencyTable currTable)
           
static long parseCurrencyExpression(java.lang.String str, char dec, CurrencyType toCurr, CurrencyTable currTable, boolean insertDecimal)
           
static double parseDouble(java.lang.String val, char decimalChar)
           
static double parseDouble(java.lang.String val, double defaultVal, char decimalChar)
           
static double parseDoubleWithException(java.lang.String val, char decimalChar)
           
static double parseFormula(java.lang.String str, char dec)
           
static double parseFraction(java.lang.String fraction, char decimalChar)
          Parse a fraction from a string - ie "1/5".
static long parseQuickenDate(java.lang.String date)
           
static double parseRate(java.lang.String rateStr, char decimalChar)
           
static double parseRate(java.lang.String rateStr, double defaultRate, char decimalChar)
           
static java.lang.String replaceAll(java.lang.String str, java.lang.String toReplace, java.lang.String replaceWith)
          Replace one or more tokens inside another string with a value.
static void sortStringArray(java.lang.String[] array)
           
static java.lang.String[] split(java.lang.String str, char splitChar)
           
static java.lang.String stripNonNumbers(java.lang.String str, char decimalChar)
           
static java.lang.String[] vectorToStringArray(java.util.Vector v)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
Method Detail

encodeHex

public static final java.lang.String encodeHex(byte[] buf,
                                               boolean breaklines)

decodeHex

public static final byte[] decodeHex(java.lang.String s)

base64Encode

public static final java.lang.String base64Encode(java.lang.String str)
Encode the given string as a (utf8) byte array and then encode that using base64 and return the result as a string. Note: Only available as of build 528


split

public static final java.lang.String[] split(java.lang.String str,
                                             char splitChar)

vectorToStringArray

public static final java.lang.String[] vectorToStringArray(java.util.Vector v)

getNLengthString

public static final java.lang.String getNLengthString(int width,
                                                      char fillChar)

getGMTDateStr

public static final java.lang.String getGMTDateStr(java.util.Date dt)

main

public static final void main(java.lang.String[] argv)

fillLeft

public static final java.lang.String fillLeft(java.lang.String str,
                                              int width,
                                              char fillChar)

fillRight

public static final java.lang.String fillRight(java.lang.String str,
                                               int width,
                                               char fillChar)

fieldIndex

public static final java.lang.String fieldIndex(java.lang.String str,
                                                char delimiter,
                                                int n)

countFields

public static final int countFields(java.lang.String str,
                                    char delimiter)

sortStringArray

public static final void sortStringArray(java.lang.String[] array)

stripNonNumbers

public static final java.lang.String stripNonNumbers(java.lang.String str,
                                                     char decimalChar)

isInteger

public static final boolean isInteger(java.lang.String str)

isAllNumber

public static final boolean isAllNumber(java.lang.String str)

isNumeric

public static final boolean isNumeric(java.lang.String str)

guessDecimalType

public static final char guessDecimalType(java.lang.String currencyString)

decodeURL

public static final java.lang.String decodeURL(java.lang.String str)
This method decodes a URL parameter that has special characters %encoded


decode

public static final java.lang.String decode(java.lang.String str)

encode

public static final java.lang.String encode(java.lang.String str)

convertToFileName

public static final java.lang.String convertToFileName(java.lang.String str)
Performs a conversion from the given string to an encoded version that can be used as a file/URL name. This is new as of Moneydance build 325.


formatRate

public static final java.lang.String formatRate(double rate,
                                                char decimalChar)

formatShortRate

public static final java.lang.String formatShortRate(double rate,
                                                     char decimalChar)

parseFraction

public static final double parseFraction(java.lang.String fraction,
                                         char decimalChar)
Parse a fraction from a string - ie "1/5". Returns 1 if there was an error in the format


parseRate

public static final double parseRate(java.lang.String rateStr,
                                     char decimalChar)

parseRate

public static final double parseRate(java.lang.String rateStr,
                                     double defaultRate,
                                     char decimalChar)

parseDouble

public static final double parseDouble(java.lang.String val,
                                       char decimalChar)

parseDouble

public static final double parseDouble(java.lang.String val,
                                       double defaultVal,
                                       char decimalChar)

parseDoubleWithException

public static final double parseDoubleWithException(java.lang.String val,
                                                    char decimalChar)
                                             throws java.lang.Exception
Throws:
java.lang.Exception

formatPercentage

public static java.lang.String formatPercentage(double value,
                                                char decimalChar)
Formats the given double [0..1.00] as a percentage with either zero (if an even percentage) or two decimal digits showing.

Parameters:
value - The value as a decimal (is multiplied by 100 for display).
decimalChar - The decimal character to display.
Returns:
A percentage for display to the user, which will have 2 decimal digits unless it is an even integer percent, in which case it will have no decimal digits displayed.

formatPercentage

public static java.lang.String formatPercentage(double value,
                                                char decimalChar,
                                                boolean forceDecimal)
Formats the given double [0..1.00] as a percentage with either zero (if an even percentage) or two decimal digits showing. If forceDecimal is true, digits after the decimal point will be displayed regardless of whether it is an even percentage or not.

Parameters:
value - The value as a decimal (is multiplied by 100 for display).
decimalChar - The decimal character to display.
forceDecimal - True to always display digits after the decimal point, false to only display them if it is not an even integer percentage.
Returns:
A percentage for display to the user, which will have 2 decimal digits unless it is an even integer percent, in which case it will have no decimal digits displayed.

formatFixedDecimals

public static java.lang.String formatFixedDecimals(java.lang.String value,
                                                   char decimalChar,
                                                   int numDecimals)
Formats the given double [0..1.00] as a percentage with the specified number of decimal digits showing.

Parameters:
value - The numeric string as currently formatted.
decimalChar - The decimal character to display.
numDecimals - The number of decimals to force display of.
Returns:
The provided string with exactly the number of decimal places requested.

formatMinDecimals

public static java.lang.String formatMinDecimals(java.lang.String value,
                                                 char decimalChar,
                                                 int numDecimals)
Formats the given double [0..1.00] as a percentage with the specified number of decimal digits showing as a minimum, there could be more.

Parameters:
value - The numeric string as currently formatted.
decimalChar - The decimal character to display.
numDecimals - The number of decimals to force display of.
Returns:
The provided string with the number of decimal places requested as a minimum.

parseQuickenDate

public static final long parseQuickenDate(java.lang.String date)

looksLikeFormula

public static final boolean looksLikeFormula(java.lang.String expr)

parseCurrencyExpression

public static final long parseCurrencyExpression(java.lang.String str,
                                                 char dec,
                                                 CurrencyType toCurr,
                                                 CurrencyTable currTable)
                                          throws java.lang.Exception
Throws:
java.lang.Exception

parseCurrencyExpression

public static final long parseCurrencyExpression(java.lang.String str,
                                                 char dec,
                                                 CurrencyType toCurr,
                                                 CurrencyTable currTable,
                                                 boolean insertDecimal)
                                          throws java.lang.Exception
Throws:
java.lang.Exception

parseFormula

public static final double parseFormula(java.lang.String str,
                                        char dec)
                                 throws java.lang.Exception
Throws:
java.lang.Exception

doNothing

public static void doNothing()

replaceAll

public static java.lang.String replaceAll(java.lang.String str,
                                          java.lang.String toReplace,
                                          java.lang.String replaceWith)
Replace one or more tokens inside another string with a value.

Parameters:
str - The string containing the token(s).
toReplace - The token, case sensitive, to be replaced.
replaceWith - The string to replace the token with. Can be null.
Returns:
The str string with the token replaced with a new value.

isEmpty

public static boolean isEmpty(java.lang.String candidate)
Null safe check for "" (empty string).

Parameters:
candidate - the String to evaluate.
Returns:
true if candidate is null or "" (empty string)

isBlank

public static boolean isBlank(java.lang.String candidate)
Null safe check for a String with nothing but whitespace characters.

Parameters:
candidate - the String to evaluate.
Returns:
true if the candidate is null or all whitespace.