Package com.caucho.quercus.env

Examples of com.caucho.quercus.env.StringValue


          var.put(NullValue.NULL);
       
        return sIndex;
      }
     
      StringValue sb = string.createStringBuilder();

      int maxLen = _maxLen;

      for (; sIndex < strlen && maxLen-- > 0; sIndex++) {
        char ch = string.charAt(sIndex);

        if (isWhitespace(ch))
          break;

        sb.append(ch);
      }

      sscanfPut(var, sb, isReturnArray);

      return sIndex;
View Full Code Here


    boolean []bitmap = parseCharsetBitmap(env, characters);

    int length = source.length();

    StringValue sb = source.createStringBuilder(length * 5 / 4);

    for (int i = 0; i < length; i++) {
      char ch = source.charAt(i);

      if (ch >= 256 || ! bitmap[ch]) {
        sb.append(ch);
        continue;
      }

      switch (ch) {
      case 0x07:
        sb.append("\\a");
        break;
      case '\b':
        sb.append("\\b");
        break;
      case '\t':
        sb.append("\\t");
        break;
      case '\n':
        sb.append("\\n");
        break;
      case 0xb:
        sb.append("\\v");
        break;
      case '\f':
        sb.append("\\f");
        break;
      case '\r':
        sb.append("\\r");
        break;
      default:
        if (ch < 0x20 || ch >= 0x7f) {
          // save as octal
          sb.append("\\");
          sb.append((char) ('0' + ((ch >> 6) & 7)));
          sb.append((char) ('0' + ((ch >> 3) & 7)));
          sb.append((char) ('0' + ((ch) & 7)));
          break;
        }
        else {
          sb.append("\\");
          sb.append(ch);
          break;
        }
      }
    }

View Full Code Here

   * @param source the source string to convert
   * @return the escaped string
   */
  public static StringValue addslashes(StringValue source)
  {
    StringValue sb = source.createStringBuilder(source.length() * 5 / 4);

    int length = source.length();
    for (int i = 0; i < length; i++) {
      char ch = source.charAt(i);

      switch (ch) {
      case 0x0:
        sb.append("\\0");
        break;
      case '\'':
        sb.append("\\'");
        break;
      case '\"':
        sb.append("\\\"");
        break;
      case '\\':
        sb.append("\\\\");
        break;
      default:
        sb.append(ch);
        break;
      }
    }

    return sb;
View Full Code Here

   * Converts a binary value to a hex value.
   */
  public static StringValue bin2hex(Env env, InputStream is)
  {
    try {
      StringValue sb = env.createUnicodeBuilder();

      int ch;
      while ((ch = is.read()) >= 0) {
        int d = (ch >> 4) & 0xf;

        if (d < 10)
          sb.append((char) (d + '0'));
        else
          sb.append((char) (d + 'a' - 10));

        d = (ch) & 0xf;

        if (d < 10)
          sb.append((char) (d + '0'));
        else
          sb.append((char) (d + 'a' - 10));
      }

      return sb;
    } catch (IOException e) {
      throw new QuercusModuleException(e);
View Full Code Here

  public static StringValue chr(Env env, long value)
  {
    if (! env.isUnicodeSemantics())
      value = value & 0xFF;

    StringValue sb = env.createUnicodeBuilder();

    sb.append((char) value);

    return sb;
  }
View Full Code Here

  public static Value convert_uuencode(StringValue source)
  {
    if (source.length() == 0)
      return BooleanValue.FALSE;

    StringValue result = source.createStringBuilder();

    int i = 0;
    int length = source.length();
    while (i < length) {
      int sublen = length - i;

      if (45 < sublen)
        sublen = 45;

      result.append((char) (sublen + 0x20));

      int end = i + sublen;

      while (i < end) {
        int code = source.charAt(i++) << 16;

        if (i < length)
          code += source.charAt(i++) << 8;

        if (i < length)
          code += source.charAt(i++);

        result.append(toUUChar(((code >> 18) & 0x3f)));
        result.append(toUUChar(((code >> 12) & 0x3f)));
        result.append(toUUChar(((code >> 6) & 0x3f)));
        result.append(toUUChar(((code) & 0x3f)));
      }

      result.append('\n');
    }

    result.append((char) 0x60);
    result.append('\n');

    return result;
  }
View Full Code Here

        return result;
      }

    case 3:
      {
        StringValue sb = data.createStringBuilder();

        for (int i = 0; i < count.length; i++) {
          if (count[i] > 0)
            sb.append((char) i);
        }

        return sb;
      }

    case 4:
      {
        StringValue sb = data.createStringBuilder();

        for (int i = 0; i < count.length; i++) {
          if (count[i] == 0)
            sb.append((char) i);
        }

        return sb;
      }
View Full Code Here

        break;
      }
     
      if (string.regionMatches(i, separator, 0, separatorLength)) {

        StringValue chunk = string.substring(head, i);
        array.append(chunk);
       
        head = i + separatorLength;
        i = head - 1;
      }
    }

    StringValue chunk = string.substring(head);

    array.append(chunk);
   
    while (array.getSize() > 0 && limit++ < 0) {
      array.pop(env);
View Full Code Here

   */
  public static Value implode(Env env,
                              Value glueV,
                              @Optional Value piecesV)
  {
    StringValue glue;
    ArrayValue pieces;

    if ((piecesV.isArray() && glueV.isArray())
         || glueV.isArray()) {
      pieces = glueV.toArrayValue(env);
      glue = piecesV.toStringValue();  
    }
    else if (piecesV.isArray()) {
      pieces = piecesV.toArrayValue(env);
      glue = glueV.toStringValue();
    }
    else {
      env.warning(L.l("neither argument to implode is an array: {0}, {1}",
                    glueV.getClass().getName(), piecesV.getClass().getName()));

      return NullValue.NULL;
    }

    StringValue sb = glue.createStringBuilder();
    boolean isFirst = true;

    Iterator<Value> iter = pieces.getValueIterator(env);

    while (iter.hasNext()) {
      if (! isFirst)
        sb = sb.append(glue);

      isFirst = false;

      sb = sb.append(iter.next());
    }

    return sb;
  }
View Full Code Here

    }
  }

  private static StringValue digestToString(Env env, byte []digest)
  {
    StringValue sb = env.createUnicodeBuilder();
    for (int i = 0; i < digest.length; i++) {
      int d1 = (digest[i] >> 4) & 0xf;
      int d2 = (digest[i] & 0xf);

      sb.append(toHexChar(d1));
      sb.append(toHexChar(d2));
    }

    return sb;
  }
View Full Code Here

TOP

Related Classes of com.caucho.quercus.env.StringValue

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.