SetCondition() 공개 메소드

Sets the condition that must be met before the affix can be applied.
public SetCondition ( String condition, String pattern ) : void
condition String Condition to be met before affix application.
pattern String Condition as a regular expression pattern.
리턴 void
        /// <summary>
        ///   Parses a specific affix rule putting the result into the provided affix map.
        /// </summary>
        /// <param name="affixes">Map where the result of the parsing will be put.</param>
        /// <param name="header">Header line of the affix rule.</param>
        /// <param name="reader">TextReader to read the content of the rule from.</param>
        /// <param name="conditionPattern">Pattern to be used to generate the condition regex pattern.</param>
        private void ParseAffix(Dictionary<String, List<HunspellAffix>> affixes, String header, TextReader reader, String conditionPattern) {
            if (affixes == null) throw new ArgumentNullException("affixes");
            if (header == null) throw new ArgumentNullException("header");
            if (reader == null) throw new ArgumentNullException("reader");
            if (conditionPattern == null) throw new ArgumentNullException("conditionPattern");

            var args = Regex.Split(header, "\\s+");
            var crossProduct = args[2].Equals("Y");
            var numLines = Int32.Parse(args[3]);

            for (var i = 0; i < numLines; i++) {
                var line = reader.ReadLine();
                var ruleArgs = Regex.Split(line, "\\s+");

                var affix = new HunspellAffix();

                affix.Flag = _flagParsingStrategy.ParseFlag(ruleArgs[1]);
                affix.Strip = (ruleArgs[2] == "0") ? "" : ruleArgs[2];

                var affixArg = ruleArgs[3];

                var flagSep = affixArg.LastIndexOf('/');
                if (flagSep != -1) {
                    var cflag = affixArg.Substring(flagSep + 1);
                    var appendFlags = _alias.Count > 0 ? _alias[int.Parse(cflag) - 1] : _flagParsingStrategy.ParseFlags(cflag);
                    Array.Sort(appendFlags);
                    affix.AppendFlags = appendFlags;
                    affix.Append = affixArg.Substring(0, flagSep);
                } else {
                    affix.Append = affixArg;
                }

                var condition = ruleArgs[4];
                affix.SetCondition(condition, String.Format(conditionPattern, condition));
                affix.IsCrossProduct = crossProduct;

                List<HunspellAffix> list;
                if (!affixes.TryGetValue(affix.Append, out list))
                    affixes.Add(affix.Append, list = new List<HunspellAffix>());

                list.Add(affix);
            }
        }
        /// <summary>
        ///   Parses a specific affix rule putting the result into the provided affix map.
        /// </summary>
        /// <param name="affixes">Map where the result of the parsing will be put.</param>
        /// <param name="header">Header line of the affix rule.</param>
        /// <param name="reader">TextReader to read the content of the rule from.</param>
        /// <param name="conditionPattern">Pattern to be used to generate the condition regex pattern.</param>
        private void ParseAffix(Dictionary <String, List <HunspellAffix> > affixes, String header, TextReader reader, String conditionPattern)
        {
            if (affixes == null)
            {
                throw new ArgumentNullException("affixes");
            }
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (conditionPattern == null)
            {
                throw new ArgumentNullException("conditionPattern");
            }

            var args         = Regex.Split(header, "\\s+");
            var crossProduct = args[2].Equals("Y");
            var numLines     = Int32.Parse(args[3]);

            var hasAliases = _aliases.Count > 0;

            for (var i = 0; i < numLines; i++)
            {
                var line     = reader.ReadLine();
                var ruleArgs = Regex.Split(line, "\\s+");

                var affix = new HunspellAffix();

                affix.Flag  = _flagParsingStrategy.ParseFlag(ruleArgs[1]);
                affix.Strip = (ruleArgs[2] == "0") ? "" : ruleArgs[2];

                var affixArg = ruleArgs[3];

                var flagSep = affixArg.LastIndexOf('/');
                if (flagSep != -1)
                {
                    var cflag       = affixArg.Substring(flagSep + 1);
                    var appendFlags = hasAliases ? _aliases[cflag] : _flagParsingStrategy.ParseFlags(cflag);
                    Array.Sort(appendFlags);
                    affix.AppendFlags = appendFlags;
                    affix.Append      = affixArg.Substring(0, flagSep);
                }
                else
                {
                    affix.Append = affixArg;
                }

                var condition = ruleArgs[4];
                affix.SetCondition(condition, String.Format(conditionPattern, condition));
                affix.IsCrossProduct = crossProduct;

                List <HunspellAffix> list;
                if (!affixes.TryGetValue(affix.Append, out list))
                {
                    affixes.Add(affix.Append, list = new List <HunspellAffix>());
                }

                list.Add(affix);
            }
        }