org.eclipse.xtend.backend.util
Class StringHelper

java.lang.Object
  extended by org.eclipse.xtend.backend.util.StringHelper

public final class StringHelper
extends java.lang.Object

This class is a collection of helper functions for string handling.

Author:
Arno Haase (http://www.haase-consulting.com)

Constructor Summary
StringHelper()
           
 
Method Summary
static boolean endsWithAny(java.lang.String str, java.util.Collection<java.lang.String> prefixes)
          tests if a string ends with any one of a collection of prefixes
static boolean endsWithAny(java.lang.String str, java.lang.String[] prefixes)
          tests if a string ends with any one of a collection of prefixes
static java.lang.String escape(java.lang.String src)
          replaces special characters that affect formatting with non-formatting character sequences.
static java.lang.String firstLower(java.lang.String str)
           
static java.lang.String firstUpper(java.lang.String str)
           
static java.lang.String getTypeAsString(java.lang.Object o)
           
static java.util.List<java.lang.String> getTypesAsString(java.util.List<?> l)
           
static int numMatches(java.lang.String s, char ch)
          returns the number of occurrences of a character in a string
static int numMatches(java.lang.String s, java.lang.String search)
          returns the number of occurrences of a substring in a string
static java.lang.String prettyPrint(java.util.Date date)
          formats a date using the default locale settings.
static java.lang.String prettyPrint(long num)
          formats a number using the default locale settings.
static java.lang.String prettyPrint(java.lang.Number num)
          formats a number using the default locale settings.
static java.lang.String replace(java.lang.String src, java.lang.String search, java.lang.String replace)
          returns a new string in which one search string is replaced by another.
static boolean startsWithAny(java.lang.String str, java.util.Collection<java.lang.String> prefixes)
          tests if a string starts with any one of a collection of prefixes
static boolean startsWithAny(java.lang.String str, java.lang.String[] prefixes)
          tests if a string starts with any one of a collection of prefixes
static java.lang.String strip(java.lang.String s, int numStart, int numEnd)
          removes a number of characters from the beginning and the end of a string
static java.lang.String substring(java.lang.String str, int beginIndex)
          same as String.substring, except that this version handles the case robustly when the index is out of bounds.
static java.lang.String substring(java.lang.String str, int beginIndex, int endIndex)
          same as String.substring, except that this version handles the case robustly when one or both of the indexes is out of bounds.
static java.lang.String truncate(java.lang.String str, int maxLen)
          truncates a string regardless of its length.
static java.lang.String unescape(java.lang.String src)
          undoes the operations of escape
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringHelper

public StringHelper()
Method Detail

getTypeAsString

public static java.lang.String getTypeAsString(java.lang.Object o)

getTypesAsString

public static java.util.List<java.lang.String> getTypesAsString(java.util.List<?> l)

prettyPrint

public static java.lang.String prettyPrint(long num)
formats a number using the default locale settings.


prettyPrint

public static java.lang.String prettyPrint(java.lang.Number num)
formats a number using the default locale settings.


prettyPrint

public static java.lang.String prettyPrint(java.util.Date date)
formats a date using the default locale settings.


replace

public static java.lang.String replace(java.lang.String src,
                                       java.lang.String search,
                                       java.lang.String replace)
returns a new string in which one search string is replaced by another.


escape

public static java.lang.String escape(java.lang.String src)
replaces special characters that affect formatting with non-formatting character sequences.


unescape

public static java.lang.String unescape(java.lang.String src)
undoes the operations of escape


truncate

public static java.lang.String truncate(java.lang.String str,
                                        int maxLen)
truncates a string regardless of its length. This method is a workaround for a shortcoming of String.substring (int, int) that is unable to handle the case where the number of characters would extend beyond the end of the string.


substring

public static java.lang.String substring(java.lang.String str,
                                         int beginIndex)
same as String.substring, except that this version handles the case robustly when the index is out of bounds.


substring

public static java.lang.String substring(java.lang.String str,
                                         int beginIndex,
                                         int endIndex)
same as String.substring, except that this version handles the case robustly when one or both of the indexes is out of bounds.


strip

public static java.lang.String strip(java.lang.String s,
                                     int numStart,
                                     int numEnd)
removes a number of characters from the beginning and the end of a string


numMatches

public static int numMatches(java.lang.String s,
                             char ch)
returns the number of occurrences of a character in a string


numMatches

public static int numMatches(java.lang.String s,
                             java.lang.String search)
returns the number of occurrences of a substring in a string


startsWithAny

public static boolean startsWithAny(java.lang.String str,
                                    java.util.Collection<java.lang.String> prefixes)
tests if a string starts with any one of a collection of prefixes


startsWithAny

public static boolean startsWithAny(java.lang.String str,
                                    java.lang.String[] prefixes)
tests if a string starts with any one of a collection of prefixes


endsWithAny

public static boolean endsWithAny(java.lang.String str,
                                  java.util.Collection<java.lang.String> prefixes)
tests if a string ends with any one of a collection of prefixes


endsWithAny

public static boolean endsWithAny(java.lang.String str,
                                  java.lang.String[] prefixes)
tests if a string ends with any one of a collection of prefixes


firstUpper

public static java.lang.String firstUpper(java.lang.String str)

firstLower

public static java.lang.String firstLower(java.lang.String str)