Java UTF8 utf8CharLen(byte byte1)

Here you can find the source of utf8CharLen(byte byte1)

Description

utf Char Len

License

Apache License

Declaration

private static int utf8CharLen(byte byte1) 

Method Source Code

//package com.java2s;
/*//from  w w w . jav  a2  s .  c  om
 * Copyright 2014 Bazaarvoice, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    private static int utf8CharLen(byte byte1) {
        if ((byte1 & 0x80) == 0) {
            return 1;
        } else if ((byte1 & 0xE0) == 0xC0) {
            return 2;
        } else if ((byte1 & 0xF0) == 0xE0) {
            return 3;
        } else if ((byte1 & 0xF8) == 0xF0) {
            return 4;
        } else if ((byte1 & 0xFC) == 0xF8) {
            return 5;
        } else {
            return 6;
        }
    }
}

Related

  1. utf8(String string)
  2. utf8BufferByteLen(CharSequence str)
  3. utf8ByteLength(String string)
  4. utf8BytesToString(byte[] bytes, int start, int length)
  5. utf8BytesToString(final byte[] in_utf8Bytes)
  6. UTF8GetBytes(final String value)
  7. UTF8GetString(final byte[] bytes, final int index, final int count)
  8. utf8Len(byte b)
  9. utf8Length(byte[] buffer, int str, int len)