Exemple #1
0
 public Grapheme(GraphemeType type, string letters, uint flags = default)
 {
     this.Type    = type;
     this.Letters = letters;
     this.Flags   = flags;
 }
Exemple #2
0
        //public Grapheme MergeWith(Grapheme other) => this.Type switch
        //{
        //    GraphemeType.Silent => new Grapheme(other.Type, this.Letters + other.Letters, other.Flags),
        //    GraphemeType.Mixed => new Grapheme(GraphemeType.Mixed, this.Letters + other.Letters, 0u),
        //    GraphemeType.Vowel => other.Type switch
        //    {
        //        GraphemeType.Silent => new Grapheme(GraphemeType.Vowel, this.Letters + other.Letters, this.Flags),
        //        GraphemeType.Mixed => new Grapheme(GraphemeType.Mixed, this.Letters + other.Letters, 0u),
        //        GraphemeType.Vowel => new Grapheme(GraphemeType.Vowel, this.Letters + other.Letters,
        //            (uint)MergeFlags((VowelFlag)this.Flags, (VowelFlag)other.Flags)),
        //        GraphemeType.Consonant => new Grapheme(GraphemeType.Mixed, this.Letters + other.Letters, 0u),
        //        _ => throw new Exception("Неверный тип")
        //    },
        //    GraphemeType.Consonant => other.Type switch
        //    {
        //        GraphemeType.Silent => new Grapheme(GraphemeType.Consonant, this.Letters + other.Letters, this.Flags),
        //        GraphemeType.Mixed => new Grapheme(GraphemeType.Mixed, this.Letters + other.Letters, 0u),
        //        GraphemeType.Vowel => new Grapheme(GraphemeType.Mixed, this.Letters + other.Letters, 0u),
        //        GraphemeType.Consonant => new Grapheme(GraphemeType.Consonant, this.Letters + other.Letters,
        //            (uint)MergeFlags((ConsonantFlag)this.Flags, (ConsonantFlag)other.Flags)),
        //        _ => throw new Exception("Неверный тип")
        //    },
        //    _ => throw new Exception("Неверный тип")
        //};

        public Grapheme MergeWith(Grapheme other)
        {
            this.Letters += other.Letters;

            switch (this.Type)
            {
            case GraphemeType.Silent:
                this.Type  = other.Type;
                this.Flags = other.Flags;
                break;

            case GraphemeType.Vowel:
                switch (other.Type)
                {
                case GraphemeType.Mixed:
                    this.Type  = GraphemeType.Mixed;
                    this.Flags = (uint)Grapheme.MergeFlags((CommonFlag)this.Flags,
                                                           (CommonFlag)other.Flags);
                    break;

                case GraphemeType.Vowel:
                    this.Flags = (uint)Grapheme.MergeFlags((VowelFlag)this.Flags,
                                                           (VowelFlag)other.Flags);
                    break;

                case GraphemeType.Consonant:
                    this.Type  = GraphemeType.Mixed;
                    this.Flags = 0;
                    break;
                }

                break;

            case GraphemeType.Consonant:
                switch (other.Type)
                {
                case GraphemeType.Mixed:
                    this.Type  = GraphemeType.Mixed;
                    this.Flags = (uint)Grapheme.MergeFlags((CommonFlag)this.Flags, (CommonFlag)other.Flags);
                    break;

                case GraphemeType.Vowel:
                    this.Type  = GraphemeType.Mixed;
                    this.Flags = 0;
                    break;

                case GraphemeType.Consonant:
                    this.Flags = (uint)Grapheme.MergeFlags((ConsonantFlag)this.Flags,
                                                           (ConsonantFlag)other.Flags);
                    break;
                }

                break;

            case GraphemeType.Mixed:
                this.Flags = (uint)Grapheme.MergeFlags((CommonFlag)this.Flags, (CommonFlag)other.Flags);
                break;
            }

            return(this);
        }