예제 #1
0
        internal bool ToHiragana(KakasiReader input, TextWriter output)
        {
            int ch = input.Get();

            if (!IsHiragana(ch))
            {
                return(false);
            }
            output.Write((char)ch);
            int length = 1;

            if (ch != WO)
            {
                for (; ; length++)
                {
                    ch = input.More();
                    if (ch == WO)
                    {
                        break;
                    }
                    if (!IsHiragana(ch))
                    {
                        break;
                    }
                    output.Write((char)ch);
                }
            }
            input.Consume(length);
            return(true);
        }
예제 #2
0
 internal bool ToHiragana(KakasiReader input, TextWriter output)
 {
     if (!IsKatakana(input.Get()))
     {
         return(false);
     }
     while (true)
     {
         int ch = input.Get();
         if ((ch >= '\u30a1' && ch <= '\u30f3') || ch == '\u30fd' || ch == '\u30fe')
         {
             // from small 'a' to 'n' and iteration marks
             input.Consume(1);
             output.Write((char)(ch - 0x60));
         }
         else if (ch == '\u30f4')        // 'vu'
         {
             input.Consume(1);
             output.Write('\u3046');
             output.Write('\u309b');
         }
         else if (IsKatakana(ch))
         {
             input.Consume(1);
             output.Write((char)ch);
         }
         else
         {
             break;
         }
     }
     return(true);
 }
예제 #3
0
        public bool ToKanji(KakasiReader input, TextWriter output)
        {
            char key = itaijiDictionary.Get((char)input.Get());

            SortedSet <KanjiYomi> .Enumerator iterator = kanwaDictionary.Lookup(key);
            string rest         = null;
            int    restLength   = 0;
            int    resultLength = 0;

            while (iterator.MoveNext())
            {
                KanjiYomi kanjiYomi = iterator.Current;
                int       length    = kanjiYomi.Length;
                if (rest == null)
                {
                    char[] chars = new char[length + 1];
                    restLength = input.More(chars);
                    for (int index = 0; index < restLength; index++)
                    {
                        chars[index] = itaijiDictionary.Get(chars[index]);
                    }
                    rest = new string(chars, 0, restLength);
                }
                if (length < resultLength)
                {
                    break;
                }
                if (length > restLength)
                {
                    continue;
                }
                if (kanjiYomi.GetYomiFor(rest) != null)
                {
                    resultLength = length;
                    break;
                }
            }
            if (resultLength > 0 && restLength > resultLength &&
                rest[resultLength - 1] == '\u3063')
            {
                char         nextCh = rest[resultLength];
                UnicodeBlock block  = UnicodeBlock.Of(nextCh);
                if (block.Equals(UnicodeBlock.Hiragana))
                {
                    ++resultLength;
                }
            }
            input.Consume(resultLength + 1);
            output.Write(key);
            if (resultLength > 0)
            {
                output.Write(rest.ToCharArray(), 0, resultLength);
            }
            return(true);
        }
예제 #4
0
        public bool Convert(KakasiReader input, TextWriter output)
        {
            bool ret = front.Convert(input, pipeOutput);

            if (ret)
            {
                while (pipeInput.Get() >= 0)
                {
                    if (!back.Convert(pipeInput, output))
                    {
                        output.Write((char)pipeInput.Get());
                        pipeInput.Consume(1);
                    }
                }
            }
            return(ret);
        }
예제 #5
0
        public bool Convert(KakasiReader input, TextWriter output)
        {
            int ch = input.Get();

            if (ch < 0)
            {
                return(false);
            }
            UnicodeBlock pblock = UnicodeBlock.Of((char)ch);

            while (true)
            {
                input.Consume(1);
                output.Write((char)ch);
                ch = input.Get();
                if (ch < 0)
                {
                    break;
                }
                UnicodeBlock block;
                switch (ch)
                {
                case '\u3005':      // kurikaesi
                case '\u3006':      // shime
                case '\u30f5':      // katakana small ka
                case '\u30f6':      // katakana small ke
                    block = UnicodeBlock.CJKUnifiedIdeographs;
                    break;

                default:
                    block = UnicodeBlock.Of((char)ch);
                    break;
                }
                if (!block.Equals(pblock))
                {
                    break;
                }
                //if (IsJapanese(block) != IsJapanese(pblock)) {
                //    break;
                //}
            }
            return(true);
        }
