Represents a bestfit mapping between two characters.
Example #1
0
        /// <summary>
        /// Send me an ASCII character and I'll return you a list of Unicode characters that
        /// best fit map to it.  Since you're not telling me a specific charset your're
        /// interested in, I'm going to send you data for all of them.
        /// </summary>
        /// <param name="cAscii">The ASCII character to query on.</param>
        /// <param name="sCharset">An option charset name to filter by, valid values include:
        /// APL-ISO-IR-68
        /// CP424
        /// IBMGRAPH
        /// US-ASCII-QUOTES
        /// windows-1250
        /// windows-1251
        /// windows-1252
        /// windows-1253
        /// windows-1254
        /// windows-1255
        /// windows-1256
        /// windows-1257
        /// windows-1258
        /// windows-874
        /// CP864
        /// CP037
        /// CP1026
        /// CP500
        /// CP875
        /// DINGBATS
        /// KEYBOARD
        /// SYMBOL
        /// symbol
        /// zdingbat
        /// JAPANESE
        /// GSM0338
        /// </param>
        /// <returns></returns>
        public List <String> GetBestfitMappings(char cAscii, string sCharset = "")
        {
            BestFitMapping bm = new BestFitMapping();

            // If an invald charset was entered then set it to the wildcard
            if (!bm.charsets.Contains(sCharset))
            {
                sCharset = "";
            }
            UniChar uc = new UniChar();

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

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

            // else filter by the charset too
            else
            {
                query = (from mapping in XDocBestfit.Descendants("Mapping")
                         where
                         (string)mapping.Element("Ascii") == "0043" &&
                         (string)mapping.Element("Charset") == sCharset
                         select mapping.Element("Unicode").Value);
            }

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

            foreach (var item in query.Distinct())
            {
                data.Add(item);
            }
            return(data);
        }
Example #2
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="lBestFit">Reference to a List you want to populate with data.</param>
        /// <param name="sCharset">An optional charset to filter results by.
        /// </param>
        public void BuildBestfitTable(char cAscii,
                                      ref List <BestFitMapping> lBestFit,
                                      string sCharset = "")
        {
            UniChar uc = new UniChar();

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

            if (String.IsNullOrEmpty(sCharset))
            {
                query = from mapping in XDocBestfit.Descendants("Mapping")
                        where (string)mapping.Element("Ascii") == uc.CodePoint
                        select mapping;
            }
            else
            {
                query = (from mapping in XDocBestfit.Descendants("Mapping")
                         where (string)mapping.Element("Ascii") == uc.CodePoint &&
                         (string)mapping.Element("Charset") == sCharset
                         select mapping);
            }

            var count = query.Count();

            foreach (var item in query.Distinct())
            {
                BestFitMapping bf  = new BestFitMapping();
                UniChar        uc2 = new UniChar();
                bf.Ascii     = item.Element("Ascii").Value;
                bf.Unicode   = item.Element("Unicode").Value;
                bf.Character = uc2.ConvertCodePointToString(bf.Unicode);
                bf.Charset   = item.Element("Charset").Value;
                bf.Name      = item.Element("Name").Value;
                lBestFit.Add(bf);
            }
        }
Example #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="lBestFit">Reference to a List you want to populate with data.</param>
        /// <param name="sCharset">An optional charset to filter results by.
        /// </param>
        public void BuildBestfitTable(char cAscii, 
            ref List<BestFitMapping> lBestFit,
            string sCharset = "")
        {
            UniChar uc = new UniChar();
            uc.CodePoint = uc.GetCodePoint(cAscii);
            IEnumerable<XElement> query;

            if (String.IsNullOrEmpty(sCharset))
            {
                query = from mapping in XDocBestfit.Descendants("Mapping")
                        where (string)mapping.Element("Ascii") == uc.CodePoint
                        select mapping;
            }
            else
            {
                query = (from mapping in XDocBestfit.Descendants("Mapping")
                            where (string)mapping.Element("Ascii") == uc.CodePoint &&
                                  (string)mapping.Element("Charset") == sCharset
                            select mapping);
            }

            var count = query.Count();
            foreach (var item in query.Distinct())
            {
                BestFitMapping bf = new BestFitMapping();
                UniChar uc2 = new UniChar();
                bf.Ascii = item.Element("Ascii").Value;
                bf.Unicode = item.Element("Unicode").Value;
                bf.Character = uc2.ConvertCodePointToString(bf.Unicode);
                bf.Charset = item.Element("Charset").Value;
                bf.Name = item.Element("Name").Value;
                lBestFit.Add(bf);
            }
        }
Example #4
0
        /// <summary>
        /// Send me an ASCII character and I'll return you a list of Unicode characters that
        /// best fit map to it.  Since you're not telling me a specific charset your're
        /// interested in, I'm going to send you data for all of them.
        /// </summary>
        /// <param name="cAscii">The ASCII character to query on.</param>
        /// <param name="sCharset">An option charset name to filter by, valid values include:
        /// APL-ISO-IR-68
        /// CP424
        /// IBMGRAPH
        /// US-ASCII-QUOTES
        /// windows-1250
        /// windows-1251
        /// windows-1252
        /// windows-1253
        /// windows-1254
        /// windows-1255
        /// windows-1256
        /// windows-1257
        /// windows-1258
        /// windows-874
        /// CP864
        /// CP037
        /// CP1026
        /// CP500
        /// CP875
        /// DINGBATS
        /// KEYBOARD
        /// SYMBOL
        /// symbol
        /// zdingbat
        /// JAPANESE
        /// GSM0338
        /// </param>
        /// <returns></returns>
        public List<String> GetBestfitMappings(char cAscii, string sCharset = "")
        {
            BestFitMapping bm = new BestFitMapping();
            // If an invald charset was entered then set it to the wildcard
            if (!bm.charsets.Contains(sCharset))
            {
                sCharset = "";
            }
            UniChar uc = new UniChar();
            uc.CodePoint = uc.GetCodePoint(cAscii);
            IEnumerable<string> query;

            // If a charset wasn't specified, filter by the ASCII character
            if (String.IsNullOrEmpty(sCharset))
            {

                query = (from mapping in XDocBestfit.Descendants("Mapping")
                                       where
                                        (string)mapping.Element("Ascii") == uc.CodePoint
                                       select mapping.Element("Unicode").Value);
            }

            // else filter by the charset too
            else
            {

                query = (from mapping in XDocBestfit.Descendants("Mapping")
                                       where
                                           (string)mapping.Element("Ascii") == "0043" &&
                                           (string)mapping.Element("Charset") == sCharset
                                       select mapping.Element("Unicode").Value);
            }

            List<String> data = new List<string>();
            foreach (var item in query.Distinct())
            {
                data.Add(item);
            }
            return data;
        }