ezvcard.util
Class VCardStringUtils

java.lang.Object
  extended by ezvcard.util.VCardStringUtils

public class VCardStringUtils
extends Object

Helper class for dealing with vCard strings.

Author:
Michael Angstadt

Method Summary
static boolean containsNewlines(String text)
          Determines if a string contains one or more newline characters.
static String escape(String text)
          Escapes all special characters within a vCard value.
static String escapeNewlines(String text)
          Escapes all newline characters within a vCard value.
static String ltrim(String string)
          Trims the whitespace off the left side of a string.
static String rtrim(String string)
          Trims the whitespace off the right side of a string.
static String[] splitBy(String str, char ch, boolean removeEmpties, boolean unescape)
          Splits a string by a character, taking escaped characters into account.
static String unescape(String text)
          Unescapes all special characters that are escaped with a backslash, as well as escaped newlines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

unescape

public static String unescape(String text)
Unescapes all special characters that are escaped with a backslash, as well as escaped newlines.

Parameters:
text - the text
Returns:
the unescaped text

escape

public static String escape(String text)
Escapes all special characters within a vCard value.

These characters are:

Parameters:
text - the text to escape
Returns:
the escaped text

escapeNewlines

public static String escapeNewlines(String text)
Escapes all newline characters within a vCard value.

This method escapes the following newline sequences:

Parameters:
text - the text to escape
Returns:
the escaped text

containsNewlines

public static boolean containsNewlines(String text)
Determines if a string contains one or more newline characters.

Parameters:
text - the string
Returns:
true if it contains one or more newline characters, false if not

splitBy

public static String[] splitBy(String str,
                               char ch,
                               boolean removeEmpties,
                               boolean unescape)
Splits a string by a character, taking escaped characters into account. Each split value is also trimmed.

For example:

splitBy("HE\:LLO::WORLD", ':', false, true)

returns

["HE:LLO", "", "WORLD"]

Parameters:
str - the string to split
ch - the character to split by
removeEmpties - true to remove empty elements, false not to
unescape - true to unescape each split string, false not to
Returns:
the split string
See Also:
http://stackoverflow.com/q/820172

ltrim

public static String ltrim(String string)
Trims the whitespace off the left side of a string.

Parameters:
string - the string to trim
Returns:
the trimmed string

rtrim

public static String rtrim(String string)
Trims the whitespace off the right side of a string.

Parameters:
string - the string to trim
Returns:
the trimmed string


Copyright © 2012-2013. All Rights Reserved.