Ejemplo n.º 1
0
        public string Transliterate(string source)
        {
            var weaver = new StringWeaver(source, 1);

            while (weaver.Slider.MoveNext())
            {
                if (Iso9Ruleset.HasRule(weaver.Slider.Current))
                {
                    var target = weaver.Slider.Char3AtCurrent;
                    foreach (var iso9Rule in Iso9Ruleset.RulesFor(weaver.Slider.Current))
                    {
                        if (iso9Rule.From.IsMatch(target))
                        {
                            weaver.Slider.MoveNext(iso9Rule.From.Lenth - 1);

                            if (iso9Rule.Alternative.Lenth == 0 ||
                                iso9Rule.IsCharacterWithDescender && _options.DescenderMapping == Iso9DescenderMapping.CommaBelow ||
                                iso9Rule.IsCharacterWithUmlautAndMacron && _options.UmlautAndMacronMapping == Iso9UmlautAndMacronMapping.DiaresisAndDotBelow)
                            {
                                if (iso9Rule.To.C0 != '\0')
                                {
                                    weaver.Append(iso9Rule.To.C0);
                                }
                                if (iso9Rule.To.C1 != '\0')
                                {
                                    weaver.Append(iso9Rule.To.C1);
                                }
                                if (iso9Rule.To.C2 != '\0')
                                {
                                    weaver.Append(iso9Rule.To.C2);
                                }
                            }
                            else
                            {
                                if (iso9Rule.Alternative.C0 != '\0')
                                {
                                    weaver.Append(iso9Rule.Alternative.C0);
                                }
                                if (iso9Rule.Alternative.C1 != '\0')
                                {
                                    weaver.Append(iso9Rule.Alternative.C1);
                                }
                                if (iso9Rule.Alternative.C2 != '\0')
                                {
                                    weaver.Append(iso9Rule.Alternative.C2);
                                }
                            }

                            break;
                        }
                    }
                }
                else
                {
                    weaver.Append(weaver.Slider.Current);
                }
            }

            return(weaver.Weave());
        }
Ejemplo n.º 2
0
        public string Translit(string original)
        {
            if (original == null)
            {
                return(string.Empty);
            }
            var weaver = new StringWeaver(original, 1.0);

            while (weaver.Slider.MoveNext())
            {
                var from = weaver.Slider.Current;
                var to   = from;
                weaver.Append(to);
            }
            weaver.Append(weaver.Current);

            return(weaver.Weave());
        }