182 if (this.enableUTF16 ==
false && this.enableUTF8 ==
false) {
186 final int buffLen = buff.length;
188 int processedBytes = 0;
189 int curOffset = offset;
190 int startOffset = offset;
191 int curStringLen = 0;
198 int firstUnprocessedOff = offset;
200 while (curOffset < buffLen) {
202 if (buff[curOffset] == 0 && curOffset + 1 < buffLen && buff[curOffset + 1] == 0) {
209 boolean runUTF16 =
false;
223 resWin = runUTF16 && resUTF16.numChars > resUTF8.numChars ? resUTF16 :
resUTF8;
224 }
else if (runUTF16) {
233 if (startOffset == offset) {
235 startOffset = resWin.offset;
237 curStringLen += resWin.numChars;
240 curStringLen += resWin.numChars + 1;
243 curOffset += resWin.numBytes;
244 processedBytes += resWin.numBytes;
245 firstUnprocessedOff = resWin.offset + resWin.numBytes;
258 res.numBytes = processedBytes;
259 res.numChars = curStringLen;
260 res.offset = startOffset;
262 res.firstUnprocessedOff = firstUnprocessedOff;
270 int curOffset = offset;
272 final StringBuilder tempString =
new StringBuilder();
277 while (curOffset < len - 1) {
281 msb = toUnsignedInt(buff[curOffset++]);
282 lsb = toUnsignedInt(buff[curOffset++]);
285 lsb = toUnsignedInt(buff[curOffset++]);
286 msb = toUnsignedInt(buff[curOffset++]);
290 char byteVal = (char) msb;
291 byteVal = (char) (byteVal << 8);
321 currentScript = scriptFound;
324 if (currentScript == scriptFound
326 if (res.numChars == 0) {
328 res.offset = curOffset;
334 tempString.append(byteVal);
346 res.textString = tempString.toString();
354 int curOffset = offset;
358 final StringBuilder tempString =
new StringBuilder();
363 while (curOffset < len) {
365 final int curByte = toUnsignedInt(buff[curOffset]);
366 if (curByte <= 0x7F) {
369 }
else if (curByte <= 0xC1) {
371 }
else if (curByte <= 0xDF) {
372 if (len - curOffset < 2) {
375 final int curByte_1 = toUnsignedInt(buff[curOffset + 1]);
376 if (curByte_1 >= 0x80 && curByte_1 <= 0xBF) {
378 curChar = (((curByte & 0x1f) << 6) + (curByte_1 & 0x3f));
382 }
else if (curByte == 0xE0) {
383 if (len - curOffset < 3) {
386 final int curByte_1 = toUnsignedInt(buff[curOffset + 1]);
387 final int curByte_2 = toUnsignedInt(buff[curOffset + 2]);
389 if (curByte_1 >= 0xA0 && curByte_1 <= 0xBF
390 && curByte_2 >= 0x80 && curByte_2 <= 0xBF) {
392 curChar = (((curByte & 0x0f) << 12) + ((curByte_1 & 0x3f) << 6) + (curByte_2 & 0x3f));
396 }
else if (curByte <= 0xEC) {
397 if (len - curOffset < 3) {
400 final int curByte_1 = toUnsignedInt(buff[curOffset + 1]);
401 final int curByte_2 = toUnsignedInt(buff[curOffset + 2]);
402 if (curByte_1 >= 0x80 && curByte_1 <= 0xBF
403 && curByte_2 >= 0x80 && curByte_2 <= 0xBF) {
405 curChar = (((curByte & 0x0f) << 12) + ((curByte_1 & 0x3f) << 6) + (curByte_2 & 0x3f));
409 }
else if (curByte == 0xED) {
410 if (len - curOffset < 3) {
413 final int curByte_1 = toUnsignedInt(buff[curOffset + 1]);
414 final int curByte_2 = toUnsignedInt(buff[curOffset + 2]);
415 if (curByte_1 >= 0x80 && curByte_1 <= 0x9F
416 && curByte_2 >= 0x80 && curByte_2 <= 0xBF) {
418 curChar = (((curByte & 0x0f) << 12) + ((curByte_1 & 0x3f) << 6) + (curByte_2 & 0x3f));
422 }
else if (curByte <= 0xEF) {
423 if (len - curOffset < 3) {
426 final int curByte_1 = toUnsignedInt(buff[curOffset + 1]);
427 final int curByte_2 = toUnsignedInt(buff[curOffset + 2]);
428 if (curByte_1 >= 0x80 && curByte_1 <= 0xBF
429 && curByte_2 >= 0x80 && curByte_2 <= 0xBF) {
431 curChar = (((curByte & 0x0f) << 12) + ((curByte_1 & 0x3f) << 6) + (curByte_2 & 0x3f));
435 }
else if (curByte == 0xF0) {
436 if (len - curOffset < 4) {
439 final int curByte_1 = toUnsignedInt(buff[curOffset + 1]);
440 final int curByte_2 = toUnsignedInt(buff[curOffset + 2]);
441 final int curByte_3 = toUnsignedInt(buff[curOffset + 3]);
442 if (curByte_1 >= 0x90 && curByte_1 <= 0xBF
443 && curByte_2 >= 0x80 && curByte_2 <= 0xBF
444 && curByte_3 >= 0x80 && curByte_3 <= 0xBF) {
446 curChar = (((curByte & 0x07) << 18) + ((curByte_1 & 0x3f) << 12) + ((curByte_2 & 0x3f) << 6) + (curByte_3 & 0x3f));
450 }
else if (curByte <= 0xF3) {
451 if (len - curOffset < 4) {
454 final int curByte_1 = toUnsignedInt(buff[curOffset + 1]);
455 final int curByte_2 = toUnsignedInt(buff[curOffset + 2]);
456 final int curByte_3 = toUnsignedInt(buff[curOffset + 3]);
457 if (curByte_1 >= 0x80 && curByte_1 <= 0xBF
458 && curByte_2 >= 0x80 && curByte_2 <= 0xBF
459 && curByte_3 >= 0x80 && curByte_3 <= 0xBF) {
461 curChar = (((curByte & 0x07) << 18) + ((curByte_1 & 0x3f) << 12) + ((curByte_2 & 0x3f) << 6) + (curByte_3 & 0x3f));
469 curOffset += chBytes;
498 currentScript = scriptFound;
501 if (currentScript == scriptFound
503 if (res.numChars == 0) {
505 res.offset = curOffset;
508 res.numBytes += chBytes;
511 tempString.append((
char) curChar);
523 res.textString = tempString.toString();