@@ -3212,28 +3212,20 @@ protected void addParentContainer(CodegenModel m, String name, Property property
32123212
32133213 /**
32143214 * Underscore the given word.
3215- * Copied from Twitter elephant bird
3216- * https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/util/Strings.java
32173215 *
32183216 * @param word The word
32193217 * @return The underscored version of the word
32203218 */
32213219 public static String underscore (String word ) {
3222- String firstPattern = "( [A-Z]+)( [A-Z][a-z][a-z]+)" ;
3223- String secondPattern = "( [a-z\\ d])([A-Z])" ;
3220+ Pattern firstPattern = Pattern . compile ( "(?<= [A-Z])(?= [A-Z][a-z]{2,})" ) ;
3221+ Pattern secondPattern = Pattern . compile ( "(?<= [a-z\\ d])(?= [A-Z])") ;
32243222 String replacementPattern = "$1_$2" ;
3225- // Replace package separator with slash.
3226- word = word .replaceAll ("\\ ." , "/" ); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
3227- // Replace $ with two underscores for inner classes.
3228- word = word .replaceAll ("\\ $" , "__" );
3229- // Replace capital letter with _ plus lowercase letter.
3230- word = word .replaceAll (firstPattern , replacementPattern );
3231- word = word .replaceAll (secondPattern , replacementPattern );
3232- word = word .replace ('-' , '_' );
3233- // replace space with underscore
3234- word = word .replace (' ' , '_' );
3235- word = word .toLowerCase ();
3236- return word ;
3223+
3224+ String replaced = word .replace ('.' , '/' ).replace ("$" , "__" );
3225+ replaced = firstPattern .matcher (replaced ).replaceAll ("_" );
3226+ replaced = secondPattern .matcher (replaced ).replaceAll ("_" );
3227+ replaced = replaced .replace ('-' , '_' ).replace (' ' , '_' ).toLowerCase ();
3228+ return replaced ;
32373229 }
32383230
32393231 /**
0 commit comments