ProtoUtil { public static StringBuilder toCamelCase(String name) { StringBuilder buffer = new StringBuilder(); int toUpper = 0; char c; for (int i = 0, len = name.length(); i < len;) { c = name.charAt(i++); if (c == '_') { if (i == len) break; if (buffer.length() != 0) toUpper++; continue; } else if (toUpper != 0) { if (c > 96 && c < 123) { buffer.append((char) (c - 32)); toUpper = 0; } else if (c > 64 && c < 91) { buffer.append(c); toUpper = 0; } else { while (toUpper > 0) { buffer.append('_'); toUpper--; } buffer.append(c); } } else { if (buffer.length() == 0 && c > 64 && c < 91) buffer.append((char) (c + 32)); else buffer.append(c); } } return buffer; } private  ProtoUtil(); static void loadFrom(ANTLRReaderStream input, Proto target); static void loadFrom(InputStream in, Proto target); static void loadFrom(Reader reader, Proto target); static Proto parseProto(File file); static void loadFrom(File file, Proto target); static void loadFrom(URL resource, Proto target); static StringBuilder toCamelCase(String name); static StringBuilder toPascalCase(String name); static StringBuilder toUnderscoreCase(String name);  }
@Test public void testToCamelCase() throws Exception { assertEquals("fooBarBaz", toCamelCase("foo_bar_baz").toString()); assertEquals("fooBarBaz", toCamelCase("fooBarBaz").toString()); assertEquals("fooBarBaz", toCamelCase("FooBarBaz").toString()); assertEquals("fooBarBaz", toCamelCase("foo_bar_baz").toString()); assertEquals("fooBarBaz", toCamelCase("____Foo____Bar___Baz____").toString()); }