aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Names.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-02-15 16:04:29 +0100
committerMartin Odersky <odersky@gmail.com>2013-02-15 16:04:36 +0100
commit75fbef7e1c6ecf2d79dd36a62863875fc89127f2 (patch)
tree24ff30626a4b368e50e6f498e72773b64b757093 /src/dotty/tools/dotc/core/Names.scala
parent2cb396197f65842499e6dd759c87dbaecb658a48 (diff)
downloaddotty-75fbef7e1c6ecf2d79dd36a62863875fc89127f2.tar.gz
dotty-75fbef7e1c6ecf2d79dd36a62863875fc89127f2.tar.bz2
dotty-75fbef7e1c6ecf2d79dd36a62863875fc89127f2.zip
PreNames as a way to unify Names and Strings.
Diffstat (limited to 'src/dotty/tools/dotc/core/Names.scala')
-rw-r--r--src/dotty/tools/dotc/core/Names.scala16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/core/Names.scala b/src/dotty/tools/dotc/core/Names.scala
index abf902a1c..8a13964e3 100644
--- a/src/dotty/tools/dotc/core/Names.scala
+++ b/src/dotty/tools/dotc/core/Names.scala
@@ -13,6 +13,11 @@ import collection.generic.CanBuildFrom
object Names {
+ trait PreName extends Any {
+ def toTypeName: TypeName
+ def toTermName: TermName
+ }
+
/** A name is essentially a string, with three differences
* 1. Names belong in one of two universes: they are type names or term names.
* The same string can correspond both to a type name and to a term name.
@@ -22,6 +27,7 @@ object Names {
* The encoding will be applied when converting a string to a name.
*/
abstract class Name extends DotClass
+ with PreName
with Seq[Char]
with IndexedSeqOptimized[Char, Name] {
@@ -82,6 +88,16 @@ object Names {
fromChars(s.toCharArray, 0, s.length)
}
+ def replace(from: Char, to: Char): ThisName = {
+ val cs = new Array[Char](length)
+ Array.copy(chrs, start, cs, 0, length)
+ for (i <- 0 until length) {
+ val c = cs(i)
+ chrs(i) = if (c == from) to else c
+ }
+ fromChars(cs, 0, length)
+ }
+
// ----- Collections integration -------------------------------------
override protected[this] def thisCollection: WrappedString = new WrappedString(repr.toString)