diff options
author | Vlad Uspensky <v.uspenskiy@icloud.com> | 2017-08-28 09:57:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-28 09:57:06 -0700 |
commit | f7621e318de56865b44a6a07ea45e37bbb3f80c1 (patch) | |
tree | ca6d966182e21d072895f7c32bea2fbc35bc2c23 /src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala | |
parent | 4512539b01e6e598d494246426b9eac261d10acf (diff) | |
parent | b249515292bfefbb70d1b5743ca46ced6da22a00 (diff) | |
download | rest-query-f7621e318de56865b44a6a07ea45e37bbb3f80c1.tar.gz rest-query-f7621e318de56865b44a6a07ea45e37bbb3f80c1.tar.bz2 rest-query-f7621e318de56865b44a6a07ea45e37bbb3f80c1.zip |
Merge pull request #21 from drivergroup/queryparsers
Added converting camel case to snake case for filters and sorting AST
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala index 02c9e28..63b0572 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala @@ -1,6 +1,7 @@ package xyz.driver.pdsuicommon.utils import java.time.LocalDateTime +import java.util.regex.{Matcher, Pattern} object Utils { @@ -20,4 +21,23 @@ object Utils { fullClassName.substring(fullClassName.lastIndexOf("$") + 1) } } + + def toSnakeCase(str: String): String = + str + .replaceAll("([A-Z]+)([A-Z][a-z])", "$1_$2") + .replaceAll("([a-z\\d])([A-Z])", "$1_$2") + .toLowerCase + + def toCamelCase(str: String): String = { + val sb = new StringBuffer() + def loop(m: Matcher): Unit = if (m.find()) { + m.appendReplacement(sb, m.group(1).toUpperCase()) + loop(m) + } + val m: Matcher = Pattern.compile("_(.)").matcher(str) + loop(m) + m.appendTail(sb) + sb.toString + } + } |