blob: 45dd96776ecca3535ce9b91164555a7f1f6f6cbb (
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
|
package scalam.m.ast
/**
* A matlab identifier.
* @name name of variable (this must be a valid matlab identifier string)
*
* @define construct identifier
*/
case class Identifier(name: String) extends Mable {
def m = name
}
object Identifier {
def makeValid(raw: String) = {
val transformSymbols = Map(' ' -> '_').withDefault(c => c)
val validChars = raw.map(c => transformSymbols(c))
validChars.headOption match {
case Some(c) if (!c.isLetter) => 'x' + validChars
case Some(c) => validChars
case None => "id"
}
}
}
|