aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/util/NameTransformer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-05-24 16:37:47 +0200
committerMartin Odersky <odersky@gmail.com>2013-05-24 16:39:06 +0200
commitacc2b198692687394c9f8f84b16a0bec9ae12ee3 (patch)
treef9a9d588a629315aa82ddcee8c285d7614ed3201 /src/dotty/tools/dotc/util/NameTransformer.scala
parente1be722f469c45e7546388359b5870a07f4c14b8 (diff)
downloaddotty-acc2b198692687394c9f8f84b16a0bec9ae12ee3.tar.gz
dotty-acc2b198692687394c9f8f84b16a0bec9ae12ee3.tar.bz2
dotty-acc2b198692687394c9f8f84b16a0bec9ae12ee3.zip
NameTransformer.encode now goes from names to names.
Also, special treatment of <init>, which is not encoded.
Diffstat (limited to 'src/dotty/tools/dotc/util/NameTransformer.scala')
-rw-r--r--src/dotty/tools/dotc/util/NameTransformer.scala15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/util/NameTransformer.scala b/src/dotty/tools/dotc/util/NameTransformer.scala
index 287c7660c..be77dd9a6 100644
--- a/src/dotty/tools/dotc/util/NameTransformer.scala
+++ b/src/dotty/tools/dotc/util/NameTransformer.scala
@@ -9,6 +9,9 @@
package dotty.tools.dotc
package util
+import core.Names._
+import core.Decorators._
+
/** Provides functions to encode and decode Scala symbolic names.
* Also provides some constants.
*/
@@ -57,16 +60,16 @@ object NameTransformer {
* @param name the string to encode
* @return the string with all recognized opchars replaced with their encoding
*/
- def encode(name: String): String = {
+ def encode(name: Name): TermName = {
var buf: StringBuilder = null
- val len = name.length()
+ val len = name.length
var i = 0
while (i < len) {
- val c = name charAt i
+ val c = name(i)
if (c < nops && (op2code(c) ne null)) {
if (buf eq null) {
buf = new StringBuilder()
- buf.append(name.substring(0, i))
+ buf.append(name.slice(0, i))
}
buf.append(op2code(c))
/* Handle glyphs that are not valid Java/JVM identifiers */
@@ -74,7 +77,7 @@ object NameTransformer {
else if (!Character.isJavaIdentifierPart(c)) {
if (buf eq null) {
buf = new StringBuilder()
- buf.append(name.substring(0, i))
+ buf.append(name.slice(0, i))
}
buf.append("$u%04X".format(c.toInt))
}
@@ -83,7 +86,7 @@ object NameTransformer {
}
i += 1
}
- if (buf eq null) name else buf.toString()
+ if (buf eq null) name.toTermName else buf.toString.toTermName
}
/** Replace `\$opname` by corresponding operator symbol.