Methods Summary |
---|
public java.lang.String | escape(java.lang.String s)
final StringBuffer buf = new StringBuffer();
final int length = s.length();
for( int i = 0; i < length; ++i )
{
final char c = s.charAt( i );
if ( shouldEscape( c ) )
{
buf.append( getEscapeSequence( c ) );
}
else
{
buf.append( c );
}
}
return( buf.toString() );
|
char | escapeSequenceToChar()
final char c = nextChar();
char result = 0;
if ( c == mEscapeChar )
{
result = mEscapeChar;
}
else if ( c == 'n" )
{
result = NEWLINE;
}
else if ( c == 'r" )
{
result = RETURN;
}
else if ( c == 't" )
{
result = TAB;
}
else if ( c == 's" )
{
result = SPACE;
}
else if ( c == UNICODE_START )
{
final String unicodeSequence = "" + nextChar() + nextChar() + nextChar() + nextChar();
final int intValue = Integer.parseInt( unicodeSequence, 16 );
result = (char)intValue;
}
else
{
throw new IllegalArgumentException( "Illegal escape sequence" );
}
return( result );
|
java.lang.String | getEscapeSequence(char c)
String sequence = null;
if ( c == mEscapeChar )
{
sequence = "" + mEscapeChar + mEscapeChar;
}
else if ( c == NEWLINE )
{
sequence = mEscapeChar + "n";
}
else if ( c == RETURN )
{
sequence = mEscapeChar + "r";
}
else if ( c == TAB )
{
sequence = mEscapeChar + "t";
}
else if ( c == SPACE )
{
sequence = mEscapeChar + "s";
}
else
{
final int numericValue = (int)c;
String valueString = "" + Integer.toHexString( numericValue );
// make sure it's 4 digits by prepending leading zeroes
while ( valueString.length() != 4 )
{
valueString = "0" + valueString;
}
// careful not to append char to char
sequence = mEscapeChar + (UNICODE_START + valueString);
}
return( sequence );
|
boolean | hasMoreChars()
return( mCharIter.current() != mCharIter.DONE );
|
char | nextChar()
final char theChar = mCharIter.current();
mCharIter.next();
if ( theChar == mCharIter.DONE )
{
throw new ArrayIndexOutOfBoundsException();
}
return( theChar );
|
char | peekNextChar()
return( mCharIter.current() );
|
boolean | shouldEscape(char c)
boolean shouldEscape = false;
for( int i = 0; i < mCharsToEscape.length; ++i )
{
if ( c == mCharsToEscape[ i ] )
{
shouldEscape = true;
break;
}
}
return( shouldEscape );
|
public java.lang.String | unescape(java.lang.String s)
final StringBuffer buf = new StringBuffer();
mCharIter = new StringCharacterIterator( s );
while ( hasMoreChars() )
{
final char c = (char)nextChar();
assert ( c != mCharIter.DONE );
if ( c == mEscapeChar )
{
final char newChar = escapeSequenceToChar();
buf.append( newChar );
}
else
{
buf.append( c );
}
}
mCharIter = null;
return( buf.toString() );
|