📄 unicodebuildervalue.java
字号:
@Override public CharSequence subSequence(int start, int end) { if (end <= start) return EMPTY; char []newBuffer = new char[end - start]; System.arraycopy(_buffer, start, newBuffer, 0, end - start); return new UnicodeBuilderValue(newBuffer, 0, end - start); } // // java.lang.String // /** * Convert to lower case. */ @Override public StringValue toLowerCase() { int length = _length; UnicodeBuilderValue string = new UnicodeBuilderValue(length); char []srcBuffer = _buffer; char []dstBuffer = string._buffer; for (int i = 0; i < length; i++) { char ch = srcBuffer[i]; if ('A' <= ch && ch <= 'Z') dstBuffer[i] = (char) (ch + 'a' - 'A'); else if (ch < 0x80) dstBuffer[i] = ch; else if (Character.isUpperCase(ch)) dstBuffer[i] = Character.toLowerCase(ch); else dstBuffer[i] = ch; } string._length = length; return string; } /** * Convert to lower case. */ @Override public StringValue toUpperCase() { int length = _length; UnicodeBuilderValue string = new UnicodeBuilderValue(_length); char []srcBuffer = _buffer; char []dstBuffer = string._buffer; for (int i = 0; i < length; i++) { char ch = srcBuffer[i]; if ('a' <= ch && ch <= 'z') dstBuffer[i] = (char) (ch + 'A' - 'a'); else if (ch < 0x80) dstBuffer[i] = ch; else if (Character.isLowerCase(ch)) dstBuffer[i] = Character.toUpperCase(ch); else dstBuffer[i] = ch; } string._length = length; return string; } /** * Returns a character array */ @Override public char []toCharArray() { char[] dest = new char[_length]; System.arraycopy(_buffer, 0, dest, 0, _length); return dest; } public char []getRawCharArray() { return _buffer; } /** * Returns the buffer backing this StringBuilderValue. */ public char []getBuffer() { return _buffer; } /** * Prints the value. * @param env */ public void print(Env env) { env.print(_buffer, 0, _length); } /** * Serializes the value. */ public void serialize(StringBuilder sb) { sb.append("U:"); sb.append(_length); sb.append(":\""); sb.append(_buffer, 0, _length); sb.append("\";"); } // // append code // /** * Creates a string builder of the same type. */ @Override public StringValue createStringBuilder() { return new UnicodeBuilderValue(); } /** * Creates a string builder of the same type. */ @Override public StringValue createStringBuilder(int length) { return new UnicodeBuilderValue(length); } /** * Converts to a string builder */ @Override public StringValue toStringBuilder(Env env) { return new UnicodeBuilderValue(_buffer, 0, _length); } @Override public String toDebugString() { StringBuilder sb = new StringBuilder(); int length = length(); sb.append("unicode("); sb.append(length); sb.append(") \""); int appendLength = length > 256 ? 256 : length; for (int i = 0; i < appendLength; i++) sb.append(charAt(i)); if (length > 256) sb.append(" ..."); sb.append('"'); return sb.toString(); } @Override public void varDumpImpl(Env env, WriteStream out, int depth, IdentityHashMap<Value, String> valueSet) throws IOException { int length = length(); if (length < 0) length = 0; out.print("unicode("); out.print(length); out.print(") \""); for (int i = 0; i < length; i++) out.print(charAt(i)); out.print("\""); } // // java.lang.Object methods // // // Java generator code // /** * Generates code to recreate the expression. * * @param out the writer to the Java source code. */ public void generate(PrintWriter out) throws IOException { out.print("new UnicodeBuilderValue(\""); printJavaString(out, this); out.print("\")"); } private void copyOnWrite() { if (_isCopy) { _isCopy = false; char []buffer = new char[_buffer.length]; System.arraycopy(_buffer, 0, buffer, 0, _length); _buffer = buffer; } } // // static helper functions // public static int getNumericType(char []buffer, int offset, int len) { if (len == 0) return IS_STRING; int i = offset; int ch = 0; boolean hasPoint = false; if (i < len && ((ch = buffer[i]) == '+' || ch == '-')) { i++; } if (len <= i) return IS_STRING; ch = buffer[i]; if (ch == '.') { for (i++; i < len && '0' <= (ch = buffer[i]) && ch <= '9'; i++) { return IS_DOUBLE; } return IS_STRING; } else if (! ('0' <= ch && ch <= '9')) return IS_STRING; for (; i < len && '0' <= (ch = buffer[i]) && ch <= '9'; i++) { } if (len <= i) return IS_LONG; else if (ch == '.' || ch == 'e' || ch == 'E') { for (i++; i < len && ('0' <= (ch = buffer[i]) && ch <= '9' || ch == '+' || ch == '-' || ch == 'e' || ch == 'E'); i++) { } if (i < len) return IS_STRING; else return IS_DOUBLE; } else return IS_STRING; } public static ValueType getValueType(char []buffer, int offset, int len) { if (len == 0) { // php/0307 return ValueType.LONG_ADD; } int i = offset; int ch = 0; boolean hasPoint = false; if (i < len && ((ch = buffer[i]) == '+' || ch == '-')) { i++; } if (len <= i) return ValueType.STRING; ch = buffer[i]; if (ch == '.') { for (i++; i < len && '0' <= (ch = buffer[i]) && ch <= '9'; i++) { return ValueType.DOUBLE_CMP; } return ValueType.STRING; } else if (! ('0' <= ch && ch <= '9')) return ValueType.STRING; for (; i < len && '0' <= (ch = buffer[i]) && ch <= '9'; i++) { } if (len <= i) return ValueType.LONG_EQ; else if (ch == '.' || ch == 'e' || ch == 'E') { for (i++; i < len && ('0' <= (ch = buffer[i]) && ch <= '9' || ch == '+' || ch == '-' || ch == 'e' || ch == 'E'); i++) { } if (i < len) return ValueType.STRING; else return ValueType.DOUBLE_CMP; } else return ValueType.STRING; } /** * Converts to a long. */ public static long toLong(char []buffer, int offset, int len) { return parseLong(buffer, offset, len); } public static double toDouble(char []buffer, int offset, int len) { int i = offset; int ch = 0; if (i < len && ((ch = buffer[i]) == '+' || ch == '-')) { i++; } for (; i < len && '0' <= (ch = buffer[i]) && ch <= '9'; i++) { } if (ch == '.') { for (i++; i < len && '0' <= (ch = buffer[i]) && ch <= '9'; i++) { } if (i == 1) return 0; } if (ch == 'e' || ch == 'E') { int e = i++; if (i < len && (ch = buffer[i]) == '+' || ch == '-') { i++; } for (; i < len && '0' <= (ch = buffer[i]) && ch <= '9'; i++) { } if (i == e + 1) i = e; } if (i == 0) return 0; try { return Double.parseDouble(new String(buffer, 0, i)); } catch (NumberFormatException e) { return 0; } } static { CHAR_STRINGS = new UnicodeBuilderValue[256]; for (int i = 0; i < CHAR_STRINGS.length; i++) CHAR_STRINGS[i] = new UnicodeBuilderValue((char) i); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -