blob: d44c4171e6db100b7f8372b9f454ac86ec544463 (
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.
* @param 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)).filter(c => c.isLetterOrDigit || c == '_')
validChars.headOption match {
case Some(c) if (!c.isLetter) => 'x' + validChars
case Some(c) => validChars
case None => "id"
}
}
}
|