Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Adds an ident-<lang>-const command line option for each language. #271

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/source/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
Expand Down
9 changes: 7 additions & 2 deletions src/source/generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down