MCPcopy Create free account
hub / github.com/beanshell/beanshell / putUTF

Method putUTF

src/bsh/org/objectweb/asm/ByteVector.java:213–251  ·  view source on GitHub ↗

Puts a String in UTF format into this byte vector. The byte vector is automatically enlarged if necessary. @param s a String. @return this byte vector.

(final String s)

Source from the content-addressed store, hash-verified

211 */
212
213 public ByteVector putUTF (final String s) {
214 int charLength = s.length();
215 int byteLength = 0;
216 for (int i = 0; i < charLength; ++i) {
217 char c = s.charAt(i);
218 if (c >= '\001' && c <= '\177') {
219 byteLength++;
220 } else if (c > '\u07FF') {
221 byteLength += 3;
222 } else {
223 byteLength += 2;
224 }
225 }
226 if (byteLength > 65535) {
227 throw new IllegalArgumentException();
228 }
229 int length = this.length;
230 if (length + 2 + byteLength > data.length) {
231 enlarge(2 + byteLength);
232 }
233 byte[] data = this.data;
234 data[length++] = (byte)(byteLength >>> 8);
235 data[length++] = (byte)(byteLength);
236 for (int i = 0; i < charLength; ++i) {
237 char c = s.charAt(i);
238 if (c >= '\001' && c <= '\177') {
239 data[length++] = (byte)c;
240 } else if (c > '\u07FF') {
241 data[length++] = (byte)(0xE0 | c >> 12 & 0xF);
242 data[length++] = (byte)(0x80 | c >> 6 & 0x3F);
243 data[length++] = (byte)(0x80 | c & 0x3F);
244 } else {
245 data[length++] = (byte)(0xC0 | c >> 6 & 0x1F);
246 data[length++] = (byte)(0x80 | c & 0x3F);
247 }
248 }
249 this.length = length;
250 return this;
251 }
252
253 /**
254 * Puts an array of bytes into this byte vector. The byte vector is

Callers 1

newUTF8Method · 0.80

Calls 1

enlargeMethod · 0.95

Tested by

no test coverage detected