예제 #6
0
 private bool ToKatakana(KakasiReader input, TextWriter output, VbStrConv conv)
 {
     if (!IsHiragana(input.Get()))
     {
         return(false);
     }
     while (true)
     {
         int ch = input.Get();
         if (IsHiragana(ch))
         {
             input.Consume(1);
             foreach (char c in Strings.StrConv(((char)ch).ToString(), conv).ToCharArray())
             {
                 output.Write(c);
             }
         }
         else
         {
             break;
         }
     }
     return(true);
 }
예제 #7
0
 internal bool ToHalfKana(KakasiReader input, TextWriter output)
 {
     return(ToKatakana(input, output, VbStrConv.Katakana | VbStrConv.Narrow));
 }
예제 #8
0
 public bool Convert(KakasiReader i, TextWriter w) => _convert(i, w);
예제 #9
0
 public ConnectedWriter(KakasiReader kanjiInput)
 {
     _kanjiInput = kanjiInput;
 }
예제 #10
0
        internal bool ToHiragana(KakasiReader input, TextWriter output)
        {
            char key = itaijiDictionary.Get((char)input.Get());

            SortedSet <KanjiYomi> .Enumerator iterator = kanwaDictionary.Lookup(key);
            HashSet <string> yomiSet = new HashSet <string>();
            string           rest    = null;
            int restLength           = 0;
            int resultLength         = 0;

            while (iterator.MoveNext())
            {
                KanjiYomi kanjiYomi = iterator.Current;
                if (rest == null)
                {
                    char[] chars = new char[kanjiYomi.Length + 1];
                    restLength = input.More(chars);
                    for (int index = 0; index < restLength; index++)
                    {
                        chars[index] = itaijiDictionary.Get(chars[index]);
                    }
                    rest = new string(chars, 0, restLength);
                }
                Logger.Log("kanjiYomi: " + kanjiYomi.Kanji + "," + kanjiYomi.Yomi + "," + kanjiYomi.Okurigana + "," + kanjiYomi.Length + "," + restLength);
                if (kanjiYomi.Length < resultLength)
                {
                    break;
                }
                if (kanjiYomi.Length > restLength)
                {
                    continue;
                }
                string yomi = kanjiYomi.GetYomiFor(rest);
                if (yomi == null)
                {
                    continue;
                }
                yomiSet.Add(yomi);
                resultLength = kanjiYomi.Length;
                if (!HeikiMode)
                {
                    break;
                }
            }
            if (yomiSet.Count == 0)
            {
                return(false);
            }
            char additionalChar = (char)0;

            if (resultLength > 0 && restLength > resultLength &&
                rest[resultLength - 1] == '\u3063')
            {
                char         nextCh = rest[resultLength];
                UnicodeBlock block  = UnicodeBlock.Of(nextCh);
                if (block.Equals(UnicodeBlock.Hiragana))
                {
                    ++resultLength;
                    additionalChar = nextCh;
                }
            }
            input.Consume(resultLength + 1);
            if (FuriganaMode)
            {
                output.Write(key);
                if (resultLength > 0)
                {
                    output.Write(rest.ToCharArray(), 0, resultLength);
                }
                output.Write('[');
            }
            if (yomiSet.Count == 1)
            {
                output.Write(yomiSet.FirstOrDefault());
                if (additionalChar > 0)
                {
                    output.Write(additionalChar);
                }
            }
            else if (yomiSet.Count > 1)
            {
                HashSet <string> .Enumerator iter = yomiSet.GetEnumerator();
                output.Write('{');
                bool bar = false;
                while (iter.MoveNext())
                {
                    if (bar)
                    {
                        output.Write('|');
                    }
                    output.Write(iter.Current);
                    if (additionalChar > 0)
                    {
                        output.Write(additionalChar);
                    }
                    bar = true;
                }
                output.Write('}');
            }
            if (FuriganaMode)
            {
                output.Write(']');
            }
            return(true);
        }