static int writeAscii(AbstractByteBuf buffer, int writerIndex, CharSequence seq, int len) { // We can use the _set methods as these not need to do any index checks and reference checks. // This is possible as we called ensureWritable(...) before. for (int i = 0; i < len; i++) { buffer._setByte(writerIndex++, AsciiString.c2b(seq.charAt(i))); } return len; }
/** * Copies this string replacing occurrences of the specified character with another character. * * @param oldChar the character to replace. * @param newChar the replacement character. * @return a new string with occurrences of oldChar replaced by newChar. */ public AsciiString replace(char oldChar, char newChar) { if (oldChar > MAX_CHAR_VALUE) { return this; } final byte oldCharAsByte = c2b0(oldChar); final byte newCharAsByte = c2b(newChar); final int len = offset + length; for (int i = offset; i < len; ++i) { if (value[i] == oldCharAsByte) { byte[] buffer = PlatformDependent.allocateUninitializedArray(length()); System.arraycopy(value, offset, buffer, 0, i - offset); buffer[i - offset] = newCharAsByte; ++i; for (; i < len; ++i) { byte oldValue = value[i]; buffer[i - offset] = oldValue != oldCharAsByte ? oldValue : newCharAsByte; } return new AsciiString(buffer, false); } } return this; }
static int writeAscii(AbstractByteBuf buffer, int writerIndex, CharSequence seq, int len) { // We can use the _set methods as these not need to do any index checks and reference checks. // This is possible as we called ensureWritable(...) before. for (int i = 0; i < len; i++) { buffer._setByte(writerIndex++, AsciiString.c2b(seq.charAt(i))); } return len; }
/** * Copies this string replacing occurrences of the specified character with another character. * * @param oldChar the character to replace. * @param newChar the replacement character. * @return a new string with occurrences of oldChar replaced by newChar. */ public AsciiString replace(char oldChar, char newChar) { if (oldChar > MAX_CHAR_VALUE) { return this; } final byte oldCharAsByte = c2b0(oldChar); final byte newCharAsByte = c2b(newChar); final int len = offset + length; for (int i = offset; i < len; ++i) { if (value[i] == oldCharAsByte) { byte[] buffer = PlatformDependent.allocateUninitializedArray(length()); System.arraycopy(value, offset, buffer, 0, i - offset); buffer[i - offset] = newCharAsByte; ++i; for (; i < len; ++i) { byte oldValue = value[i]; buffer[i - offset] = oldValue != oldCharAsByte ? oldValue : newCharAsByte; } return new AsciiString(buffer, false); } } return this; }
/** * Create a copy of {@code value} into this instance assuming ASCII encoding. * The copy will start at index {@code start} and copy {@code length} bytes. */ public AsciiString(CharSequence value, int start, int length) { if (isOutOfBounds(start, length, value.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= start(" + start + ") <= start + length(" + length + ") <= " + "value.length(" + value.length() + ')'); } this.value = PlatformDependent.allocateUninitializedArray(length); for (int i = 0, j = start; i < length; i++, j++) { this.value[i] = c2b(value.charAt(j)); } this.offset = 0; this.length = length; }
/** * Copies this string replacing occurrences of the specified character with another character. * * @param oldChar the character to replace. * @param newChar the replacement character. * @return a new string with occurrences of oldChar replaced by newChar. */ public AsciiString replace(char oldChar, char newChar) { if (oldChar > MAX_CHAR_VALUE) { return this; } final byte oldCharAsByte = c2b0(oldChar); final byte newCharAsByte = c2b(newChar); final int len = offset + length; for (int i = offset; i < len; ++i) { if (value[i] == oldCharAsByte) { byte[] buffer = new byte[length()]; System.arraycopy(value, offset, buffer, 0, i - offset); buffer[i - offset] = newCharAsByte; ++i; for (; i < len; ++i) { byte oldValue = value[i]; buffer[i - offset] = oldValue != oldCharAsByte ? oldValue : newCharAsByte; } return new AsciiString(buffer, false); } } return this; }
static int writeAscii(AbstractByteBuf buffer, int writerIndex, CharSequence seq, int len) { // We can use the _set methods as these not need to do any index checks and reference checks. // This is possible as we called ensureWritable(...) before. for (int i = 0; i < len; i++) { buffer._setByte(writerIndex++, AsciiString.c2b(seq.charAt(i))); } return len; }
/** * Copies this string replacing occurrences of the specified character with another character. * * @param oldChar the character to replace. * @param newChar the replacement character. * @return a new string with occurrences of oldChar replaced by newChar. */ public AsciiString replace(char oldChar, char newChar) { if (oldChar > MAX_CHAR_VALUE) { return this; } final byte oldCharAsByte = c2b0(oldChar); final byte newCharAsByte = c2b(newChar); final int len = offset + length; for (int i = offset; i < len; ++i) { if (value[i] == oldCharAsByte) { byte[] buffer = PlatformDependent.allocateUninitializedArray(length()); System.arraycopy(value, offset, buffer, 0, i - offset); buffer[i - offset] = newCharAsByte; ++i; for (; i < len; ++i) { byte oldValue = value[i]; buffer[i - offset] = oldValue != oldCharAsByte ? oldValue : newCharAsByte; } return new AsciiString(buffer, false); } } return this; }
/** * Create a copy of {@code value} into this instance assuming ASCII encoding. * The copy will start at index {@code start} and copy {@code length} bytes. */ public AsciiString(char[] value, int start, int length) { if (isOutOfBounds(start, length, value.length)) { throw new IndexOutOfBoundsException("expected: " + "0 <= start(" + start + ") <= start + length(" + length + ") <= " + "value.length(" + value.length + ')'); } this.value = PlatformDependent.allocateUninitializedArray(length); for (int i = 0, j = start; i < length; i++, j++) { this.value[i] = c2b(value[j]); } this.offset = 0; this.length = length; }
private static void writeCharSequence(ByteBuf buf, int offset, CharSequence value, int valueLen) { for (int i = 0; i < valueLen; ++i) { buf.setByte(offset++, c2b(value.charAt(i))); } } }
/** * Create a copy of {@code value} into this instance assuming ASCII encoding. * The copy will start at index {@code start} and copy {@code length} bytes. */ public AsciiString(CharSequence value, int start, int length) { if (isOutOfBounds(start, length, value.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= start(" + start + ") <= start + length(" + length + ") <= " + "value.length(" + value.length() + ')'); } this.value = PlatformDependent.allocateUninitializedArray(length); for (int i = 0, j = start; i < length; i++, j++) { this.value[i] = c2b(value.charAt(j)); } this.offset = 0; this.length = length; }
/** * Create a copy of {@code value} into this instance assuming ASCII encoding. * The copy will start at index {@code start} and copy {@code length} bytes. */ public AsciiString(CharSequence value, int start, int length) { if (isOutOfBounds(start, length, value.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= start(" + start + ") <= start + length(" + length + ") <= " + "value.length(" + value.length() + ')'); } this.value = new byte[length]; for (int i = 0, j = start; i < length; i++, j++) { this.value[i] = c2b(value.charAt(j)); } this.offset = 0; this.length = length; }
/** * Create a copy of {@code value} into this instance assuming ASCII encoding. * The copy will start at index {@code start} and copy {@code length} bytes. */ public AsciiString(char[] value, int start, int length) { if (isOutOfBounds(start, length, value.length)) { throw new IndexOutOfBoundsException("expected: " + "0 <= start(" + start + ") <= start + length(" + length + ") <= " + "value.length(" + value.length + ')'); } this.value = new byte[length]; for (int i = 0, j = start; i < length; i++, j++) { this.value[i] = c2b(value[j]); } this.offset = 0; this.length = length; }
/** * Create a copy of {@code value} into this instance assuming ASCII encoding. * The copy will start at index {@code start} and copy {@code length} bytes. */ public AsciiString(char[] value, int start, int length) { if (isOutOfBounds(start, length, value.length)) { throw new IndexOutOfBoundsException("expected: " + "0 <= start(" + start + ") <= start + length(" + length + ") <= " + "value.length(" + value.length + ')'); } this.value = PlatformDependent.allocateUninitializedArray(length); for (int i = 0, j = start; i < length; i++, j++) { this.value[i] = c2b(value[j]); } this.offset = 0; this.length = length; }
System.arraycopy(value, arrayOffset(), newValue, 0, thisLen); for (int i = thisLen, j = 0; i < newValue.length; i++, j++) { newValue[i] = c2b(string.charAt(j));
System.arraycopy(value, arrayOffset(), newValue, 0, thisLen); for (int i = thisLen, j = 0; i < newValue.length; i++, j++) { newValue[i] = c2b(string.charAt(j));
System.arraycopy(value, arrayOffset(), newValue, 0, thisLen); for (int i = thisLen, j = 0; i < newValue.length; i++, j++) { newValue[i] = c2b(string.charAt(j));
static int writeAscii(AbstractByteBuf buffer, int writerIndex, CharSequence seq, int len) { // We can use the _set methods as these not need to do any index checks and reference checks. // This is possible as we called ensureWritable(...) before. for (int i = 0; i < len; i++) { buffer._setByte(writerIndex++, AsciiString.c2b(seq.charAt(i))); } return len; }
/** * Create a copy of {@code value} into this instance assuming ASCII encoding. * The copy will start at index {@code start} and copy {@code length} bytes. */ public AsciiString(CharSequence value, int start, int length) { if (isOutOfBounds(start, length, value.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= start(" + start + ") <= start + length(" + length + ") <= " + "value.length(" + value.length() + ')'); } this.value = PlatformDependent.allocateUninitializedArray(length); for (int i = 0, j = start; i < length; i++, j++) { this.value[i] = c2b(value.charAt(j)); } this.offset = 0; this.length = length; }
/** * Create a copy of {@code value} into this instance assuming ASCII encoding. * The copy will start at index {@code start} and copy {@code length} bytes. */ public AsciiString(char[] value, int start, int length) { if (isOutOfBounds(start, length, value.length)) { throw new IndexOutOfBoundsException("expected: " + "0 <= start(" + start + ") <= start + length(" + length + ") <= " + "value.length(" + value.length + ')'); } this.value = PlatformDependent.allocateUninitializedArray(length); for (int i = 0, j = start; i < length; i++, j++) { this.value[i] = c2b(value[j]); } this.offset = 0; this.length = length; }