Exemple #1
0
        static void Main(string[] args)
        {
            var counter = (new LocaleCharCounter()).Counter;

            counter.SetRange(5, 12);
            CharCounter.PrintDict(counter.Count('e'));

            var counter2 = (new LocaleCharCounter(5, 12)).Counter;

            CharCounter.PrintDict(counter2.Count('e'));
            CharCounter.PrintDict(counter.SetRange(1, 3).Count('e'));
        }
        /// <summary>
        /// creater function to create CharCounter instance
        /// </summary>
        /// <param name="startNum"></param>
        /// <param name="endNum"></param>
        /// <param name="locale"></param>
        /// <returns></returns>
        private CharCounter createCounterByLocale(int?startNum, int?endNum, string locale)
        {
            bool        withRange   = startNum != null && endNum != null;
            CharCounter charCounter = withRange ?
                                      new EnglishCharCounter(startNum.Value, endNum.Value) :
                                      new EnglishCharCounter();

            switch (locale)
            {
            case "en":
                break;

            case "zh":
                charCounter = withRange ?
                              new ChineseCharCounter(startNum.Value, endNum.Value) :
                              new ChineseCharCounter();
                break;

            default:
                break;
            }
            return(charCounter);
        }
 public LocaleCharCounter(int?startNum, int?endNum, string locale)
 {
     this.counter = createCounterByLocale(startNum, endNum, locale);
 }