⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringvalue.java

📁 RESIN 3.2 最新源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      return StringValue.create(charAt((int) index));    }  }  /**   * sets the character at an index   */  @Override  public Value setCharValueAt(long index, String value)  {    //XXX: need to double-check this for non-string values        int len = length();    if (index < 0 || len <= index)      return this;    else {      return (createStringBuilder()              .append(this, 0, (int) index)              .append(value)              .append(this, (int) (index + 1), length()));    }  }  /**   * Pre-increment the following value.   */  public Value preincr(int incr)  {    return postincr(incr);  }  /**   * Post-increment the following value.   */  public Value postincr(int incr)  {    // php/03i6    if (length() == 0) {      if (incr == 1)        return createStringBuilder().append("1");      else        return LongValue.MINUS_ONE;    }    if (incr > 0) {      StringBuilder tail = new StringBuilder();      for (int i = length() - 1; i >= 0; i--) {        char ch = charAt(i);        if (ch == 'z') {          if (i == 0)            return createStringBuilder().append("aa").append(tail);          else            tail.insert(0, 'a');        }        else if ('a' <= ch && ch < 'z') {          return (createStringBuilder()		  .append(this, 0, i)		  .append((char) (ch + 1))		  .append(tail));        }        else if (ch == 'Z') {          if (i == 0)            return createStringBuilder().append("AA").append(tail);          else            tail.insert(0, 'A');        }        else if ('A' <= ch && ch < 'Z') {          return (createStringBuilder()		  .append(this, 0, i)		  .append((char) (ch + 1))		  .append(tail));        }        else if ('0' <= ch && ch <= '9' && i == length() - 1) {          return LongValue.create(toLong() + incr);        }      }      return createStringBuilder().append(tail.toString());    }    else if (getValueType().isLongAdd()) {      return LongValue.create(toLong() + incr);    }    else {      return this;    }  }    /**   * Adds to the following value.   */  public Value add(long rValue)  {    if (getValueType().isLongAdd())      return LongValue.create(toLong() + rValue);        return DoubleValue.create(toDouble() + rValue);  }    /**   * Adds to the following value.   */  public Value sub(long rValue)  {    if (getValueType().isLongAdd())      return LongValue.create(toLong() - rValue);        return DoubleValue.create(toDouble() - rValue);  }    /*   * Bit and.   */  @Override  public Value bitAnd(Value rValue)  {    if (rValue.isString()) {      StringValue rStr = (StringValue) rValue;            int len = Math.min(length(), rValue.length());      StringValue sb = createStringBuilder();            for (int i = 0; i < len; i++) {        char l = charAt(i);        char r = rStr.charAt(i);                sb.appendByte(l & r);      }      return sb;    }    else      return LongValue.create(toLong() & rValue.toLong());  }    /*   * Bit or.   */  @Override  public Value bitOr(Value rValue)  {    if (rValue.isString()) {      StringValue rStr = (StringValue) rValue;            int len = Math.min(length(), rValue.length());      StringValue sb = createStringBuilder();            for (int i = 0; i < len; i++) {        char l = charAt(i);        char r = rStr.charAt(i);                sb.appendByte(l | r);      }           if (len != length())        sb.append(substring(len));      else if (len != rStr.length())        sb.append(rStr.substring(len));      return sb;    }    else      return LongValue.create(toLong() | rValue.toLong());  }    /*   * Bit xor.   */  @Override  public Value bitXor(Value rValue)  {    if (rValue.isString()) {      StringValue rStr = (StringValue) rValue;            int len = Math.min(length(), rValue.length());      StringValue sb = createStringBuilder();            for (int i = 0; i < len; i++) {        char l = charAt(i);        char r = rStr.charAt(i);                sb.appendByte(l ^ r);      }      return sb;    }    else      return LongValue.create(toLong() ^ rValue.toLong());  }    /**   * Serializes the value.   */  @Override  public void serialize(StringBuilder sb)  {    sb.append("s:");    sb.append(length());    sb.append(":\"");    sb.append(toString());    sb.append("\";");  }    /*   * Returns a value to be used as a key for the deserialize cache.   */  /*  public StringValue toSerializeKey()  {    if (length() <= 4096)      return this;    try {      MessageDigest md = MessageDigest.getInstance("SHA1");      byte []buffer = toBytes();      md.update(buffer, 0, buffer.length);      //XXX: create a special serialize type?      return new StringBuilderValue(md.digest());    } catch (NoSuchAlgorithmException e) {      throw new QuercusException(e);    }  }  */  //  // append code  //  /**   * Append a Java string to the value.   */  public StringValue append(String s)  {    throw new UnsupportedOperationException(getClass().getName());  }  /**   * Append a Java string to the value.   */  public StringValue append(String s, int start, int end)  {    throw new UnsupportedOperationException(getClass().getName());  }  /**   * Append a Java buffer to the value.   */  public StringValue append(char []buf, int offset, int length)  {    throw new UnsupportedOperationException(getClass().getName());  }  /**   * Append a Java double to the value.   */  public StringValue append(char []buf)  {    return append(buf, 0, buf.length);  }  /**   * Append a Java buffer to the value.   */  public StringValue append(CharSequence buf, int head, int tail)  {    throw new UnsupportedOperationException(getClass().getName());  }  /**   * Append a Java buffer to the value.   */  public StringValue append(UnicodeBuilderValue sb, int head, int tail)  {    throw new UnsupportedOperationException(getClass().getName());  }    /*   * Appends a Unicode string to the value.   *    * @param str should be a Unicode string   * @param charset to decode string from   */  public StringValue append(Env env, StringValue unicodeStr, String charset)  {    if (! unicodeStr.isUnicode())      return append(unicodeStr);    try {      byte []bytes = unicodeStr.toString().getBytes(charset);            append(bytes);      return this;          }    catch (UnsupportedEncodingException e) {      env.warning(e);            return append(unicodeStr);    }  }  /**   * Append a Java char to the value.   */  public StringValue append(char v)  {    throw new UnsupportedOperationException(getClass().getName());  }  /**   * Append a Java boolean to the value.   */  public StringValue append(boolean v)  {    return append(v ? "true" : "false");  }  /**   * Append a Java long to the value.   */  public StringValue append(long v)  {    return append(String.valueOf(v));  }  /**   * Append a Java double to the value.   */  public StringValue append(double v)  {    return append(String.valueOf(v));  }  /**   * Append a Java value to the value.   */  public StringValue append(Object v)  {    return append(String.valueOf(v));  }  /**   * Append a Java value to the value.   */  public StringValue append(Value v)  {    throw new UnsupportedOperationException(getClass().getName());  }  /**   * Ensure enough append capacity.   */  public void ensureAppendCapacity(int size)  {    throw new UnsupportedOperationException(getClass().getName());  }  /**   * Append a byte buffer to the value.   */  public StringValue append(byte []buf, int offset, int length)  {    throw new UnsupportedOperationException(getClass().getName());  }    /**   * Append a byte buffer to the value.   */  public StringValue append(byte []buf)  {    return append(buf, 0, buf.length);  }    /**   * Append to a string builder.   */  @Override  public StringValue appendTo(UnicodeBuilderValue sb)  {    int length = length();    for (int i = 0; i < length; i++)      sb.append(charAt(i));    return this;  }  /**   * Append a Java boolean to the value.   */  public StringValue appendUnicode(boolean v)  {    return append(v ? "true" : "false");  }  /**   * Append a Java long to the value.   */  public StringValue appendUnicode(long v)  {    return append(String.valueOf(v));  }  /**   * Append a Java double to the value.   */  public StringValue appendUnicode(double v)  {    return append(String.valueOf(v));  }  /**   * Append a Java value to the value.   */  public StringValue appendUnicode(Object v)  {    return append(String.valueOf(v));  }  /**   * Append a Java char, possibly converting to a unicode string   */  public StringValue appendUnicode(char v)  {    return append(v);  }  /**   * Append a Java char buffer, possibly converting to a unicode string   */  public StringValue appendUnicode(char []buffer, int offset, int length)  {    return append(buffer, offset, length);  }  /**   * Append a Java char buffer, possibly converting to a unicode string   */  public StringValue appendUnicode(char []buffer)  {    return append(buffer);  }  /**   * Append a Java char buffer, possibly converting to a unicode string   */  public StringValue appendUnicode(String value)  {    return append(value);  }  /**   * Append a Java char buffer, possibly converting to a unicode string   */  public StringValue appendUnicode(String value, int offset, int length)  {    return append(value, offset, length);  }  /**   * Append a Java char buffer, possibly converting to a unicode string   */  public StringValue appendUnicode(Value value)  {    return append(value);  }  /**   * Append a Java char buffer, possibly converting to a unicode string   */  public StringValue appendUnicode(Value v1, Value v2)  {    return append(v1).append(v2);  }  /**   * Append a Java byte to the value without conversions.   */  public StringValue appendByte(int v)  {    throw new UnsupportedOperationException(getClass().getName());  }    /**   * Append a Java String to the value without conversions.   */  public StringValue appendBytes(String s)  {    StringValue sb = this;        for (int i = 0; i < s.length(); i++) {      sb = sb.appendByte(s.charAt(i));    }        return sb;  }    /**   * Append a Java char[] to the value without conversions.   */  public StringValue appendBytes(char []buf, int offset, int length)  {    StringValue sb = this;    int end = Math.min(buf.length, offset + length);        while (offset < end) {      sb = sb.appendByte(buf[offset++]);    }        return sb;  }  /**   * Append from a read stream   */  public StringValue append(Reader reader)    throws IOException  {    int ch;        while ((ch = reader.read()) >= 0) {      append((char) ch);    }    return this;  }  /**   * Append from a read stream   */  public StringValue append(Reader reader, long length)    throws IOException  {    int ch;        while (length-- > 0 && (ch = reader.read()) >= 0) {      append((char) ch);    }    return this;  }  /**   * Append from an input stream, using InputStream.read semantics,   * i.e. just call is.read once even if more data is available.   */  public int appendRead(InputStream is, long length)  {    TempBuffer tBuf = TempBuffer.allocate();    try {      byte []buffer = tBuf.getBuffer();      int sublen = buffer.length;      if (length < sublen)        sublen = (int) length;      sublen = is.read(buffer, 0, sublen);      if (sublen > 0)        append(buffer, 0, sublen);      return sublen;    } catch (IOException e) {      throw new QuercusModuleException(e);    } finally {      TempBuffer.free(tBuf);    }  }  /**   * Append from an input stream, reading from the input stream until   * end of file or the length is reached.   */  public int appendReadAll(InputStream is, long length)  {    TempBuffer tBuf = TempBuffer.allocate();    try {      byte []buffer = tBuf.getBuffer();      int readLength = 0;            while (length > 0) {	int sublen = buffer.length;	if (length < sublen)	  sublen = (int) length;	sublen = is.read(buffer, 0, sublen);	if (sublen > 0) {	  append(buffer, 0, sublen);	  length -= sublen;	  readLength += sublen;	}	else	  return readLength > 0 ? readLength : -1;      }      return readLength;    } catch (IOException e) {      throw new QuercusModuleException(e);    } finally {      TempBuffer.free(tBuf);    }  }  /**   * Append from an input stream, using InputStream semantics, i.e   * call is.read() only once.   */  public int appendRead(BinaryInput is, long length)  {    TempBuffer tBuf = TempBuffer.allocate();    try {      byte []buffer = tBuf.getBuffer();      int sublen = buffer.length;      if (length < sublen)        sublen = (int) length;      else if (length > sublen) {        buffer = new byte[(int) length];        sublen = (int) length;      }      sublen = is.read(buffer, 0, sublen);      if (sublen > 0)        append(buffer, 0, sublen);      return sublen;    } catch (IOException e) {      throw new QuercusModuleException(e);    } finally {      TempBuffer.free(tBuf);    }  }  /**   * Append from an input stream, reading all available data from the   * stream.   */  public int appendReadAll(BinaryInput is, long length)  {    TempBuffer tBuf = TempBuffer.allocate();    try {      byte []buffer = tBuf.getBuffer();      int readLength = 0;            while (length > 0) {	int sublen = buffer.length;	if (length < sublen)	  sublen = (int) length;	sublen = is.read(buffer, 0, sublen);	if (sublen > 0) {	  append(buffer, 0, sublen);	  length -= sublen;	  readLength += sublen;	}	else	  return readLength > 0 ? readLength : -1;      }      return readLength;    } catch (IOException e) {      throw new QuercusModuleException(e);    } finally {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -