Beispiel #1
0
 private bool ThemVaoChu(KieuGo dnkg, int trungDau)
 {
     if (dnkg < KieuGo.khongDau || dnkg > KieuGo.nang)
     {
         this.mocCu = this.chu.moc;
         if (dnkg == KieuGo.DauMuChungChoAOE)
         {
             char[] c = new char[]
             {
                 'a',
                 'A',
                 'o',
                 'O',
                 'e',
                 'E'
             };
             if (this.chu.nguyenAm.IndexOfAny(c) < 0)
             {
                 return(false);
             }
             this.chu.moc = '^';
         }
         else if (dnkg == KieuGo.AThanh6)
         {
             char[] c2 = new char[]
             {
                 'a',
                 'A'
             };
             char[] c3 = new char[]
             {
                 'o',
                 'O',
                 'e',
                 'E'
             };
             if (this.chu.nguyenAm.IndexOfAny(c2) < 0 || this.chu.nguyenAm.IndexOfAny(c3) >= 0)
             {
                 return(false);
             }
             this.chu.moc = '^';
         }
         else if (dnkg == KieuGo.EThanh6)
         {
             char[] c4 = new char[]
             {
                 'E',
                 'e'
             };
             char[] c5 = new char[]
             {
                 'a',
                 'A',
                 'o',
                 'O'
             };
             if (this.chu.nguyenAm.IndexOfAny(c4) < 0 || this.chu.nguyenAm.IndexOfAny(c5) >= 0)
             {
                 return(false);
             }
             this.chu.moc = '^';
         }
         else if (dnkg == KieuGo.OThanh6)
         {
             char[] c6 = new char[]
             {
                 'O',
                 'o'
             };
             char[] c7 = new char[]
             {
                 'a',
                 'A',
                 'e',
                 'E'
             };
             if (this.chu.nguyenAm.IndexOfAny(c6) < 0 || this.chu.nguyenAm.IndexOfAny(c7) >= 0)
             {
                 return(false);
             }
             this.chu.moc = '^';
         }
         else if (dnkg == KieuGo.UThanh7OThanh7AThanh8 || dnkg == KieuGo.UOASimple)
         {
             char[] d = new char[]
             {
                 'a',
                 'A'
             };
             if (this.chu.nguyenAm.Length == 0 || this.chu.nguyenAm[0] == 'u' || this.chu.nguyenAm[0] == 'U' || (this.chu.nguyenAm.IndexOfAny(d) < 0 && this.chu.nguyenAm[0] == 'o') || this.chu.nguyenAm[0] == 'O')
             {
                 char[] c8 = new char[]
                 {
                     'u',
                     'o',
                     'U',
                     'O'
                 };
                 if (this.chu.nguyenAm.IndexOfAny(c8) < 0)
                 {
                     return(false);
                 }
                 if (this.chu.nguyenAm.Length == 1)
                 {
                     this.chu.UODau = true;
                 }
                 this.chu.moc = '*';
             }
             else
             {
                 if (this.chu.nguyenAm.IndexOfAny(d) < 0)
                 {
                     return(false);
                 }
                 this.chu.moc = '(';
             }
         }
         else if (dnkg == KieuGo.UThanh7OThanh7)
         {
             char[] c9 = new char[]
             {
                 'u',
                 'o',
                 'U',
                 'O'
             };
             if (this.chu.nguyenAm.IndexOfAny(c9) < 0)
             {
                 return(false);
             }
             if (this.chu.nguyenAm.Length == 1)
             {
                 this.chu.UODau = true;
             }
             this.chu.moc = '*';
         }
         else if (dnkg == KieuGo.AThanh8)
         {
             char[] c10 = new char[]
             {
                 'a',
                 'A'
             };
             if (this.chu.nguyenAm.IndexOfAny(c10) < 0)
             {
                 return(false);
             }
             this.chu.moc = '(';
         }
         if (this.chu.moc == '*' && this.mocCu == '*' && this.chu.UODau && this.chu.nguyenAm.Length == 2)
         {
             this.mocCu     = '-';
             this.chu.UODau = false;
         }
         if (this.chu.moc == this.mocCu)
         {
             this.chu.trungdau       = trungDau;
             this.chu.moc            = '-';
             this.chu.vitriThanhPhan = 2;
             if (this.mocCu == '*' && dnkg == KieuGo.UThanh7OThanh7AThanh8)
             {
                 if (this.chu.nguyenAm[0] == 'U')
                 {
                     this.chu.amCuoi = this.chu.amCuoi + this.kieuGo[10].ToString().ToUpper();
                 }
                 else
                 {
                     this.chu.amCuoi = this.chu.amCuoi + this.kieuGo[10].ToString().ToLower();
                 }
                 if (this.chu.UOA)
                 {
                     this.chu.nguyenAm = this.chu.nguyenAm.Substring(1);
                 }
             }
         }
         return(true);
     }
     this.KiemTraViTriDau();
     if (this.chu.vitriDau == -1 || this.chu.nguyenAm.Length == 0)
     {
         return(false);
     }
     if (this.chu.dau == (GoTiengViet.Dau)dnkg)
     {
         if (this.chu.dau == GoTiengViet.Dau.khongDau)
         {
             return(false);
         }
         this.chu.trungdau       = trungDau;
         this.chu.dau            = GoTiengViet.Dau.khongDau;
         this.chu.vitriThanhPhan = 2;
     }
     if (this.chu.trungdau == -1)
     {
         this.chu.dau = (GoTiengViet.Dau)dnkg;
     }
     return(true);
 }
