class BundleNormalizer {

  public static String toFieldName(String s) {
    Require.nonNull(s, "parameter s may not be null or empty.");
    Require.nonWhitespace(s, "parameter s may not be null or empty.");

    s= normalize(s);

    final char[] chars= s.toCharArray();
    final StringBuilder sb= new StringBuilder();

    //if the first char is a number, prepend it by an underscore
    if (Character.isDigit(chars[0])) {
      sb.append("_");
    }

    //always lowercase the first char
    sb.append(Character.toLowerCase(chars[0]));

    for (int i=1; i<chars.length; i++) {
      if (chars[i] == '_') {
        // if char is underscore, leave it out…
        if (chars.length > i+1) {
          // … and uppercase next letter, if available
          final char nextChar= chars[i+1];
          sb.append(Character.toUpperCase(nextChar));
          i++;
        }
      } else {
        // leave all other chars as the are
        sb.append(chars[i]);
      }
    }

    return sb.toString();
  }

}