Ejemplo n.º 1
0
        protected override void AddParsers(ConfigDic configDic)
        {
            configDic.AddParser(str => (CheckState)Enum.Parse(typeof(CheckState), str));
            configDic.AddParser(str =>
            {
                var format   = Regex.Match(str, @"[^\s]+").Value;
                var strMatch = Regex.Match(Regex.Replace(str, @"[^\s]+\s(.*)", "$1"), @"([^\|]+)");
                var strs     = new List <string>();

                while (strMatch.Value != string.Empty)
                {
                    strs.Add(strMatch.Value);
                    strMatch = strMatch.NextMatch();
                }

                return(new LineSetting(format, strs.ToArray()));
            });
            configDic.AddParser(str =>
            {
                try
                {
                    return(Encoding.GetEncoding(str));
                }
                catch
                {
                    return(int.TryParse(str, out int codePage)
                        ? Encoding.GetEncoding(codePage)
                        : throw new InvalidCastException());
                }
            });

            configDic.AddParser(str =>
            {
                Match match = Regex.Match(str, @"\((?<X>-?\d+), (?<Y>-?\d+)\)");
                if (match.Success)
                {
                    return(new Point(int.Parse(match.Groups["X"].Value), int.Parse(match.Groups["Y"].Value)));
                }
                throw new InvalidCastException();
            });

            configDic.AddParser(str =>
            {
                Match match = Regex.Match(str, @"(?<X>\d+) \* (?<Y>\d+)");
                if (match.Success)
                {
                    return(new Size(int.Parse(match.Groups["X"].Value), int.Parse(match.Groups["Y"].Value)));
                }
                throw new InvalidCastException();
            });
        }
Ejemplo n.º 2
0
        public Setting(ConfigDic config)
        {
            Config = config;

            config.AddParser(str =>
            {
                try
                {
                    return(Encoding.GetEncoding(str));
                }
                catch
                {
                    int codePage;
                    if (int.TryParse(str, out codePage))
                    {
                        return(Encoding.GetEncoding(codePage));
                    }
                    else
                    {
                        throw new InvalidCastException();
                    }
                }
            });

            config.AddWriter <Encoding>(encoding => encoding.WebName.ToUpper());

            config.AddParser(str => (CheckState)Enum.Parse(typeof(CheckState), str));
            config.AddParser(str =>
            {
                var format         = Regex.Match(str, @"[^\s]+").Value;
                var strMatch       = Regex.Match(Regex.Replace(str, @"[^\s]+\s(.*)", "$1"), @"([^\|]+)");
                List <string> strs = new List <string>();
                while (strMatch.Value != string.Empty)
                {
                    strs.Add(strMatch.Value);
                    strMatch = strMatch.NextMatch();
                }
                return(new LineSetting(format, strs.ToArray()));
            });

            if (!config.HasKey(nameof(KoreanCB)))
            {
                KoreanCB = CheckState.Checked;
            }

            if (!config.HasKey(nameof(JapaneseCB)))
            {
                JapaneseCB = CheckState.Checked;
            }

            if (!config.HasKey(nameof(etcCB)))
            {
                etcCB = CheckState.Checked;
            }

            if (!config.HasKey(nameof(LineSetting)))
            {
                LineSetting = LineSetting.Default;
            }

            if (!config.HasKey(nameof(ReadEncoding)))
            {
                ReadEncoding = Encoding.UTF8;
            }

            if (!config.HasKey(nameof(IgnoreBlankERB)))
            {
                IgnoreBlankERB = true;
            }
        }