Class CharsetSelector


  • public final class CharsetSelector
    extends java.lang.Object
    Charset Selector A charset selector is built with a list of charset names and given an input CharSequence returns the list of names the corresponding charsets which can convert the CharSequence.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String[] encodings  
      private int[] pv  
      private IntTrie trie  
    • Constructor Summary

      Constructors 
      Constructor Description
      CharsetSelector​(java.util.List<java.lang.String> charsetList, UnicodeSet excludedCodePoints, int mappingTypes)
      Construct a CharsetSelector from a list of charset names.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private int countOnes​(int[] mask, int len)  
      private void generateSelectorData​(PropsVectors pvec, UnicodeSet excludedCodePoints, int mappingTypes)  
      private boolean intersectMasks​(int[] dest, int pvIndex, int len)  
      private java.util.List<java.lang.String> selectForMask​(int[] mask)  
      java.util.List<java.lang.String> selectForString​(java.lang.CharSequence unicodeText)
      Select charsets that can map all characters in a CharSequence, ignoring the excluded code points.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • pv

        private int[] pv
      • encodings

        private java.lang.String[] encodings
    • Constructor Detail

      • CharsetSelector

        public CharsetSelector​(java.util.List<java.lang.String> charsetList,
                               UnicodeSet excludedCodePoints,
                               int mappingTypes)
        Construct a CharsetSelector from a list of charset names.
        Parameters:
        charsetList - a list of charset names in the form of strings. If charsetList is empty, a selector for all available charset is constructed.
        excludedCodePoints - a set of code points to be excluded from consideration. Excluded code points appearing in the input CharSequence do not change the selection result. It could be empty when no code point should be excluded.
        mappingTypes - an int which determines whether to consider only roundtrip mappings or also fallbacks, e.g. CharsetICU.ROUNDTRIP_SET. See CharsetICU.java for the constants that are currently supported.
        Throws:
        java.lang.IllegalArgumentException - if the parameters is invalid.
        java.nio.charset.IllegalCharsetNameException - If the given charset name is illegal.
        java.nio.charset.UnsupportedCharsetException - If no support for the named charset is available in this instance of the Java virtual machine.
    • Method Detail

      • generateSelectorData

        private void generateSelectorData​(PropsVectors pvec,
                                          UnicodeSet excludedCodePoints,
                                          int mappingTypes)
      • intersectMasks

        private boolean intersectMasks​(int[] dest,
                                       int pvIndex,
                                       int len)
      • selectForMask

        private java.util.List<java.lang.String> selectForMask​(int[] mask)
      • countOnes

        private int countOnes​(int[] mask,
                              int len)
      • selectForString

        public java.util.List<java.lang.String> selectForString​(java.lang.CharSequence unicodeText)
        Select charsets that can map all characters in a CharSequence, ignoring the excluded code points.
        Parameters:
        unicodeText - a CharSequence. It could be empty.
        Returns:
        a list that contains charset names in the form of strings. The returned encoding names and their order will be the same as supplied when building the selector.