/** * Set the 32-bit character at a particular 16-bit offset in a string buffer, * replacing the previous character at that position, and taking account of the * fact that either, both, or neither of the characters might be a surrogate pair. * * @param target the StringBuffer in which the data is to be inserted * @param offset the position at which the data is to be inserted * @param ch32 the character to be inserted, as a 32-bit Unicode codepoint */ private static void setCharAt(FastStringBuffer target, int offset, int ch32) { if (ch32 < 65536) { if (UTF16CharacterSet.isHighSurrogate(target.charAt(offset))) { target.setCharAt(offset, (char) ch32); target.removeCharAt(offset + 1); } else { target.setCharAt(offset, (char) ch32); } } else { if (UTF16CharacterSet.isHighSurrogate(target.charAt(offset))) { target.setCharAt(offset, UTF16CharacterSet.highSurrogate(ch32)); target.setCharAt(offset + 1, UTF16CharacterSet.lowSurrogate(ch32)); } else { target.setCharAt(offset, UTF16CharacterSet.highSurrogate(ch32)); target.insert(offset + 1, UTF16CharacterSet.lowSurrogate(ch32)); } } }
/** * Set the 32-bit character at a particular 16-bit offset in a string buffer, * replacing the previous character at that position, and taking account of the * fact that either, both, or neither of the characters might be a surrogate pair. * * @param target the StringBuffer in which the data is to be inserted * @param offset the position at which the data is to be inserted * @param ch32 the character to be inserted, as a 32-bit Unicode codepoint */ private static void setCharAt(FastStringBuffer target, int offset, int ch32) { if (ch32 < 65536) { if (UTF16CharacterSet.isHighSurrogate(target.charAt(offset))) { target.setCharAt(offset, (char) ch32); target.removeCharAt(offset + 1); } else { target.setCharAt(offset, (char) ch32); } } else { if (UTF16CharacterSet.isHighSurrogate(target.charAt(offset))) { target.setCharAt(offset, UTF16CharacterSet.highSurrogate(ch32)); target.setCharAt(offset + 1, UTF16CharacterSet.lowSurrogate(ch32)); } else { target.setCharAt(offset, UTF16CharacterSet.highSurrogate(ch32)); target.insert(offset + 1, UTF16CharacterSet.lowSurrogate(ch32)); } } }
if (replacement.length() == count) { for (int j = 0; j < count; j++) { buffer.setCharAt(offset + j, replacement.charAt(j));
if (replacement.length() == count) { for (int j = 0; j < count; j++) { buffer.setCharAt(offset + j, replacement.charAt(j));
public String toShortString() { int size = size(); if (size == 0) { return "map{}"; } else if (size > 5) { return "map{(:size " + size + ":)}"; } else { FastStringBuffer buff = new FastStringBuffer(256); buff.append("map{"); Iterator<Tuple2<AtomicMatchKey, KeyValuePair>> iter = imap.iterator(); while (iter.hasNext()) { Tuple2<AtomicMatchKey, KeyValuePair> entry = iter.next(); AtomicMatchKey k1 = entry._1; AtomicValue k2 = entry._2.key; Sequence<?> v = entry._2.value; buff.append(k2.toShortString()); buff.append(':'); buff.append(Err.depictSequence(v).toString().trim()); buff.append(", "); } if (size == 1) { buff.append("}"); } else { buff.setCharAt(buff.length() - 2, '}'); } return buff.toString().trim(); } }
/** * Provide a short string showing the contents of the item, suitable * for use in error messages * * @return a depiction of the item suitable for use in error messages */ @Override public String toShortString() { int size = getLength(); if (size == 0) { return "[]"; } else if (size > 5) { return "[(:size " + size + ":)]"; } else { FastStringBuffer buff = new FastStringBuffer(256); buff.append("["); for (GroundedValue<?> entry : members()) { buff.append(Err.depictSequence(entry).toString().trim()); buff.append(", "); } if (size == 1) { buff.append("]"); } else { buff.setCharAt(buff.length() - 2, ']'); } return buff.toString().trim(); } } }
public String toShortString() { int size = size(); if (size == 0) { return "map{}"; } else if (size > 5) { return "map{(:size " + size + ":)}"; } else { FastStringBuffer buff = new FastStringBuffer(256); buff.append("map{"); Iterator<Tuple2<AtomicMatchKey, KeyValuePair>> iter = imap.iterator(); while (iter.hasNext()) { Tuple2<AtomicMatchKey, KeyValuePair> entry = iter.next(); AtomicMatchKey k1 = entry._1; AtomicValue k2 = entry._2.key; Sequence<?> v = entry._2.value; buff.append(k2.toShortString()); buff.append(':'); buff.append(Err.depictSequence(v).toString().trim()); buff.append(", "); } if (size == 1) { buff.append("}"); } else { buff.setCharAt(buff.length() - 2, '}'); } return buff.toString().trim(); } }
/** * Provide a short string showing the contents of the item, suitable * for use in error messages * * @return a depiction of the item suitable for use in error messages */ @Override public String toShortString() { int size = getLength(); if (size == 0) { return "[]"; } else if (size > 5) { return "[(:size " + size + ":)]"; } else { FastStringBuffer buff = new FastStringBuffer(256); buff.append("["); for (GroundedValue<?> entry : members()) { buff.append(Err.depictSequence(entry).toString().trim()); buff.append(", "); } if (size == 1) { buff.append("]"); } else { buff.setCharAt(buff.length() - 2, ']'); } return buff.toString().trim(); } } }
public ValidationFailure validate( CharSequence input) { // if it's valid as an NCName then it's OK CharSequence trimmed = Whitespace.trimWhitespace(input); if (NameChecker.isValidNCName(trimmed)) { return null; } // if not, replace any colons by underscores and then test if it's a valid NCName FastStringBuffer buff = new FastStringBuffer(trimmed.length()); buff.append(trimmed); for (int i = 0; i < buff.length(); i++) { if (buff.charAt(i) == ':') { buff.setCharAt(i, '_'); } } if (NameChecker.isValidNCName(buff)) { return null; } else { return new ValidationFailure("The value '" + trimmed + "' is not a valid xs:Name"); } } }
public ValidationFailure validate( CharSequence input) { // if it's valid as an NCName then it's OK CharSequence trimmed = Whitespace.trimWhitespace(input); if (NameChecker.isValidNCName(trimmed)) { return null; } // if not, replace any colons by underscores and then test if it's a valid NCName FastStringBuffer buff = new FastStringBuffer(trimmed.length()); buff.append(trimmed); for (int i = 0; i < buff.length(); i++) { if (buff.charAt(i) == ':') { buff.setCharAt(i, '_'); } } if (NameChecker.isValidNCName(buff)) { return null; } else { return new ValidationFailure("The value '" + trimmed + "' is not a valid xs:Name"); } } }
/** * The toString() method on this class is designed for diagnostics only, and the output * should not be regarded as stable between releases. Up to 100 key-value pairs are output in the format * key:value, with comma separators, enclosed between braces: for example "{1:100,2:200}". * @return A string representation of some of the key-value pairs */ @Override public String toString() { // For diagnostics FastStringBuffer buffer = new FastStringBuffer(256); buffer.append("{"); IntIterator keys = keyIterator(); int count = 0; while (keys.hasNext()) { int k = keys.next(); int v = get(k); buffer.append(" " + k + ":" + v + ","); if (count++ >= 100) { buffer.append("...."); break; } } buffer.setCharAt(buffer.length() - 1, '}'); return buffer.toString(); }
/** * The toString() method on this class is designed for diagnostics only, and the output * should not be regarded as stable between releases. Up to 100 key-value pairs are output in the format * key:value, with comma separators, enclosed between braces: for example "{1:100,2:200}". * @return A string representation of some of the key-value pairs */ @Override public String toString() { // For diagnostics FastStringBuffer buffer = new FastStringBuffer(256); buffer.append("{"); IntIterator keys = keyIterator(); int count = 0; while (keys.hasNext()) { int k = keys.next(); int v = get(k); buffer.append(" " + k + ":" + v + ","); if (count++ >= 100) { buffer.append("...."); break; } } buffer.setCharAt(buffer.length() - 1, '}'); return buffer.toString(); }