Example #1
0
  /**
   * Format a prefixed name as camelCase. The prefix is kept verbatim, while tha name is split on
   * '_' chars, and joined with each part capitalized.
   *
   * @param name The name to camel-case.
   * @return theCamelCasedName
   */
  public static String camelCase(String name) {
    StringBuilder builder = new StringBuilder();

    String[] parts = name.split("[-._]");
    boolean first = true;
    int skipped = 0;
    for (String part : parts) {
      if (part.isEmpty()) {
        skipped++;
        continue;
      }
      if (first) {
        first = false;
        builder.append(part);
      } else if (skipped > 1) {
        builder.append('_');
        builder.append(part);
      } else {
        builder.append(Strings.capitalize(part));
      }
      skipped = 0;
    }

    return builder.toString();
  }
Example #2
0
 public static String getPackageClassPath(String javaPackage) throws GeneratorException {
   String[] parts = javaPackage.split("[.]");
   return Strings.join(File.separator, parts);
 }
Example #3
0
 public static String enumConst(PEnumValue value) {
   return Strings.c_case("", value.getName()).toUpperCase();
 }