Package com.caucho.quercus.env

Examples of com.caucho.quercus.env.StringValue


   */
  @Override
  public StringValue readLine(Env env)
    throws IOException
  {
    StringValue sb = env.createStringBuilder();

    int ch;

    while ((ch = read()) >= 0) {
      sb.append((char) ch);

      if (ch == '\n')
  return sb;
      // XXX: issues with mac
    }

    if (sb.length() > 0)
      return sb;
    else
      return null;
  }
View Full Code Here


                                        StringValue str,
                                        @Optional("ENT_COMPAT") int quoteStyle)
  {
    int len = str.length();
   
    StringValue sb = str.createStringBuilder(len * 4 / 5);

    for (int i = 0; i < len; i++) {
      char ch = str.charAt(i);

      if (ch != '&') {
        sb.append(ch);
       
        continue;
      }
     
      switch (str.charAt(i + 1)) {
        case 'a':
          sb.append('&');
          if (i + 4 < len
              && str.charAt(i + 2) == 'm'
              && str.charAt(i + 3) == 'p'
              && str.charAt(i + 4) == ';') {
            i += 4;
          }
          break;
         
        case 'q':
          if ((quoteStyle & ENT_HTML_QUOTE_DOUBLE) != 0
              && i + 5 < len
              && str.charAt(i + 2) == 'u'
              && str.charAt(i + 3) == 'o'
              && str.charAt(i + 4) == 't'
              && str.charAt(i + 5) == ';') {
            i += 5;
            sb.append('"');
          }
          else
            sb.append('&');
          break;
         
        case '#':
          if ((quoteStyle & ENT_HTML_QUOTE_SINGLE) != 0
              && i + 5 < len
              && str.charAt(i + 2) == '0'
              && str.charAt(i + 3) == '3'
              && str.charAt(i + 4) == '9'
              && str.charAt(i + 5) == ';') {
            i += 5;
            sb.append('\'');
          }
          else
            sb.append('&');
         
          break;

        case 'l':
          if (i + 3 < len
              && str.charAt(i + 2) == 't'
              && str.charAt(i + 3) == ';') {
                i += 3;
               
                sb.append('<');
          }
          else
            sb.append('&');
          break;

        case 'g':
          if (i + 3 < len
              && str.charAt(i + 2) == 't'
              && str.charAt(i + 3) == ';') {
                i += 3;
               
                sb.append('>');
          }
          else
            sb.append('&');
          break;

        default:
          sb.append('&');
      }
    }

    return sb;
  }
View Full Code Here

                                       @Optional("ENT_COMPAT") int quoteStyle,
                                       @Optional String charset)
  {
    int len = string.length();
   
    StringValue sb = string.createStringBuilder(len * 5 / 4);

    for (int i = 0; i < len; i++) {
      char ch = string.charAt(i);

      switch (ch) {
      case '&':
        sb.append("&amp;");
        break;
      case '"':
        if ((quoteStyle & ENT_HTML_QUOTE_DOUBLE) != 0)
          sb.append("&quot;");
        else
          sb.append(ch);
        break;
      case '\'':
        if ((quoteStyle & ENT_HTML_QUOTE_SINGLE) != 0)
          sb.append("&#039;");
        else
          sb.append(ch);
        break;
      case '<':
        sb.append("&lt;");
        break;
      case '>':
        sb.append("&gt;");
        break;
      default:
        sb.append(ch);
        break;
      }
    }

    return sb;
View Full Code Here

      env.warning(e);
     
      reader = new StringReader(string.toString());
    }
   
    StringValue sb = string.createStringBuilder(string.length() * 5 / 4);
   
    int ch;
    try {
      while ((ch = reader.read()) >= 0) {
        StringValue entity = HTML_SPECIALCHARS_MAP[ch & 0xffff];
       
        if (ch == '"') {
          if ((quoteStyle & ENT_HTML_QUOTE_DOUBLE) != 0)
            sb.append("&quot;");
          else
View Full Code Here

      out = Encoding.getWriteEncoding(charset);
    }

    int len = string.length();
    int htmlEntityStart = -1;
    StringValue result = env.createStringBuilder();
   
    try {
      // Loop through each character
      for (int i = 0; i < len; i++) {     
        char ch = string.charAt(i);
       
        // Check whether it's a html entity i.e. starts with '&' and ends with ';'
        if (ch == '&' && htmlEntityStart < 0) {                   
          htmlEntityStart = i;
        }
        else if (htmlEntityStart < 0) {
          // else add it to result.
          result.append(ch);
        }
        else if (ch == ';') {
          // If so substitute the entity and add it to result.
          StringValue entity = string.substring(htmlEntityStart, i + 1);
          Value value = htmlEntities.get(entity);
         
          if (value.isNull()) {
            result.append(entity);
          }
View Full Code Here

   */
  public static Value nl2br(Env env, StringValue string)
  {
    int strLen = string.length();

    StringValue sb = string.createStringBuilder(strLen * 5 / 4);

    for (int i = 0; i < strLen; i++) {
      char ch = string.charAt(i);

      if (ch == '\n') {
        sb.append("<br />\n");
      }
      else if (ch == '\r') {
        if (i + 1 < strLen && string.charAt(i + 1) == '\n') {
          sb.append("<br />\r\n");
          i++;
        }
        else {
          sb.append("<br />\r");
        }
      }
      else {
        sb.append(ch);
      }
    }

    return sb;
  }
View Full Code Here

  private static void entity(ArrayValue array, StringValue []map,
                             ArrayValue revMap, int ch, String entity)
  {
    // XXX: i18n and optimize static variables usage
    array.put("" + (char) ch, entity);
    StringValue entityValue = new StringBuilderValue(entity);
    map[ch & 0xffff] = entityValue;
    revMap.put(entityValue, LongValue.create(ch));
  }
View Full Code Here

                     int strlen,
                     int sIndex,
                     Value var,
                     boolean isReturnArray)
    {
      StringValue sb = string.createStringBuilder();
     
      for (; sIndex < strlen; sIndex++) {
        char ch = string.charAt(sIndex);
       
        if (_set.contains(ch)) {
          sb.append(ch);
        }
        else {
          break;
        }
      }
     
      if (sb.length() > 0)
        sscanfPut(var, sb, isReturnArray);
      else if (isReturnArray)
        var.put(NullValue.NULL);
     
      return sIndex;
View Full Code Here

                     int strlen,
                     int sIndex,
                     Value var,
                     boolean isReturnArray)
    {
      StringValue sb = string.createStringBuilder();
     
      for (; sIndex < strlen; sIndex++) {
        char ch = string.charAt(sIndex);
       
        if (! _set.contains(ch)) {
          sb.append(ch);
        }
        else {
          break;
        }
      }
     
      if (sb.length() > 0)
        sscanfPut(var, sb, isReturnArray);
      else if (isReturnArray)
        var.put(NullValue.NULL);
     
      return sIndex;
View Full Code Here

          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

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.