コード例 #1
0
        /// <summary>
        /// Get a unique list of the charsets from the bestfit database.
        /// </summary>
        /// <returns></returns>
        public List <String> GetAvailableTransforms()
        {
            List <String> transforms = new List <string>();
            var           query      = (from mapping in XDocUnicode.Descendants("Mapping")
                                        select(string) mapping.Element("Transform").Value).Distinct();

            foreach (var charset in query.Distinct())
            {
                transforms.Add(charset);
            }
            return(transforms);
        }
コード例 #2
0
        /// <summary>
        /// Get all normalization mappings for an ASCII character.  Optionally specify a specific transform
        /// as a filter.
        /// </summary>
        /// <param name="cAscii">A single ASCII character.</param>
        /// <param name="sTransform">Valid transformations specified as:
        ///
        /// Simple_Lowercase_Mapping
        /// Lowercase_Mapping
        /// Simple_Case_Folding
        /// cf
        /// Simple_Uppercase_Mapping
        /// Simple_Titlecase_Mapping
        /// Uppercase_Mapping
        /// Titlecase_Mapping
        /// Decomposition_Mapping
        /// FC_NFKC
        /// </param>
        /// <returns></returns>
        public List <String> GetNormalizationMappings(char cAscii, string sTransform = "")
        {
            UnicodeMapping um = new UnicodeMapping();

            // If something is passed in we don't know about then set transform to a wildcard
            if (!um.transformations.Contains(sTransform))
            {
                sTransform = "";
            }
            UniChar uc = new UniChar();

            uc.CodePoint = uc.GetCodePoint(cAscii);
            IEnumerable <string> query;

            // If a transformation wasn't specified, filter by the ASCII character
            if (String.IsNullOrEmpty(sTransform))
            {
                query = (from mapping in XDocUnicode.Descendants("Mapping")
                         where
                         (string)mapping.Element("Ascii") == uc.CodePoint
                         select mapping.Element("Unicode").Value);
            }

            // else filter by the transformation too
            else
            {
                query = (from mapping in XDocUnicode.Descendants("Mapping")
                         where
                         (string)mapping.Element("Ascii") == "0043" &&
                         (string)mapping.Element("Transform") == sTransform
                         select mapping.Element("Unicode").Value);
            }

            List <String> data = new List <string>();

            foreach (var item in query.Distinct())
            {
                data.Add(item);
            }
            return(data);
        }
コード例 #3
0
        /// <summary>
        /// Build a data table for all of an ASCII character's bestfit mappings.
        /// </summary>
        /// <param name="cAscii">The ASCII character to query on.</param>
        /// <param name="lTransformations">Reference to a List you want to populate with data.</param>
        /// <param name="sTransform">An optional charset to filter results by.</param>
        public void BuildTransformationsTable(char cAscii,
                                              ref List <UnicodeMapping> lTransformations,
                                              string sTransform = "")
        {
            UniChar uc = new UniChar();

            uc.CodePoint = uc.GetCodePoint(cAscii);
            IEnumerable <XElement> query;

            if (String.IsNullOrEmpty(sTransform))
            {
                query = from mapping in xDocUnicode.Descendants("Mapping")
                        where (string)mapping.Element("Ascii") == uc.CodePoint
                        select mapping;
            }
            else
            {
                query = (from mapping in XDocUnicode.Descendants("Mapping")
                         where (string)mapping.Element("Ascii") == uc.CodePoint &&
                         (string)mapping.Element("Transform") == sTransform
                         select mapping);
            }

            var count = query.Count();

            foreach (var item in query.Distinct())
            {
                UnicodeMapping um  = new UnicodeMapping();
                UniChar        uc2 = new UniChar();
                um.Ascii     = item.Element("Ascii").Value;
                um.Unicode   = item.Element("Unicode").Value;
                um.Character = uc2.ConvertCodePointToString(um.Unicode);
                um.Transform = item.Element("Transform").Value;
                um.Name      = item.Element("Name").Value;
                lTransformations.Add(um);
            }
        }