Exemple #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the valid characters from the specified language definition into a new
        /// instance of the <see cref="ValidCharacters"/> class.
        /// </summary>
        /// <returns>A <see cref="ValidCharacters"/> initialized with the valid characters data
        /// from the language definition.</returns>
        /// ------------------------------------------------------------------------------------
        public static ValidCharacters Load(CoreWritingSystemDefinition ws)
        {
            var validChars = new ValidCharacters();

            validChars.AddCharactersFromWritingSystem(ws, "main", ValidCharacterType.WordForming);
            validChars.AddCharactersFromWritingSystem(ws, "punctuation", ValidCharacterType.Other);

            validChars.InitSortComparer(ws);

            return(validChars);
        }
Exemple #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the valid characters from the specified language definition into a new
        /// instance of the <see cref="ValidCharacters"/> class.
        /// </summary>
        /// <param name="ws">The writing system.</param>
        /// <param name="exceptionHandler">The exception handler to use if valid character data
        /// cannot be loaded.</param>
        /// <returns>A <see cref="ValidCharacters"/> initialized with the valid characters data
        /// from the language definition.</returns>
        /// ------------------------------------------------------------------------------------
        public static ValidCharacters Load(CoreWritingSystemDefinition ws, LoadExceptionDelegate exceptionHandler = null)
        {
            var validChars = new ValidCharacters();

            validChars.LoadException += exceptionHandler;

            var invalidChars = new List <string>();

            validChars.AddCharactersFromWritingSystem(ws, "main", ValidCharacterType.WordForming, invalidChars);
            validChars.AddCharactersFromWritingSystem(ws, "numeric", ValidCharacterType.Numeric, invalidChars);
            validChars.AddCharactersFromWritingSystem(ws, "punctuation", ValidCharacterType.Other, invalidChars);

            if (invalidChars.Count > 0)
            {
                var bldr = new StringBuilder();
                bldr.AppendFormat("Invalid ValidChars field while loading the {0} writing system. The following characters are invalid:",
                                  ws.DisplayLabel);
                foreach (string chr in invalidChars)
                {
                    bldr.Append(Environment.NewLine);
                    bldr.Append("\t");
                    bldr.AppendFormat("{0} (U+{1:X4}", chr, (int)chr[0]);
                    for (int ich = 1; ich < chr.Length; ich++)
                    {
                        bldr.AppendFormat(", U+{0:X4}", (int)chr[ich]);
                    }
                    bldr.Append(")");
                }
                validChars.ReportError(new ArgumentException(bldr.ToString(), "ws"));
            }

            if (invalidChars.Count > 0 && validChars.m_wordFormingCharacters.Count == 0)
            {
                validChars.m_wordFormingCharacters.AddRange(DefaultWordformingChars);
                validChars.Sort(validChars.m_wordFormingCharacters);
            }

            validChars.InitSortComparer(ws);

            return(validChars);
        }