public static String unescapeTokenString(String token, char escapechar, boolean upcaseP) {
    { int nofescapes = 0;
      int cursor = 0;
      int cursor2 = 0;
      int size = token.length();
      StringBuffer result = null;
      boolean escapeP = false;

      while (cursor < size) {
        if (token.charAt(cursor) == escapechar) {
          nofescapes = nofescapes + 1;
          cursor = cursor + 1;
        }
        cursor = cursor + 1;
      }
      if (nofescapes == 0) {
        return (token);
      }
      result = Stella.makeRawMutableString(size - nofescapes);
      cursor = 0;
      while (cursor < size) {
        if ((token.charAt(cursor) == escapechar) &&
            (!escapeP)) {
          escapeP = true;
        }
        else if (upcaseP &&
            (!escapeP)) {
          edu.isi.stella.javalib.Native.mutableString_nthSetter(result, (Stella.$CHARACTER_UPCASE_TABLE$.charAt(((int) (token.charAt(cursor))))), cursor2);
          cursor2 = cursor2 + 1;
        }
        else {
          edu.isi.stella.javalib.Native.mutableString_nthSetter(result, (token.charAt(cursor)), cursor2);
          escapeP = false;
          cursor2 = cursor2 + 1;
        }
        cursor = cursor + 1;
      }
      return (result.toString());
    }
  }