Package com.caucho.util

Examples of com.caucho.util.CharBuffer


    if (length < 2 + offset ||
        uri.charAt(offset) != '/' ||
        uri.charAt(offset + 1) != '/')
      throw new RuntimeException(L.l("bad scheme in `{0}'", uri));

    CharBuffer buf = CharBuffer.allocate();
    int i = 2 + offset;
    int ch = 0;
    for (; i < length && (ch = uri.charAt(i)) != ':' && ch != '/' && ch != '?';
         i++) {
      buf.append((char) ch);
    }

    String host = buf.close();
    if (host.length() == 0)
      throw new RuntimeException(L.l("bad host in `{0}'", uri));

    int port = 0;
    if (ch == ':') {
View Full Code Here


            crc64 = Crc64.generate(crc64, pattern);
          }
        }
      }

      CharBuffer cb = new CharBuffer();
      Base64.encode(cb, crc64);
      String newETag = cb.close();
      host.setConfigETag(newETag);
   
      writeString(os, HMUX_ETAG, host.getConfigETag());
    }
    else {
View Full Code Here

    return _matchPatterns.size() - 1;
  }

  String getName(String tag)
  {
    CharBuffer newTag = new CharBuffer();

    for (int i = 0; i < tag.length(); i++) {
      int ch = tag.charAt(i);
      switch (ch) {
      case ' ':
      case '\t':
      case '\r':
      case '\n':
      case '(':
      case ')':
        break;

      case ':':
      case '.':
      case '|':
        newTag.append('_');
        break;

      default:
        if (ch >= 'a' && ch <= 'z' ||
            ch >= 'A' && ch <= 'Z' ||
            ch >= '0' && ch <= '9')
          newTag.append((char) ch);
      }
    }
    tag = newTag.toString();

    if (_names.get(tag) == null) {
      _names.put(tag, tag);
      return tag;
    }
View Full Code Here

   * @param elt the containing element.  Needed for namespaces.
   */
  void generateString(String string, int mode, Element elt)
    throws Exception
  {
    CharBuffer cb = new CharBuffer();
    int i = 0;
    boolean first = true;
    int length = string.length();

    for (; i < length; i++) {
      char ch = string.charAt(i);

      if (ch == '\n') {
        cb.append("\\n");
      }
      else if (ch == '"') {
        cb.append("\\\"");
      }
      else if (ch == '{' && i + 1 < length) {
        // {{ is treated as a single {
        if (string.charAt(i + 1) == '{') {
          cb.append('{');
          i++;
        }
        // the value is computed from an XPath expr
        else {
          // print the gathered text if any
          if (mode == ',') {
            if (cb.length() > 0)
              println("out.print(\"" + cb.toString() + "\");");
          }
          else {
            if (! first)
              print((char) mode);

            if (cb.length() > 0) {
              print("\"");
              print(cb.toString());
              print("\"");
              print((char) mode);
            }
          }

          // scan the contents of '{' ... '}'
          cb.clear();
          for (i++; i < length && string.charAt(i) != '}'; i++)
            cb.append(string.charAt(i));

          // and add the results
          if (mode == ',')
            printStringExpr(cb.toString(), elt);
          else
            stringExpr(cb.toString(), elt);
          cb.clear();
          first = false;
        }
      }
      // }} is treated as a single }
      else if (ch == '}' && i + 1 < length) {
        if (string.charAt(i + 1) == '}') {
          cb.append('}');
          i++;
        }
        else
          cb.append('}');
      }
      // <#= interpolates
      else if (i + 2 < length && ch == '<' &&
               string.charAt(i + 1) == '#' &&
               string.charAt(i + 2) == '=') {
        // print the gathered text if any
        if (mode == ',') {
          if (cb.length() > 0)
            println("out.print(\"" + cb.toString() + "\");");
        }
        else {
          if (! first)
            print((char) mode);

          if (cb.length() > 0) {
            print("\"");
            print(cb.toString());
            print("\"");
            print((char) mode);
          }
        }

        // scan the contents of '{' ... '}'
        cb.clear();
        for (i += 3;
             i + 1 < length && string.charAt(i) != '#' &&
               string.charAt(i + 1) != '>';
             i++)
          cb.append(string.charAt(i));

        i++;

        // and add the results
        if (mode == ',')
          println("out.print(" + cb + ");");
        else {
          print("(" + cb + ")");
        }
        cb.clear();
        first = false;
      }
      else
        cb.append((char) ch);
    }

    // add any trailing text
    if (cb.length() > 0) {
      if (mode == ',')
        println("out.print(\"" + cb + "\");");
      else {
        if (! first)
          print((char) mode);
View Full Code Here

    }
  }

  public String toString()
  {
    CharBuffer cb = CharBuffer.allocate();
    cb.append("(");

    for (int i = 0; i < _exprList.size(); i++) {
      if (i != 0)
        cb.append(" AND ");

      cb.append(_exprList.get(i));
    }

    cb.append(")");

    return cb.close();
  }
View Full Code Here

   * @return the variable storing the generated string.
   */
  String generateStringVar(String string, Element elt)
    throws Exception
  {
    CharBuffer cb = new CharBuffer();
    int i = 0;
    boolean first = true;
    int length = string.length();

    String strVar = "_xsl_str" + _unique++;

    if (string.indexOf('{') < 0 &&
        string.indexOf('}') < 0) {
      print("String " + strVar + " = \"");
      printString(string);
      println("\";");
     
      return strVar;
    }
    else if (string.lastIndexOf('{') == 0 &&
        string.indexOf('}') == string.length() - 1) {
      println("String " + strVar + " = \"\";");
      string = string.substring(1, string.length() - 1);
     
      addStringExpr(strVar, string, elt, true);
      return strVar;
    }

   
    String cbVar = "_xsl_cb" + _unique++;

    println("com.caucho.util.CharBuffer " + cbVar +
            " = com.caucho.util.CharBuffer.allocate();");

    for (; i < length; i++) {
      char ch = string.charAt(i);

      if (ch == '\n') {
        cb.append("\\n");
      }
      else if (ch == '"') {
        cb.append("\\\"");
      }
      else if (ch == '{' && i + 1 < length) {
        // {{ is treated as a single {
        if (string.charAt(i + 1) == '{') {
          cb.append('{');
          i++;
        }
        // the value is computed from an XPath expr
        else {
          // print the gathered text if any
          if (cb.length() > 0)
            println(cbVar + ".append(\"" + cb.toString() + "\");");

          // scan the contents of '{' ... '}'
          cb.clear();
          for (i++; i < length && string.charAt(i) != '}'; i++)
            cb.append(string.charAt(i));

          // and add the results
          addStringExpr(cbVar, cb.toString(), elt, false);
         
          cb.clear();
          first = false;
        }
      }
      // }} is treated as a single }
      else if (ch == '}' && i + 1 < length) {
        if (string.charAt(i + 1) == '}') {
          cb.append('}');
          i++;
        }
        else
          cb.append('}');
      }
      // <#= interpolates
      else if (i + 2 < length && ch == '<' &&
               string.charAt(i + 1) == '#' &&
               string.charAt(i + 2) == '=') {
        // print the gathered text if any
        if (cb.length() > 0)
          println(cbVar + ".append(\"" + cb.toString() + "\");");

        // scan the contents of '<#=' ... '#>'
        cb.clear();
        for (i += 3;
             i + 1 < length && string.charAt(i) != '#' &&
               string.charAt(i + 1) != '>';
             i++)
          cb.append(string.charAt(i));

        i++;

        // and add the results
        println(cbVar + ".append(" + cb + ");");
        cb.clear();
        first = false;
      }
      else
        cb.append((char) ch);
    }

    // add any trailing text
    if (cb.length() > 0)
      println(cbVar + ".append(\"" + cb + "\");");

    println("String " + strVar + " = " + cbVar + ".close();");

    return strVar;
View Full Code Here

   * Converts a string to a Java identifier, encoding unknown characters
   * as "_"
   */
  public String toJavaIdentifier(String name)
  {
    CharBuffer cb = new CharBuffer();

    char ch = name.charAt(0);
    if (Character.isJavaIdentifierStart(ch))
      cb.append(ch);
    else
      cb.append("_");

    for (int i = 1; i < name.length(); i++) {
      ch = name.charAt(i);
     
      if (Character.isJavaIdentifierPart(ch))
        cb.append(ch);
      else {
        cb.append("_");
        cb.append((char) ((ch & 0xf) + 'a'));
        cb.append((char) ((ch / 16 & 0xf) + 'a'));
      }
    }

    return cb.toString();
  }
View Full Code Here

        throw error(L.l("`@' expected at {0}", charName(ch)));
      return scanToken();
    }

    if (Character.isJavaIdentifierStart((char) ch)) {
      CharBuffer cb = _cb;
      cb.clear();

      for (; ch > 0 && Character.isJavaIdentifierPart((char) ch); ch = read())
        cb.append((char) ch);

      unread(ch);

      _lexeme = cb.toString();
      String lower = _lexeme.toLowerCase(Locale.ENGLISH);

      int token = _reserved.get(lower);

      if (token > 0)
        return token;
      else
        return IDENTIFIER;
    }
    else if (ch >= '0' && ch <= '9') {
      CharBuffer cb = _cb;
      cb.clear();

      int type = INTEGER;

      if (sign < 0)
        cb.append('-');

      for (; ch >= '0' && ch <= '9'; ch = read())
        cb.append((char) ch);

      if (ch == '.') {
        type = DOUBLE;

        cb.append('.');
        for (ch = read(); ch >= '0' && ch <= '9'; ch = read())
          cb.append((char) ch);
      }

      if (ch == 'e' || ch == 'E') {
        type = DOUBLE;

        cb.append('e');
        if ((ch = read()) == '+' || ch == '-') {
          cb.append((char) ch);
          ch = read();
        }

        if (! (ch >= '0' && ch <= '9'))
          throw error(L.l("exponent needs digits at {0}",
                          charName(ch)));

        for (; ch >= '0' && ch <= '9'; ch = read())
          cb.append((char) ch);
      }

      if (ch == 'F' || ch == 'D')
        type = DOUBLE;
      else if (ch == 'L') {
        type = LONG;
      }
      else
        unread(ch);

      _lexeme = cb.toString();

      return type;
    }
    else if (ch == '\'') {
      CharBuffer cb = _cb;
      cb.clear();

      for (ch = read(); ch >= 0; ch = read()) {
        if (ch == '\'') {
          if ((ch = read()) == '\'')
            cb.append('\'');
          else {
            unread(ch);
            break;
          }
        }
        else if (ch == '\\') {
          ch = read();

          if (ch >= 0)
            cb.append(ch);
        }
        else
          cb.append((char) ch);
      }

      _lexeme = cb.toString();

      return STRING;
    }
    else if (ch == '#') {
      // skip comment
View Full Code Here

  /**
   * Returns the named attribute set.
   */
  public HashMap<String,String> getAttributeSet(String name)
  {
    CharBuffer cb = CharBuffer.allocate();
    int i = 0;
    int len = name.length();

    HashMap<String,String> map = new HashMap<String,String>();
   
    while (i < len) {
      for (; i < len && name.charAt(i) == ' '; i++) {
      }

      cb.clear();
      for (; i < len && name.charAt(i) != ' '; i++)
        cb.append(name.charAt(i));

      if (cb.length() > 0) {
        XslAttributeSet newSet = _attributeSets.get(cb.toString());

        if (newSet != null) {
          ArrayList<XslAttribute> attrList = newSet.getAttributes();

          for (int j = 0; j < attrList.size(); j++) {
View Full Code Here

  /**
   * Returns the named attribute set.
   */
  public ArrayList<XslAttribute> getAttributeSetList(String name)
  {
    CharBuffer cb = CharBuffer.allocate();
    int i = 0;
    int len = name.length();

    ArrayList<XslAttribute> set = new ArrayList<XslAttribute>();
   
    while (i < len) {
      for (; i < len && name.charAt(i) == ' '; i++) {
      }

      cb.clear();
      for (; i < len && name.charAt(i) != ' '; i++)
        cb.append(name.charAt(i));

      if (cb.length() > 0) {
        XslAttributeSet newSet = _attributeSets.get(cb.toString());

        if (newSet != null) {
          set.addAll(newSet.getAttributes());
        }
      }
View Full Code Here

TOP

Related Classes of com.caucho.util.CharBuffer

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.