Find the first occured tab in a UTF-8 encoded string
@param utf a byte array containing a UTF-8 encoded string
@return position that first tab occures otherwise -1
764503
public static int findTab(byte [] utf) {
    return org.apache.hadoop.util.UTF8ByteArrayUtils.findNthByte(utf, 0, 
        utf.length, (byte)'\t', 1);
  }
315078
public static function findCharPosition($string, $char, $start_at = 0)
    {
        $position = strpos($string, $char, $start_at);

        return ($position !== false) ? $position + 1 : null;
    }
1318574
public static String toPGString(byte[] buf) {
    if (buf == null) {
      return null;
    }
    StringBuilder stringBuilder = new StringBuilder(2 * buf.length);
    for (byte element : buf) {
      int elementAsInt = (int) element;
      if (elementAsInt < 0) {
        elementAsInt = 256 + elementAsInt;
      }
      // we escape the same non-printable characters as the backend
      // we must escape all 8bit characters otherwise when convering
      // from java unicode to the db character set we may end up with
      // question marks if the character set is SQL_ASCII
      if (elementAsInt < 040 || elementAsInt > 0176) {
        // escape charcter with the form \000, but need two \\ because of
        // the Java parser
        stringBuilder.append("\\");
        stringBuilder.append((char) (((elementAsInt >> 6) & 0x3) + 48));
        stringBuilder.append((char) (((elementAsInt >> 3) & 0x7) + 48));
        stringBuilder.append((char) ((elementAsInt & 0x07) + 48));
      } else if (element == (byte) '\\') {
        // escape the backslash character as \\, but need four \\\\ because
        // of the Java parser
        stringBuilder.append("\\\\");
      } else {
        // other characters are left alone
        stringBuilder.append((char) element);
      }
    }
    return stringBuilder.toString();
  }
215064
int getTabIndex(Component component) {

        List<Component> tabs = Lists.newArrayList(m_tabs.iterator());
        while (component != null) {
            int pos = tabs.indexOf(component);
            if (pos >= 0) {
                return pos;
            }
            component = component.getParent();
        }
        return -1;
    }
218625
private int findFirst(CharSequence input, int beginIndex, int rewindIndex) {
        int first = -1;
        boolean atomBoundary = true;
        for (int i = beginIndex; i >= rewindIndex; i--) {
            char c = input.charAt(i);
            if (localAtomAllowed(c)) {
                first = i;
                atomBoundary = false;
            } else if (c == '.') {
                if (atomBoundary) {
                    break;
                }
                atomBoundary = true;
            } else {
                break;
            }
        }
        return first;
    }
12603
private static int firstNonMatchPosition(Slice utf8, int[] codePointsToMatch)
    {
        int length = utf8.length();

        int position = 0;
        while (position < length) {
            int codePoint = tryGetCodePointAt(utf8, position);
            if (codePoint < 0) {
                break;
            }
            if (!matches(codePoint, codePointsToMatch)) {
                break;
            }
            position += lengthOfCodePoint(codePoint);
        }
        return position;
    }
376050
public String getUtf8AsString(int index)
  {
    Utf8Constant utf8 = (Utf8Constant) _entries.get(index);

    if (utf8 == null)
      return null;
    else
      return utf8.getValue();
  }
272990
def utf8_char_length_in_bytes(first_byte)
      if first_byte.hex < 'C0'.hex
        1
      elsif first_byte.hex < 'DF'.hex
        2
      elsif first_byte.hex < 'EF'.hex
        3
      else
        4
      end
    end
433357
static int writeUtf8(AbstractByteBuf buffer, int writerIndex, CharSequence seq, int len) {
        int oldWriterIndex = writerIndex;

        // 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++) {
            char c = seq.charAt(i);
            if (c < 0x80) {
                buffer._setByte(writerIndex++, (byte) c);
            } else if (c < 0x800) {
                buffer._setByte(writerIndex++, (byte) (0xc0 | (c >> 6)));
                buffer._setByte(writerIndex++, (byte) (0x80 | (c & 0x3f)));
            } else if (isSurrogate(c)) {
                if (!Character.isHighSurrogate(c)) {
                    buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
                    continue;
                }
                final char c2;
                try {
                    // Surrogate Pair consumes 2 characters. Optimistically try to get the next character to avoid
                    // duplicate bounds checking with charAt. If an IndexOutOfBoundsException is thrown we will
                    // re-throw a more informative exception describing the problem.
                    c2 = seq.charAt(++i);
                } catch (IndexOutOfBoundsException ignored) {
                    buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
                    break;
                }
                // Extra method to allow inlining the rest of writeUtf8 which is the most likely code path.
                writerIndex = writeUtf8Surrogate(buffer, writerIndex, c, c2);
            } else {
                buffer._setByte(writerIndex++, (byte) (0xe0 | (c >> 12)));
                buffer._setByte(writerIndex++, (byte) (0x80 | ((c >> 6) & 0x3f)));
                buffer._setByte(writerIndex++, (byte) (0x80 | (c & 0x3f)));
            }
        }
        return writerIndex - oldWriterIndex;
    }
