Java UTF8 utf8StringLength(final CharSequence sequence)

Here you can find the source of utf8StringLength(final CharSequence sequence)

Description

utf String Length

License

Apache License

Declaration

public static int utf8StringLength(final CharSequence sequence) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int utf8StringLength(final CharSequence sequence) {
        int count = 0;
        for (int i = 0, len = sequence.length(); i < len; i++) {
            char ch = sequence.charAt(i);
            if (ch <= 0x7F) {
                count++;//  w  w  w.ja  v a 2  s . c o  m
            } else if (ch <= 0x7FF) {
                count += 2;
            } else if (Character.isHighSurrogate(ch)) {
                count += 4;
                ++i;
            } else {
                count += 3;
            }
        }
        return count;
    }
}

Related

  1. utf8Len(byte b)
  2. utf8Length(byte[] buffer, int str, int len)
  3. utf8Replace(String str)
  4. utf8SafeCEscape(String src)
  5. utf8String(String... strs)
  6. utf8StringSizeInBytes(String s)
  7. utf8StringToByteArray(String dataString)
  8. utf8StringToBytes(String string)
  9. utf8ToString(byte[] data)