org.eclipse.internal.xtend.util
Class StringHelper

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

public class StringHelper
extends java.lang.Object

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

Author:
Arno Haase

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 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 java.util.List<java.lang.String> split(java.lang.String value, java.lang.String delimiter)
          Splits a string around matches of the given delimiter character.
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(int, int), 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

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(int, int), 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)

split

public static java.util.List<java.lang.String> split(java.lang.String value,
                                                     java.lang.String delimiter)
Splits a string around matches of the given delimiter character.

This method works similar to String.split(String) but does not treat the delimiter as a regular expression. This makes it perform better in most cases where this feature is not necessary. Furthermore this implies that trailing empty segments will not be part of the result.

Copied from org.eclipse.xtext.util.Strings

Parameters:
value - the string to split
delimiter - the delimiting String (e.g. '.' or ':' or '::')
Returns:
the list of strings computed by splitting the string around matches of the given delimiter without trailing empty segments. Never null and the list does not contain any null values.
Throws:
java.lang.NullPointerException - If the value is null
Since:
1.4
See Also:
String.split(String)