Android UTF8 Encode bytesUTF8len(byte[] buf, int bufOffset, int bufLength)

Here you can find the source of bytesUTF8len(byte[] buf, int bufOffset, int bufLength)

Description

get the length of the bytes in UTF-8 rules: 0xxxxxxx or 11xxxxxx is the first the byte of the

Parameter

Parameter Description
buf a parameter

Declaration

private static int bytesUTF8len(byte[] buf, int bufOffset, int bufLength) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w ww  . j a  va2  s . c o m*/
     * get the length of the bytes in UTF-8
     * rules: 0xxxxxxx or 11xxxxxx is the first the byte of the 
     * @param buf
     * @return
     */
    private static int bytesUTF8len(byte[] buf, int bufOffset, int bufLength) {
        int len = 0;
        for (int i = bufOffset; i < (bufOffset + bufLength); i++) {
            if (((buf[i]) & 0x80) == 0x00 || ((buf[i]) & 0xc0) == 0xc0) {
                len++;
            }
        }
        return len;
    }
}

Related

  1. toUtf8(String str)
  2. bytesUtf8(int c)
  3. bytes2StringUTF8(byte[] buf)
  4. bytes2StringUTF8(byte[] buf, int bufOffset, int bufLength, boolean bigEndian)
  5. bytes2charsUTF8(byte[] buf, int bufOffset, int bufLength, char[] cbuf, boolean bigEndian)
  6. char2ByteUTF8(String input, int inOff, int inEnd, byte[] output, int outOff, int outEnd, boolean getLengthFlag)
  7. getStringInUtf8(final String str)
  8. stringToUtf8Bytes(String string)
  9. utf8encode(String str)