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

📄 unicodebuildervalue.java

📁 RESIN 3.2 最新源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT.  See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * *   Free Software Foundation, Inc. *   59 Temple Place, Suite 330 *   Boston, MA 02111-1307  USA * * @author Scott Ferguson */package com.caucho.quercus.env;import com.caucho.quercus.Quercus;import com.caucho.quercus.QuercusModuleException;import com.caucho.quercus.QuercusRuntimeException;import com.caucho.vfs.*;import java.io.*;import java.util.IdentityHashMap;/** * Represents a PHP string value. */public class UnicodeBuilderValue extends StringBuilderValue{  public static final UnicodeBuilderValue EMPTY = new UnicodeBuilderValue("");  private final static UnicodeBuilderValue []CHAR_STRINGS;  public UnicodeBuilderValue()  {  }  public UnicodeBuilderValue(int capacity)  {    super(capacity);  }  public UnicodeBuilderValue(String value)  {    super(value);  }  public UnicodeBuilderValue(String value, int minLength)  {    super(value);  }  public UnicodeBuilderValue(char []buffer, int offset, int length)  {    super(buffer, offset, length);  }  private UnicodeBuilderValue(char []buffer, int offset, int length,                             String copy)  {    super(buffer, offset, length);  }  public UnicodeBuilderValue(char []buffer)  {    super(buffer, 0, buffer.length);  }  public UnicodeBuilderValue(char []buffer, int length)  {    super(buffer, 0, length);  }  public UnicodeBuilderValue(char []buffer, int offset, int length,                            boolean isExact)  {    super(buffer, offset, length);  }  public UnicodeBuilderValue(Character []buffer)  {    super(buffer);  }  public UnicodeBuilderValue(char ch)  {    super(ch);  }  public UnicodeBuilderValue(char []s, Value v1)  {    super(s, v1);  }  public UnicodeBuilderValue(Value v1)  {    super(v1);  }  /**   * Creates the string.   */  public static StringValue create(char value)  {    if (value < CHAR_STRINGS.length)      return CHAR_STRINGS[value];    else      return new UnicodeBuilderValue(value);  }  /**   * Creates a PHP string from a Java String.   * If the value is null then NullValue is returned.   */  public static Value create(String value)  {    if (value == null)      return NullValue.NULL;    else if (value.length() == 0)      return UnicodeBuilderValue.EMPTY;    else      return new UnicodeBuilderValue(value);  }  /*   * Decodes the Unicode str from charset.   *    * @param str should be a Unicode string   * @param charset to decode string from   */  @Override  public StringValue create(Env env, StringValue str, String charset)  {    return str;  }    /*   * Creates an empty string builder of the same type.   */  public StringValue createEmptyStringBuilder()  {    return new UnicodeBuilderValue();  }    /*   * Returns the empty string of same type.   */  public StringValue getEmptyString()  {    return EMPTY;  }    /**   * Decodes from charset and returns UnicodeValue.   *   * @param env   * @param charset   */  public StringValue convertToUnicode(Env env, String charset)  {    return this;  }    /**   * Returns true for UnicodeValue   */  @Override  public boolean isUnicode()  {    return true;  }    /**   * Returns the value.   */  public String getValue()  {    return toString();  }  /**   * Returns the type.   */  public String getType()  {    return "string";  }  /**   * Returns the ValueType.   */  @Override  public ValueType getValueType()  {    return getValueType(_buffer, 0, _length);  }  /**   * Interns the string.   */  public StringValue intern(Quercus quercus)  {    return quercus.intern(toString());  }  /**   * Converts to a string builder   */  @Override  public StringValue toStringBuilder()  {    return new UnicodeBuilderValue(_buffer, 0, _length);  }  /**   * Converts to a UnicodeValue.   */  @Override  public StringValue toUnicodeValue()  {    return this;  }  /**   * Converts to a UnicodeValue.   */  @Override  public StringValue toUnicodeValue(Env env)  {    return this;  }  /**   * Converts to a UnicodeValue in desired charset.   */  @Override  public StringValue toUnicodeValue(Env env, String charset)  {    return this;  }  /**   * Append a buffer to the value.   */  /*  public final StringValue append(byte []buf, int offset, int length)  {    if (_buffer.length < _length + length)      ensureCapacity(_length + length);    Env env = Env.getInstance();    String charset = (env != null		      ? env.getRuntimeEncoding().toString()		      : null);    // ...    char []charBuffer = _buffer;    int charLength = _length;    for (int i = 0; i < length; i++)      charBuffer[charLength + i] = (char) buf[offset + i];    _length += length;    return this;  }  */  /*   * Appends a Unicode string to the value.   *    * @param str should be a Unicode string   * @param charset to decode string from   */  @Override  public StringValue append(Env env, StringValue unicodeStr, String charset)  {    return append(unicodeStr);  }    /**   * Append to a string builder.   */  @Override  public StringValue appendTo(UnicodeBuilderValue sb)  {    sb.append(_buffer, 0, _length);    return sb;  }  /**   * Converts to a BinaryValue.   */  @Override  public StringValue toBinaryValue()  {    return toBinaryValue(Env.getInstance());  }  /**   * Converts to a BinaryValue.   */  @Override  public StringValue toBinaryValue(Env env)  {    return toBinaryValue(env, env.getRuntimeEncoding());  }  /**   * Converts to a BinaryValue in desired charset.   *   * @param env   * @param charset   */  public StringValue toBinaryValue(Env env, String charset)  {    try {      BinaryBuilderValue result = new BinaryBuilderValue();      BinaryBuilderStream stream = new BinaryBuilderStream(result);      // XXX: can use EncodingWriter directly(?)      WriteStream out = new WriteStream(stream);      out.setEncoding(charset);      out.print(_buffer, 0, _length);      out.close();      return result;    } catch (IOException e) {      throw new QuercusModuleException(e.getMessage());    }  }  /**   * Returns the character at an index   */  @Override  public Value charValueAt(long index)  {    int len = _length;    if (index < 0 || len <= index)      return UnsetUnicodeValue.UNSET;    else {      int ch = _buffer[(int) index];      if (ch < CHAR_STRINGS.length)	return CHAR_STRINGS[ch];      else	return new UnicodeBuilderValue((char) ch);    }  }  /**   * sets the character at an index   */  /*  @Override  public Value setCharValueAt(long index, String value)  {    if (_isCopy)      copyOnWrite();        int len = _length;    if (index < 0 || len <= index)      return this;    else {      UnicodeBuilderValue sb = new UnicodeBuilderValue(_buffer, 0, (int) index);      sb.append(value);      sb.append(_buffer, (int) (index + 1), (int) (len - index - 1));      return sb;    }  }  /*  /**   * Returns a subsequence   */

⌨️ 快捷键说明

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