diff --git a/src/source/Main.scala b/src/source/Main.scala index 8932bb7a4..6bb455710 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -196,18 +196,21 @@ object Main { .text("Way of specifying if file generation should be skipped (default: false)") note("\nIdentifier styles (ex: \"FooBar\", \"fooBar\", \"foo_bar\", \"FOO_BAR\", \"m_fooBar\")\n") - identStyle("ident-java-enum", c => { javaIdentStyle = javaIdentStyle.copy(enum = c) }) - identStyle("ident-java-field", c => { javaIdentStyle = javaIdentStyle.copy(field = c) }) - identStyle("ident-cpp-enum", c => { cppIdentStyle = cppIdentStyle.copy(enum = c) }) - identStyle("ident-cpp-field", c => { cppIdentStyle = cppIdentStyle.copy(field = c) }) - identStyle("ident-cpp-method", c => { cppIdentStyle = cppIdentStyle.copy(method = c) }) - identStyle("ident-cpp-type", c => { cppIdentStyle = cppIdentStyle.copy(ty = c) }) - identStyle("ident-cpp-enum-type", c => { cppTypeEnumIdentStyle = c }) - identStyle("ident-cpp-type-param", c => { cppIdentStyle = cppIdentStyle.copy(typeParam = c) }) - identStyle("ident-cpp-local", c => { cppIdentStyle = cppIdentStyle.copy(local = c) }) - identStyle("ident-cpp-file", c => { cppFileIdentStyle = c }) - identStyle("ident-jni-class", c => {jniClassIdentStyleOptional = Some(c)}) - identStyle("ident-jni-file", c => {jniFileIdentStyleOptional = Some(c)}) + identStyle("ident-java-const", c => { javaIdentStyle = javaIdentStyle.copy(const = c) }) + identStyle("ident-java-enum", c => { javaIdentStyle = javaIdentStyle.copy(enum = c) }) + identStyle("ident-java-field", c => { javaIdentStyle = javaIdentStyle.copy(field = c) }) + identStyle("ident-cpp-const", c => { cppIdentStyle = cppIdentStyle.copy(const = c) }) + identStyle("ident-cpp-enum", c => { cppIdentStyle = cppIdentStyle.copy(enum = c) }) + identStyle("ident-cpp-field", c => { cppIdentStyle = cppIdentStyle.copy(field = c) }) + identStyle("ident-cpp-method", c => { cppIdentStyle = cppIdentStyle.copy(method = c) }) + identStyle("ident-cpp-type", c => { cppIdentStyle = cppIdentStyle.copy(ty = c) }) + identStyle("ident-cpp-enum-type", c => { cppTypeEnumIdentStyle = c }) + identStyle("ident-cpp-type-param", c => { cppIdentStyle = cppIdentStyle.copy(typeParam = c) }) + identStyle("ident-cpp-local", c => { cppIdentStyle = cppIdentStyle.copy(local = c) }) + identStyle("ident-cpp-file", c => { cppFileIdentStyle = c }) + identStyle("ident-jni-class", c => { jniClassIdentStyleOptional = Some(c) }) + identStyle("ident-jni-file", c => { jniFileIdentStyleOptional = Some(c) }) + identStyle("ident-objc-const", c => { objcIdentStyle = objcIdentStyle.copy(const = c) }) identStyle("ident-objc-enum", c => { objcIdentStyle = objcIdentStyle.copy(enum = c) }) identStyle("ident-objc-field", c => { objcIdentStyle = objcIdentStyle.copy(field = c) }) identStyle("ident-objc-method", c => { objcIdentStyle = objcIdentStyle.copy(method = c) }) diff --git a/src/source/generator.scala b/src/source/generator.scala index b14564076..c48cb393a 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -85,7 +85,8 @@ package object generatorTools { } def q(s: String) = '"' + s + '"' def firstUpper(token: String) = if (token.isEmpty()) token else token.charAt(0).toUpper + token.substring(1) - + def toUpperCase(token: String) = token.toUpperCase + type IdentConverter = String => String case class CppIdentStyle(ty: IdentConverter, enumType: IdentConverter, typeParam: IdentConverter, @@ -108,7 +109,11 @@ package object generatorTools { } val underLower = (s: String) => s val underUpper = (s: String) => s.split('_').map(firstUpper).mkString("_") - val underCaps = (s: String) => s.toUpperCase + val underCaps = (s: String) => { + // Splits the string either by underscores or Camel case. Underscores have precendence. + val splitArr = if (s.contains("_")) s.split('_') else s.split("(?<=.)(?=\\p{Lu})") + splitArr.map(toUpperCase).mkString("_") + } val prefix = (prefix: String, suffix: IdentConverter) => (s: String) => prefix + suffix(s) val javaDefault = JavaIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, underCaps, underCaps)