litesoft
@ 941
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.core.util; /** * Takes a 'CamelCased' string and produces a space separated string. */ public class DeCamelizer { public static String resolve( String pID ) { if ( pID != null ) { // remove all leading and trailing spaces and convert multiple spaces to one. (treat '_' as a space) int zSpaces = -pID.length(); StringBuilder sb = new StringBuilder( pID.length() ); for ( int at = 0; at < pID.length(); at++ ) { char c = pID.charAt( at ); if ( (c == '_') || (c == ' ') ) { zSpaces++; } else { if ( zSpaces > 0 ) { sb.append( ' ' ); } sb.append( c ); zSpaces = 0; } } if ( sb.length() != 0 ) { boolean zUpperNext = true; boolean zLastUpper = false; for ( int at = 0; at < sb.length(); at++ ) { char c = sb.charAt( at ); if ( zUpperNext ) { sb.setCharAt( at, Character.toUpperCase( c ) ); zLastUpper = true; zUpperNext = false; } else if ( Character.isUpperCase( c ) ) { if ( !zLastUpper ) { sb.insert( at++, ' ' ); } zLastUpper = true; } else { if ( c == ' ' ) { zUpperNext = true; } zLastUpper = false; } } return sb.toString(); } } return null; } } |