public static String read_digits ( EvaluationContext ctx , Object text ) { String _text = Conversions . toString ( text , ctx ) . trim ( ) ; if ( StringUtils . isEmpty ( _text ) ) { return "" ; } // trim off the plus for phone numbers if ( _text . startsWith ( "+" ) ) { _text = _text . substring ( 1 ) ; } if ( _text . length ( ) == 9 ) { // SSN return StringUtils . join ( _text . substring ( 0 , 3 ) . toCharArray ( ) , ' ' ) + " , " + StringUtils . join ( _text . substring ( 3 , 5 ) . toCharArray ( ) , ' ' ) + " , " + StringUtils . join ( _text . substring ( 5 ) . toCharArray ( ) , ' ' ) ; } else if ( _text . length ( ) % 3 == 0 && _text . length ( ) > 3 ) { // triplets, most international phone numbers List < String > chunks = chunk ( _text , 3 ) ; return StringUtils . join ( StringUtils . join ( chunks , ' ' ) . toCharArray ( ) , ' ' ) ; } else if ( _text . length ( ) % 4 == 0 ) { // quads, credit cards List < String > chunks = chunk ( _text , 4 ) ; return StringUtils . join ( StringUtils . join ( chunks , ' ' ) . toCharArray ( ) , ' ' ) ; } else { // otherwise, just put a comma between each number return StringUtils . join ( _text . toCharArray ( ) , ' ' ) ; } }
Formats digits in text for reading in TTS