aboutsummaryrefslogtreecommitdiff
path: root/mavlink-library/src/main/scala/com/github/jodersky/mavlink/StringUtils.scala
blob: 29f262f2dddbda4debeae5ab01b1e30f7ad70a97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.github.jodersky.mavlink

object StringUtils {

  private final val Keywords = Set(
  	"class",
  	"object",
  	"trait",
  	"extends",
  	"type",
  	"import",
  	"package",
  	"val",
  	"var",
  	"def",
  	"implicit",
  	"private",
  	"protected",
  	"abstract",
  	"override",
  	"class",
  	"case",
  	"match",
  	"final",
  	"this",
  	"super",
  	"throw",
  	"catch",
  	"finally",
  	"if",
  	"else",
  	"for",
  	"while",
  	"do"
  )

  private def escape(str: String) = if (Keywords.contains(str)) {
  	"`" + str + "`"
  } else {
  	str
  }

  def camelify(str: String) = {
  	val lower = str.toLowerCase
  	escape("_([a-z\\d])".r.replaceAllIn(lower, {m => m.group(1).toUpperCase()}))
  }

  def Camelify(str: String) = {
  	val camel = camelify(str)
  	val (head, tail) = camel.splitAt(1)
  	escape(head.toUpperCase + tail)
  }

}