|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.sap.i18n.text.Utf16String
Wrapper class for JDK class String
Purpose: handle surrogate pairs and combining characters
Offers alternatives for searching, accessing substrings
and accessing characters.
The main rules are:
Constructor Summary | |
Utf16String()
|
Method Summary | |
static int |
charAt(java.lang.String str,
int index)
Alternative to String.charAt to handle surrogate pairs properly. |
static int |
codeunitAt(java.lang.String str,
int index)
Alternative to String.charAt. |
static java.lang.String |
combinedCharAt(java.lang.String str,
int index)
Alternative to String.charAt to handle surrogate pairs and combined characters. |
static int |
countCodeUnits(int ch)
Determine number of code units (16-bit) of char ch (1 or 2). |
static int |
indexOf(java.lang.String str,
int ch)
Alternative to String.indexOf to handle combining characters properly. |
static int |
indexOf(java.lang.String str,
java.lang.String substr)
Alternative to String.indexOf that handles combining characters properly. |
static boolean |
isCombiningChar(int ch)
Check if character combines with previous character. |
static boolean |
isCombiningCharAt(java.lang.String str,
int index)
Check if character at str[index] combines with previous character. |
static int |
lastIndexOf(java.lang.String str,
int ch)
Alternative to String.lastIndexOf that handles combining characters properly. |
static int |
lastIndexOf(java.lang.String str,
java.lang.String substr)
Alternative to String.lastIndexOf that handles combining characters properly. |
static java.lang.String |
limitLength(java.lang.String str,
int limit)
Alternative to String.substring that avoids cutting surrogate pairs and combining characters. |
static java.lang.String |
removePostfix(java.lang.String str,
java.lang.String postfix)
Alternative to String.substring that avoids cutting surrogate pairs and combining characters. |
static java.lang.String |
removePrefix(java.lang.String str,
java.lang.String prefix)
Alternative to String.substring that avoids cutting of surrogate pairs and combining characters. |
static char |
simplifiedCharAt(java.lang.String str,
int index)
Alternative to String.charAt. |
static java.lang.String |
substringAfter(java.lang.String str,
char delim)
Alternative to String.substring that avoids cutting surrogate pairs and combining characters. |
static java.lang.String |
substringAfter(java.lang.String str,
java.lang.String delimstr)
Alternative to String.substring that avoids cutting surrogate pairs and combining characters. |
static java.lang.String |
substringBefore(java.lang.String str,
char delim)
Alternative to String.substring that avoids cutting surrogate pairs and combining characters. |
static java.lang.String |
substringBefore(java.lang.String str,
java.lang.String delimstr)
Alternative to String.substring that avoids cutting surrogate pairs and combining characters. |
static java.lang.String |
substringFixedFormat(java.lang.String str,
int beginIndex,
int endIndex)
Alternative to String.substring. |
static java.lang.String |
toLowerFirstChar(java.lang.String str)
Converts the first character of str to lower case. |
static java.lang.String |
toUpperFirstChar(java.lang.String str)
Converts the first character of str to upper case. coding sample old: String getMethod = "get" + Character.toUpperCase( columnName.charAt(0) ) + columnName.substring(1); coding sample new: String getMethod = "get" + Utf16String.toUpperFirstChar( columnName ); |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Utf16String()
Method Detail |
public static int indexOf(java.lang.String str, int ch)
public static int indexOf(java.lang.String str, java.lang.String substr)
public static int lastIndexOf(java.lang.String str, int ch)
public static int lastIndexOf(java.lang.String str, java.lang.String substr)
public static boolean isCombiningCharAt(java.lang.String str, int index)
isCombiningChar(int)
public static boolean isCombiningChar(int ch)
isCombiningCharAt(java.lang.String, int)
public static java.lang.String removePrefix(java.lang.String str, java.lang.String prefix)
if ( name.startsWith("environment.") ) { env.setProperty( Name.substring("environment.".length() ), System.getProperty(name) ); }coding sample new:
String prop = Utf16String.removePrefix( name, "environment." ); if( prop != null ) { env.setProperty( prop, System.getProperty(name) ); }
public static java.lang.String removePostfix(java.lang.String str, java.lang.String postfix)
removePrefix(java.lang.String, java.lang.String)
public static java.lang.String substringBefore(java.lang.String str, char delim)
if ( text.indexOf('|') >= 0 ) { text1 = text.substring( 0, text.indexOf('|') ); text2 = text.substring( text.indexOf('|') + 1, text.length() ); } else { text1 = text; text2 = ""; }coding sample new:
text1 = Utf16String.substringBefore( text, '|' ); text2 = Utf16String.substringAfter( text, '|' ); if ( text1 == null ) { text1 = text; text2 = ""; }
public static java.lang.String substringBefore(java.lang.String str, java.lang.String delimstr)
substringBefore( java.lang.String, char )
public static java.lang.String substringAfter(java.lang.String str, char delim)
substringBefore( java.lang.String, char )
public static java.lang.String substringAfter(java.lang.String str, java.lang.String delimstr)
substringBefore( java.lang.String, char )
public static java.lang.String limitLength(java.lang.String str, int limit)
if ( s.length() > maxLength ) { s = s.substring( 0, maxLength ); }coding sample new:
s = limitLength( s, maxLength );
public static java.lang.String substringFixedFormat(java.lang.String str, int beginIndex, int endIndex)
char ch = str.charAt(i); if ( ch < 0x20 || ch > 0x7e ) { String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + s.substring( s.length() - 4, s.length() ) ); }coding sample new:
char ch = str.charAt(i); if ( ch < 0x20 || ch > 0x7e ) { String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + Utf16String.substringFixedFormat( s, s.length() - 4, s.length() ) ); }
public static java.lang.String toUpperFirstChar(java.lang.String str)
String getMethod = "get" + Character.toUpperCase( columnName.charAt(0) ) + columnName.substring(1);coding sample new:
String getMethod = "get" + Utf16String.toUpperFirstChar( columnName );
public static java.lang.String toLowerFirstChar(java.lang.String str)
toLowerFirstChar(java.lang.String)
public static int charAt(java.lang.String str, int index)
for (int i = 0; i < s.length(); ++i ) { char ch = s.charAt( i ); doSomethingWith( ch ); }coding sample new:
int ch; for (int i = 0; i < s.length(); i+=Utf16String.countCodeUnits(ch) ) { ch = Utf16String.charAt( s, i ); doSomethingWith( ch ); }
public static int countCodeUnits(int ch)
charAt(java.lang.String, int)
public static java.lang.String combinedCharAt(java.lang.String str, int index)
public static char simplifiedCharAt(java.lang.String str, int index)
for( int i=0; i < arg.length ; i++ ) { if( Utf16String.simplifiedCharAt(arg[i],0) == '-' ) { if( arg[i].length() < 2 ) continue; // known options switch( Utf16String.simplifiedCharAt( arg[i], 1 ) ) { case 'u': // user user = Utf16String.removePrefix( arg[i], "-u" ); break; case 'd': // duration try { duration = Long.parseLong( Utf16String.removePrefix( arg[i], "-d" ) ); } catch( NumberFormatException e ) { System.err.println( "Wrong duration specified: " + arg[i] ); } break; default: System.err.println( "Unknown option: " + arg[i] ); break; } // not an option } else { otherArgs.add( arg[i] ); } } // for i < arg.lengthcoding sample new:
for( int i=0; i < arg.length ; i++ ) { if( Utf16String.simplifiedCharAt(arg[i],0) == '-' ) { if( arg[i].length() < 2 ) continue; // known options switch( Utf16String.simplifiedCharAt( arg[i], 1 ) ) { case 'u': // user user = Utf16String.removePrefix( arg[i], "-u" ); break; case 'd': // duration try { duration = Long.parseLong( Utf16String.removePrefix( arg[i], "-d" ) ); } catch( NumberFormatException e ) { System.err.println( "Wrong duration specified: " + arg[i] ); } break; default: System.err.println( "Unknown option: " + arg[i] ); break; } // not an option } else { otherArgs.add( arg[i] ); } } // for i < arg.length
public static int codeunitAt(java.lang.String str, int index)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |