Class Utf8Util

java.lang.Object
dev.blaauwendraad.masker.json.util.Utf8Util

public final class Utf8Util extends Object
UTF-8 encoding utilities class
  • Method Details

    • getCodePointByteLength

      public static int getCodePointByteLength(byte input)
      UTF-8: variable width 1-4 byte code points: 1 byte: 0xxxxxxx 2 bytes: 110xxxxx 10xxxxxx 3 bytes: 1110xxxx 10xxxxxx 10xxxxxx 4 bytes: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
      Parameters:
      input - first (or only) code point byte
      Returns:
      code point length in bytes
    • countNonVisibleCharacters

      public static int countNonVisibleCharacters(byte[] message, int fromIndex, int length)
      Counts amount of non-visible characters inside the string. The intervals supplied must be within a single string (already inside quotes) as this method will not do boundary checks or look for end of string value. an escaped quotes.
      Parameters:
      message - the byte array containing the string
      fromIndex - the starting index of the string value (after the quote)
      length - the length of the string value (excluding the quotes)
      Returns:
      the amount of non-visible characters in the string - escape characters, UTF-8 character data (''), characters that use more than a single byte