592441
public int getTabIndex(final WComponent content) {
		List<WTab> tabs = getTabs();
		final int count = tabs.size();

		for (int i = 0; i < count; i++) {
			WTab tab = tabs.get(i);

			if (content == tab.getContent()) {
				return i;
			}
		}

		return -1;
	}
543619
public static int setCodePointAt(int codePoint, Slice utf8, int position)
    {
        if (codePoint < 0) {
            throw new InvalidCodePointException(codePoint);
        }
        if (codePoint < 0x80) {
            // normal ASCII
            // 0xxx_xxxx
            utf8.setByte(position, codePoint);
            return 1;
        }
        if (codePoint < 0x800) {
            // 110x_xxxx 10xx_xxxx
            utf8.setByte(position, 0b1100_0000 | (codePoint >>> 6));
            utf8.setByte(position + 1, 0b1000_0000 | (codePoint & 0b0011_1111));
            return 2;
        }
        if (MIN_SURROGATE <= codePoint && codePoint <= MAX_SURROGATE) {
            throw new InvalidCodePointException(codePoint);
        }
        if (codePoint < 0x1_0000) {
            // 1110_xxxx 10xx_xxxx 10xx_xxxx
            utf8.setByte(position, 0b1110_0000 | ((codePoint >>> 12) & 0b0000_1111));
            utf8.setByte(position + 1, 0b1000_0000 | ((codePoint >>> 6) & 0b0011_1111));
            utf8.setByte(position + 2, 0b1000_0000 | (codePoint & 0b0011_1111));
            return 3;
        }
        if (codePoint < 0x11_0000) {
            // 1111_0xxx 10xx_xxxx 10xx_xxxx 10xx_xxxx
            utf8.setByte(position, 0b1111_0000 | ((codePoint >>> 18) & 0b0000_0111));
            utf8.setByte(position + 1, 0b1000_0000 | ((codePoint >>> 12) & 0b0011_1111));
            utf8.setByte(position + 2, 0b1000_0000 | ((codePoint >>> 6) & 0b0011_1111));
            utf8.setByte(position + 3, 0b1000_0000 | (codePoint & 0b0011_1111));
            return 4;
        }
        // Per RFC3629, UTF-8 is limited to 4 bytes, so more bytes are illegal
        throw new InvalidCodePointException(codePoint);
    }
1225193
public static final int readUTF(DataInput in,
                                    char[] chars, int offset, int length,
                                    int bytesExpected)
        throws IOException
    {
        int c, c2, c3;

        int byteCount = 0;
        int charCount = 0;
        while (byteCount < bytesExpected && charCount < length) {
            c = in.readByte() & 0xff;
            switch (c >> 4) {
            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
                // 0xxxxxxx
                byteCount++;
                chars[offset + charCount++] = (char)c;
                break;
            case 12: case 13:
                // 110x xxxx  10xx xxxx
                if ((byteCount += 2) > bytesExpected) {
                    throw new UTFDataFormatException();
                }
                c2 = in.readByte();
                if ((c2 & 0xc0) != 0x80) {
                    throw new UTFDataFormatException();
                }
                chars[offset + charCount++] =
                    (char)(((c & 0x1f) << 6) | (c2 & 0x3f));
                break;
            case 14:
                // 1110 xxxx  10xx xxxx  10xx xxxx
                if ((byteCount += 3) > bytesExpected) {
                    throw new UTFDataFormatException();
                }
                c2 = in.readByte();
                c3 = in.readByte();
                if ((c2 & 0xc0) != 0x80 || (c3 & 0xc0) != 0x80) {
                    throw new UTFDataFormatException();
                }
                chars[offset + charCount++] = (char)(((c & 0x0f) << 12) |
                                                     ((c2 & 0x3f) << 6) |
                                                     (c3 & 0x3f));
                break;
            default:
                // 10xx xxxx,  1111 xxxx
                throw new UTFDataFormatException();
            }
        }

        return charCount;
    }
