Package java.lang

Examples of java.lang.StringBuilder$Cell


public static class RegexReader extends AFn{
  static StringReader stringrdr = new StringReader();

  public Object invoke(Object reader, Object doublequote) {
    StringBuilder sb = new StringBuilder();
    Reader r = (Reader) reader;
    for(int ch = read1(r); ch != '"'; ch = read1(r))
      {
      if(ch == -1)
        throw Util.runtimeException("EOF while reading regex");
      sb.append( (char) ch );
      if(ch == '\\'//escape
        {
        ch = read1(r);
        if(ch == -1)
          throw Util.runtimeException("EOF while reading regex");
        sb.append( (char) ch ) ;
        }
      }
    return Pattern.compile(sb.toString());
  }
View Full Code Here


  }
}

public static class StringReader extends AFn{
  public Object invoke(Object reader, Object doublequote) {
    StringBuilder sb = new StringBuilder();
    Reader r = (Reader) reader;

    for(int ch = read1(r); ch != '"'; ch = read1(r))
      {
      if(ch == -1)
        throw Util.runtimeException("EOF while reading string");
      if(ch == '\\'//escape
        {
        ch = read1(r);
        if(ch == -1)
          throw Util.runtimeException("EOF while reading string");
        switch(ch)
          {
          case 't':
            ch = '\t';
            break;
          case 'r':
            ch = '\r';
            break;
          case 'n':
            ch = '\n';
            break;
          case '\\':
            break;
          case '"':
            break;
          case 'b':
            ch = '\b';
            break;
          case 'f':
            ch = '\f';
            break;
          case 'u':
          {
          ch = read1(r);
          if (Character.digit(ch, 16) == -1)
            throw Util.runtimeException("Invalid unicode escape: \\u" + (char) ch);
          ch = readUnicodeChar((PushbackReader) r, ch, 16, 4, true);
          break;
          }
          default:
          {
          if(Character.isDigit(ch))
            {
            ch = readUnicodeChar((PushbackReader) r, ch, 8, 3, false);
            if(ch > 0377)
              throw Util.runtimeException("Octal escape sequence must be in range [0, 377].");
            }
          else
            throw Util.runtimeException("Unsupported escape character: \\" + (char) ch);
          }
          }
        }
      sb.append((char) ch);
      }
    return sb.toString();
  }
View Full Code Here

  private static String quoteString(String unquoted)
  {
    if (unquoted == null)
      return "null";
    StringBuilder b = new StringBuilder(unquoted.length() + 2);
    b.append('"');
    for (int i = 0; i < unquoted.length(); ++i) {
      char c = unquoted.charAt(i);
      if (c == '"' || c == '\\')
        b.append('\\');
      b.append(c);
    }
    b.append('"');
    return b.toString();
  }
View Full Code Here

      return null;
    if (quoted.length() == 0 || quoted.charAt(0) != '"')
      throw new ServalDInterfaceException("malformed header field: " + header + ": missing quote at start of quoted-string");
    boolean slosh = false;
    boolean end = false;
    StringBuilder b = new StringBuilder(quoted.length());
    for (int i = 1; i < quoted.length(); ++i) {
      char c = quoted.charAt(i);
      if (end)
        throw new ServalDInterfaceException("malformed header field: " + header + ": spurious character after quoted-string");
      if (c < ' ' || c > '~')
        throw new ServalDInterfaceException("malformed header field: " + header + ": invalid character in quoted-string");
      if (slosh) {
        b.append(c);
        slosh = false;
      }
      else if (c == '"')
        end = true;
      else if (c == '\\')
        slosh = true;
      else
        b.append(c);
    }
    if (!end)
      throw new ServalDInterfaceException("malformed header field: " + header + ": missing quote at end of quoted-string");
    return b.toString();
  }
View Full Code Here

