Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        private static string GetFirstWadeGilesPinyinString(char ch)
        {
            string[] pinyinStrArray = PinyinHelper.ToWadeGilesPinyinStringArray(ch);

            if ((null != pinyinStrArray) && (pinyinStrArray.Length > 0))
            {
                return(pinyinStrArray[0]);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        public void testToWadeGilesPinyinStringArray()
        {
            // any input of non-Chinese characters will return null
            {
                Assert.IsNull(PinyinHelper.ToWadeGilesPinyinStringArray('A'));
                Assert.IsNull(PinyinHelper.ToWadeGilesPinyinStringArray('z'));
                Assert.IsNull(PinyinHelper.ToWadeGilesPinyinStringArray(','));
                Assert.IsNull(PinyinHelper.ToWadeGilesPinyinStringArray('。'));
            }

            // Chinese characters
            // single pronounciation
            {
                string[] expectedPinyinArray = new string[] { "li3" };
                string[] pinyinArray         = PinyinHelper.ToWadeGilesPinyinStringArray('李');

                Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length);

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }
            {
                string[] expectedPinyinArray = new string[] { "ch`iu2" };
                string[] pinyinArray         = PinyinHelper.ToWadeGilesPinyinStringArray('球');

                Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length);

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }
            {
                string[] expectedPinyinArray = new string[] { "chuang1" };
                string[] pinyinArray         = PinyinHelper.ToWadeGilesPinyinStringArray('桩');

                Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length);

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }

            // multiple pronounciations
            {
                string[] expectedPinyinArray = new string[] { "ch`uan2", "chuan4" };
                string[] pinyinArray         = PinyinHelper.ToWadeGilesPinyinStringArray('传');

                Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length);

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }

            {
                string[] expectedPinyinArray = new string[] { "lu:4", "lu4" };
                string[] pinyinArray         = PinyinHelper.ToWadeGilesPinyinStringArray('绿');

                Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length);

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }
        }