Package com.caucho.quercus.env

Examples of com.caucho.quercus.env.ArrayValue


      else if (value instanceof Number)
        return new long[] { ((Number) value).longValue() };
      else if (value == null)
        return null;
      else if (value instanceof ArrayValue) {
        ArrayValue array = (ArrayValue) value;
       
        long []result = new long[array.getSize()];
       
        for (int i = 0; i < result.length; i++)
          result[i] = array.get(LongValue.create(i)).toLong();
       
        return result;
      }
      else {
        try {
View Full Code Here


    }

    switch (mode) {
    case 0:
      {
        ArrayValue result = new ArrayValueImpl();

        for (int i = 0; i < count.length; i++) {
          result.put(LongValue.create(i), LongValue.create(count[i]));
        }

        return result;
      }

    case 1:
      {
        ArrayValue result = new ArrayValueImpl();

        for (int i = 0; i < count.length; i++) {
          if (count[i] > 0)
            result.put(LongValue.create(i), LongValue.create(count[i]));
        }

        return result;
      }

    case 2:
      {
        ArrayValue result = new ArrayValueImpl();

        for (int i = 0; i < count.length; i++) {
          if (count[i] == 0)
            result.put(LongValue.create(i), LongValue.create(count[i]));
        }

        return result;
      }
View Full Code Here

      env.warning(L.l("Delimiter is empty"));
      return BooleanValue.FALSE;
    }
   
    int head = 0;   
    ArrayValue array = new ArrayValueImpl();

    int separatorLength = separator.length();
    int stringLength = string.length();
    long ulimit;
   
    if (limit >= 0) {
      ulimit = limit;     
    } else {
      ulimit = 0x7fffffff;
    }

    for (int i = 0; i < stringLength; ++i) {
     
      if (ulimit <= array.getSize() + 1) {
        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);
    }

    return array;
  }
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);
View Full Code Here

  public static Value parse_str(Env env, StringValue str,
                                @Optional @Reference Value ref)
  {
    boolean isRef = ref instanceof Var;

    ArrayValue result = null;

    if (isRef) {
      result = new ArrayValueImpl();
      ref.set(result);
    }
View Full Code Here

    if (strlen == 0) {
      return isReturnArray ? NullValue.NULL : LongValue.MINUS_ONE;
    }

    ArrayValue array = new ArrayValueImpl();

    for (int i = 0; i < formatArray.length; i++) {
      ScanfSegment segment = formatArray[i];

      Value var;
View Full Code Here

    if (strlen == 0) {
      return isAssign ? LongValue.MINUS_ONE : NullValue.NULL;
    }

    ArrayValue array = new ArrayValueImpl();

    while (fIndex < fmtLen) {
      char ch = format.charAt(fIndex++);

      if (isWhitespace(ch)) {
        for (;
             (fIndex < fmtLen
                 && isWhitespace(ch = format.charAt(fIndex)));
             fIndex++) {
        }

        /*ch = string.charAt(sIndex);
        if (! isWhitespace(ch)) {
          // XXX: return false?
          return sscanfReturn(env, array, args, argIndex, isAssign, true);
        }*/

        for (;
          sIndex < strlen && isWhitespace(string.charAt(sIndex));
          sIndex++) {
        }
      }
      else if (ch == '%') {
        int maxLen = -1;

        loop:
        while (fIndex < fmtLen) {
          ch = format.charAt(fIndex++);

          if (sIndex >= strlen && ch != 'n') {
            array.append(NullValue.NULL);
            break loop;
          }

          Value obj;

View Full Code Here

    if (search.isNull())
      return subject;

    if (subject instanceof ArrayValue) {
      ArrayValue subjectArray = (ArrayValue) subject;
      ArrayValue resultArray = new ArrayValueImpl();

      for (Map.Entry<Value, Value> entry : subjectArray.entrySet()) {

        if (entry.getValue() instanceof ArrayValue) {
          resultArray.append(entry.getKey(), entry.getValue());
        } else {
          Value result = strReplaceImpl(env,
                                      search,
                                      replace,
                                      entry.getValue().toStringValue(),
                                      count,
                                      isInsensitive);

          resultArray.append(entry.getKey(), result);
        }
      }

      return resultArray;
    }
View Full Code Here

                               subject,
                               count,
                               isInsensitive);
    }
    else if (replace instanceof ArrayValue) {
      ArrayValue searchArray = (ArrayValue) search;
      ArrayValue replaceArray = (ArrayValue) replace;

      Iterator<Value> searchIter = searchArray.values().iterator();
      Iterator<Value> replaceIter = replaceArray.values().iterator();

      while (searchIter.hasNext()) {
        Value searchItem = searchIter.next();
        Value replaceItem = replaceIter.next();

        if (replaceItem == null)
          replaceItem = NullValue.NULL;

        subject = strReplaceImpl(env,
                                 searchItem.toStringValue(),
                                 replaceItem.toStringValue(),
                                 subject,
                                 count,
                                 isInsensitive);
      }
    }
    else {
      ArrayValue searchArray = (ArrayValue) search;

      Iterator<Value> searchIter = searchArray.values().iterator();

      while (searchIter.hasNext()) {
        Value searchItem = searchIter.next();

        subject = strReplaceImpl(env,
View Full Code Here

   * @param chunk chunk size
   */
  public static Value str_split(StringValue string,
                                @Optional("1") int chunk)
  {
    ArrayValue array = new ArrayValueImpl();

    if (string.length() == 0) {
      array.put(string);
      return array;
    }

    int strLen = string.length();

    int currentArrayIndex = 0;
    for (int i = 0; i < strLen; i += chunk) {
      Value value;

      if (i + chunk <= strLen) {
        value = string.substring(i, i + chunk);
      } else {
        value = string.substring(i);
      }

      array.put(LongValue.create(currentArrayIndex), value);
      currentArrayIndex++;
    }

    return array;
  }
View Full Code Here

TOP

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

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.