      case 'n':
        this.reader.unread(c);
        readWord("null");
        return Token.NULL;
      case '"': {
          StringBuilder sb = new StringBuilder();
          boolean slosh = false;
          while (true) {
            c = _read();
            if (c == -1)
              throw new SyntaxException("unexpected EOF in JSON string");
            if (slosh) {
              switch (c) {
              case '"': case '/': case '\\': sb.append((char)c); break;
              case 'b': sb.append('\b'); break;
              case 'f': sb.append('\f'); break;
              case 'n': sb.append('\n'); break;
              case 'r': sb.append('\r'); break;
              case 't': sb.append('\t'); break;
              case 'u': sb.append((char)readHex(4)); break;
              default: throw new SyntaxException("malformed JSON string");
              }
              slosh = false;
            }
            else {
              switch (c) {
              case '"':
                return sb.toString();
              case '\\':
                slosh = true;
                break;
              default:
                sb.append((char)c);
                break;
              }
            }
          }
        }
      case '0':
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
      case '-': {
          StringBuilder sb = new StringBuilder();
          if (c == '-') {
            sb.append((char)c);
            c = _read();
          }
          if (c == '0') {
            sb.append((char)c);
            c = _read();
          }
          else if (Character.isDigit(c)) {
            do {
              sb.append((char)c);
              c = _read();
            }
              while (Character.isDigit(c));
          }
          else
            throw new SyntaxException("malformed JSON number");
          boolean isfloat = false;
          if (c == '.') {
            isfloat = true;
            sb.append((char)c);
            c = _read();
            if (c == -1)
              throw new SyntaxException("unexpected EOF in JSON number");
            if (!Character.isDigit(c))
              throw new SyntaxException("malformed JSON number");
            do {
              sb.append((char)c);
              c = _read();
            }
              while (Character.isDigit(c));
          }
          if (c == 'e' || c == 'E') {
            isfloat = true;
            sb.append((char)c);
            c = _read();
            if (c == '+' || c == '-') {
              sb.append((char)c);
              c = _read();
            }
            if (c == -1)
              throw new SyntaxException("unexpected EOF in JSON number");
            if (!Character.isDigit(c))
              throw new SyntaxException("malformed JSON number");
            do {
              sb.append((char)c);
              c = _read();
            }
              while (Character.isDigit(c));
          }
          this.reader.unread(c);
          String number = sb.toString();
          try {
            if (isfloat)
              return Double.parseDouble(number);
            else {
              try {
View Full Code Here

    '='
  };

  public static String encode(byte[] binary)
  {
    StringBuilder sb = new StringBuilder();
    int place = 0;
    byte buf = 0;
    for (byte b: binary) {
      switch (place) {
      case 0:
        sb.append(SYMBOLS[b >>> 2]);
        buf = (byte)((b << 4) & 0x3f);
        place = 1;
        break;
      case 1:
        sb.append(SYMBOLS[(b >>> 4) | buf]);
        buf = (byte)((b << 2) & 0x3f);
        place = 2;
        break;
      case 2:
        sb.append(SYMBOLS[(b >>> 6) | buf]);
        sb.append(SYMBOLS[b & 0x3f]);
        place = 0;
        break;
      }
    }
    if (place != 0)
      sb.append(SYMBOLS[buf]);
    switch (place) {
    case 1:
      sb.append(SYMBOLS[64]);
    case 2:
      sb.append(SYMBOLS[64]);
    }
    return sb.toString();
  }
View Full Code Here

        this.totalSplits = totalSplits;
    }

    @Override
    public String toString() {
        StringBuilder st = new StringBuilder();
        st.append("Number of splits :" + wrappedSplits.length+"\n");
        try {
            st.append("Total Length = "+ getLength()+"\n");
            for (int i = 0; i < wrappedSplits.length; i++) {
                st.append("Input split["+i+"]:\n   Length = "+ wrappedSplits[i].getLength()+"\n  Locations:\n");
                for (String location :  wrappedSplits[i].getLocations())
                    st.append("    "+location+"\n");
                st.append("\n-----------------------\n");
          }
        } catch (IOException e) {
          return null;
        } catch (InterruptedException e) {
          return null;
        }
        return st.toString();
    }
View Full Code Here

            throw new ReaderException(rdr.getLineNumber(), rdr.getColumnNumber(), e);
        }
    }

    static private String readToken(PushbackReader r, char initch) {
        StringBuilder sb = new StringBuilder();
        sb.append(initch);

        for (;;) {
            int ch = read1(r);
            if (ch == -1 || isWhitespace(ch) || isTerminatingMacro(ch)) {
                unread(r, ch);
                return sb.toString();
            }
            sb.append((char) ch);
        }
    }
View Full Code Here

            sb.append((char) ch);
        }
    }

    static private Object readNumber(PushbackReader r, char initch) {
        StringBuilder sb = new StringBuilder();
        sb.append(initch);

        for (;;) {
            int ch = read1(r);
            if (ch == -1 || isWhitespace(ch) || isMacro(ch)) {
                unread(r, ch);
                break;
            }
            sb.append((char) ch);
        }

        String s = sb.toString();
        // CUSTOM NUMBERS start
        boolean convert = Character.isLetter(s.charAt(s.length()-1)) && !s.contains("x");
        Number n;
        if (convert) {
            n = matchNumber(s.substring(0, s.length()-1));
View Full Code Here

        this.totalSplits = totalSplits;
    }

    @Override
    public String toString() {
        StringBuilder st = new StringBuilder();
        st.append("Number of splits :" + wrappedSplits.length+"\n");
        try {
            st.append("Total Length = "+ getLength()+"\n");
            for (int i = 0; i < wrappedSplits.length; i++) {
                st.append("Input split["+i+"]:\n   Length = "+ wrappedSplits[i].getLength()+"\n  Locations:\n");
                for (String location :  wrappedSplits[i].getLocations())
                    st.append("    "+location+"\n");
                st.append("\n-----------------------\n");
          }
        } catch (IOException e) {
          return null;
        } catch (InterruptedException e) {
          return null;
        }
        return st.toString();
    }
View Full Code Here

TOP

Related Classes of java.lang.StringBuilder$Cell

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.