Beispiel #2
0
 public string Convert(string nguon)
 {
     this.s = (this.value = "");
     this.chu.Reset();
     this.i = 0;
     while (this.i < nguon.Length)
     {
         if (this.chu.vitriThanhPhan == 0)
         {
             this.viTriDauMoc = this.TimKiemKieuGo(nguon[this.i]);
             if (this.viTriDauMoc == KieuGo.DThanhD)
             {
                 if (this.chu.amDau.ToLower() == "d")
                 {
                     this.chu.D9             = true;
                     this.chu.vitriThanhPhan = 1;
                 }
                 else
                 {
                     this.chu.amDau = this.chu.amDau + nguon[this.i];
                 }
             }
             else if (this.viTriDauMoc == KieuGo.UThanh7OThanh7AThanh8)
             {
                 this.chu.vitriThanhPhan = 1;
                 this.chu.moc            = '*';
                 if (nguon[this.i].ToString() == nguon[this.i].ToString().ToLower())
                 {
                     this.chu.nguyenAm = "u";
                 }
                 else
                 {
                     this.chu.nguyenAm = "U";
                 }
                 this.chu.UOA = true;
             }
             else if (this.KiemTraNguyenAm(nguon[this.i]))
             {
                 this.chu.vitriThanhPhan = 1;
                 this.chu.nguyenAm       = nguon[this.i].ToString();
             }
             else
             {
                 this.chu.amDau = this.chu.amDau + nguon[this.i];
             }
         }
         else if (this.chu.vitriThanhPhan == 1)
         {
             this.viTriDauMoc = this.TimKiemKieuGo(nguon[this.i]);
             if ((this.chu.nguyenAm.Length > 0 && this.KiemTraNguyenAm(nguon[this.i])) || (this.viTriDauMoc == KieuGo.UThanh7OThanh7AThanh8 && this.chu.nguyenAm.Length == 1))
             {
                 if ((this.chu.amDau == "g" || this.chu.amDau == "G") && (this.chu.nguyenAm[0] == 'i' || this.chu.nguyenAm[0] == 'I'))
                 {
                     this.chu.amDau    = this.chu.amDau + this.chu.nguyenAm[0];
                     this.chu.nguyenAm = this.chu.nguyenAm.Substring(1);
                 }
                 else if ((this.chu.amDau == "q" || this.chu.amDau == "Q") && (this.chu.nguyenAm[0] == 'u' || this.chu.nguyenAm[0] == 'U'))
                 {
                     this.chu.amDau    = this.chu.amDau + this.chu.nguyenAm[0];
                     this.chu.nguyenAm = this.chu.nguyenAm.Substring(1);
                 }
             }
             if (this.viTriDauMoc == KieuGo.UThanh7OThanh7AThanh8 && this.chu.nguyenAm.Length == 0)
             {
                 if (nguon[this.i].ToString() == nguon[this.i].ToString().ToLower())
                 {
                     this.chu.nguyenAm = "u";
                 }
                 else
                 {
                     this.chu.nguyenAm = "U";
                 }
                 this.chu.UOA = true;
             }
             if (this.viTriDauMoc >= KieuGo.khongDau && (this.TimKiemAmDau() || this.ktChinhTa != 2))
             {
                 if (this.viTriDauMoc == KieuGo.DThanhD)
                 {
                     if (this.chu.amDau == "d" || this.chu.amDau == "D")
                     {
                         if (this.chu.D9)
                         {
                             this.chu.D9             = false;
                             this.chu.trungdau       = this.i;
                             this.chu.vitriThanhPhan = 2;
                             this.chu.amCuoi         = nguon[this.i].ToString();
                         }
                         else
                         {
                             this.chu.D9 = true;
                         }
                     }
                     else
                     {
                         this.chu.vitriThanhPhan = 2;
                         this.chu.amCuoi         = this.chu.amCuoi + nguon[this.i];
                     }
                 }
                 else if (!this.ThemVaoChu(this.viTriDauMoc, this.i))
                 {
                     if (this.KiemTraNguyenAm(nguon[this.i]))
                     {
                         this.chu.nguyenAm = this.chu.nguyenAm + nguon[this.i];
                     }
                     else
                     {
                         this.chu.vitriThanhPhan = 2;
                         this.chu.amCuoi         = this.chu.amCuoi + nguon[this.i];
                     }
                 }
             }
             else if (this.KiemTraNguyenAm(nguon[this.i]))
             {
                 this.chu.nguyenAm = this.chu.nguyenAm + nguon[this.i];
             }
             else
             {
                 this.chu.vitriThanhPhan = 2;
                 this.chu.amCuoi         = this.chu.amCuoi + nguon[this.i];
             }
             if (this.chu.trungdau >= 0)
             {
                 this.chu.vitriThanhPhan = 2;
                 this.chu.amCuoi         = nguon[this.i].ToString();
             }
         }
         else if (this.chu.vitriThanhPhan == 2)
         {
             this.viTriDauMoc = this.TimKiemKieuGo(nguon[this.i]);
             if (this.viTriDauMoc >= KieuGo.khongDau && (this.TimKiemAmDau() || this.ktChinhTa == 0) && this.TimKiemPhuAmCuoi() && this.chu.trungdau == -1)
             {
                 if (this.viTriDauMoc == KieuGo.DThanhD)
                 {
                     if (this.chu.amDau == "d" || this.chu.amDau == "D")
                     {
                         if (this.chu.D9)
                         {
                             this.chu.D9             = false;
                             this.chu.trungdau       = this.i;
                             this.chu.vitriThanhPhan = 2;
                             this.chu.amCuoi         = this.chu.amCuoi + nguon[this.i];
                         }
                         else
                         {
                             this.chu.D9 = true;
                         }
                     }
                     else
                     {
                         this.chu.amCuoi = this.chu.amCuoi + nguon[this.i];
                     }
                 }
                 else if (!this.ThemVaoChu(this.viTriDauMoc, this.i) || this.chu.trungdau >= 0)
                 {
                     this.chu.amCuoi = this.chu.amCuoi + nguon[this.i];
                 }
             }
             else
             {
                 this.chu.amCuoi = this.chu.amCuoi + nguon[this.i];
             }
             if (this.ktChinhTa != 0 && this.chu.trungdau < 0 && this.chu.amCuoi.Length > 0 && this.KiemTraNguyenAm(this.chu.amCuoi[this.chu.amCuoi.Length - 1]))
             {
                 return(nguon);
             }
         }
         this.i++;
     }
     if (this.chu.D9)
     {
         if (this.chu.amDau == "D")
         {
             this.s = this.bangMa[145];
         }
         else
         {
             if (!(this.chu.amDau == "d"))
             {
                 return(nguon);
             }
             this.s = this.bangMa[72];
         }
     }
     else
     {
         this.s = this.chu.amDau;
     }
     this.value = this.ChuyenSangTiengViet();
     if (this.value != null)
     {
         return(this.s + this.value + this.chu.amCuoi);
     }
     if (this.chu.nguyenAm == "")
     {
         return(this.s + this.chu.amCuoi);
     }
     return(nguon);
 }