1205437
public int putUTF8(int pos, String s) {
		ByteBuffer minibb = null;
		
		CharsetEncoder enc = getUTF8Encoder();
		CharBuffer in = CharBuffer.wrap(s);
		
		int pos2 = pos;
		ByteBuffer bb = getBuffer(pos2);
		int index = pos2 % _bufferSize;
		bb.position(index);
		
		while (in.remaining() > 0) {
			CoderResult res = enc.encode(in, bb, true);
			
			//flush minibb first
			if (bb == minibb) {
				bb.flip();
				while (bb.remaining() > 0) {
					putByte(pos2, bb.get());
					++pos2;
				}
			} else {
				pos2 += bb.position() - index;
			}
			
			if (res.isOverflow()) {
				if (bb.remaining() > 0) {
					//exceeded buffer boundaries; write to a small temporary buffer
					if (minibb == null) {
						minibb = ByteBuffer.allocate(4);
					}
					minibb.clear();
					bb = minibb;
					index = 0;
				} else {
					bb = getBuffer(pos2);
					index = pos2 % _bufferSize;
					bb.position(index);
				}
			} else if (res.isError()) {
				try {
					res.throwException();
				} catch (CharacterCodingException e) {
					throw new RuntimeException("Could not encode string", e);
				}
			}
		}
		
		adaptSize(pos2);
		return pos2 - pos;
	}
978356
public static String findFirstWord(String buffer) {
        if (buffer.indexOf(SPACE_CHAR) < 0)
            return buffer;
        else {
            buffer = Parser.trim(buffer);
            int index = buffer.indexOf(SPACE_CHAR);
            if (index > 0)
                return buffer.substring(0, index);
            else
                return buffer;
        }
    }
321308
final String readString(int position, Charset encoding) {
        // Sanity check the string size int position. Note that the eventual
        // m_buffer.get() does check for underflow, getInt() does not.
        if (STRING_LEN_SIZE > m_buffer.limit() - position) {
            throw new RuntimeException(String.format(
                    "VoltTableRow::readString: Can't read string size as %d byte integer " +
                    "from buffer with %d bytes remaining.",
                    STRING_LEN_SIZE, m_buffer.limit() - position));
        }
        final int len = m_buffer.getInt(position);
        //System.out.println(len);

        // check for null string
        if (len == VoltTable.NULL_STRING_INDICATOR)
            return null;

        if (len < 0) {
            throw new RuntimeException("Invalid object length.");
        }

        // Sanity check the size against the remaining buffer size.
        if (position + STRING_LEN_SIZE + len > m_buffer.limit()) {
            throw new RuntimeException(String.format(
                    "VoltTableRow::readString: Can't read %d byte string " +
                    "from buffer with %d bytes remaining.",
                    len, m_buffer.limit() - position - STRING_LEN_SIZE));
        }

        // this is a bit slower than directly getting the array (see below)
        // but that caused bugs
        byte[] stringData = new byte[len];
        int oldPos = m_buffer.position();
        m_buffer.position(position + STRING_LEN_SIZE);
        m_buffer.get(stringData);
        m_buffer.position(oldPos);

        return new String(stringData, encoding);
    }
739352
public static function ucFirst($string)
    {
        return self::strToUpper(mb_substr($string, 0, 1, 'UTF-8'))
        . self::strToLower(mb_substr($string, 1, null, 'UTF-8'));
    }
1166040
public static int compareUtf16BE(Slice utf8Left, Slice utf8Right)
    {
        int leftLength = utf8Left.length();
        int rightLength = utf8Right.length();

        int offset = 0;
        while (offset < leftLength) {
            // if there are no more right code points, right is less
            if (offset >= rightLength) {
                return 1; // left.compare(right) > 0
            }

            int leftCodePoint = tryGetCodePointAt(utf8Left, offset);
            if (leftCodePoint < 0) {
                throw new InvalidUtf8Exception("Invalid UTF-8 sequence in utf8Left at " + offset);
            }

            int rightCodePoint = tryGetCodePointAt(utf8Right, offset);
            if (rightCodePoint < 0) {
                throw new InvalidUtf8Exception("Invalid UTF-8 sequence in utf8Right at " + offset);
            }

            int result = compareUtf16BE(leftCodePoint, rightCodePoint);
            if (result != 0) {
                return result;
            }

            // the code points are the same and non-canonical sequences are not allowed,
            // so we advance a single offset through both sequences
            offset += lengthOfCodePoint(leftCodePoint);
        }

        // there are no more left code points, so if there are more right code points,
        // left is less
        if (offset < rightLength) {
            return -1; // left.compare(right) < 0
        }

        return 0;
    }