diff options
author | paltherr <paltherr@epfl.ch> | 2004-02-27 22:56:35 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2004-02-27 22:56:35 +0000 |
commit | 01599fa37b24e623d1bc6836a8f65548bd5fdcea (patch) | |
tree | 295dcb780d72eb2fb7db075be8ca84014573cc9b /sources/scalac/util | |
parent | 0b75ded56f99a77dc19892fe8c3ceda16e72148e (diff) | |
download | scala-01599fa37b24e623d1bc6836a8f65548bd5fdcea.tar.gz scala-01599fa37b24e623d1bc6836a8f65548bd5fdcea.tar.bz2 scala-01599fa37b24e623d1bc6836a8f65548bd5fdcea.zip |
- Changed return type of NameTransformer.decode...
- Changed return type of NameTransformer.decode to String (was Name)
Diffstat (limited to 'sources/scalac/util')
-rw-r--r-- | sources/scalac/util/NameTransformer.java | 79 |
1 files changed, 30 insertions, 49 deletions
diff --git a/sources/scalac/util/NameTransformer.java b/sources/scalac/util/NameTransformer.java index 1a7218c8f3..a347a6bf81 100644 --- a/sources/scalac/util/NameTransformer.java +++ b/sources/scalac/util/NameTransformer.java @@ -56,57 +56,38 @@ public class NameTransformer { /** Replace "$op_name" by corresponding operator symbols in names. */ - public static Name decode(Name name) { - int i = name.index; - int length = i + name.length(); - StringBuffer res = new StringBuffer(); - while (i < length) { - byte c = Name.names[i++]; - if ((char)c == '$') { - String op = cutOut(i, length); - res.append(decode("$" + op)); - i = i + op.length(); - } - else res.append((char)c); - } - return Name.fromString(res.toString()); + public static String decode(Name name) { + return decode(name.toString()); } - - /** Decodes (a prefix of) a string. - */ public static String decode(String string) { - for (int i = string.length(); i > 0; i--) { - String prefix = string.substring(0, i); - String c = lookup(prefix); - if (c != null) { - String suffix = string.substring(i, string.length()); - return c + suffix; - } - } - return string; - } - - /** Cuts out the name of an operator plus succeeding characters. - * Does NOT return the preceeding '$' symbol. - */ - private static String cutOut(int pos, int length) { - int i = pos; // avoid side-effects - StringBuffer res = new StringBuffer(); - while (i < length) { - char c = (char)Name.names[i++]; - if (c == '$') return res.toString(); - else res.append(c); - } - return res.toString(); + StringBuffer buffer = null; + for (int i = 0; i < string.length(); i++) { + char c = string.charAt(i); + if (c == '$') { + int index = -1; + int length = -1; // an operator may be a prefix of another one + for (int j = 0; j < operatorName.length; j++) { + String operator = operatorName[j]; + if (operator == null) continue; + if (operator.length() <= length) continue; + if (!string.startsWith(operator, i)) continue; + index = j; + length = operator.length(); + } + if (length >= 0) { + if (buffer == null) { + int capacity = string.length() - length + 1; + buffer = new StringBuffer(capacity); + buffer.append(string.substring(0, i)); + } + buffer.append((char)index); + i += length - 1; + continue; + } + } + if (buffer != null) buffer.append(c); + } + return buffer == null ? string : buffer.toString(); } - /** Looks up the array entry for the operator name. - */ - private static String lookup(String string) { - for (int i = 0; i < 128; i++) { - if ((operatorName[i] != null) && (string.compareTo(operatorName[i]) == 0)) - return String.valueOf((char)i); - } - return null; - } } |