From 408957d582493c18ac8e3d004c6bbc4d11b7a1a1 Mon Sep 17 00:00:00 2001 From: Artiom Basenko Date: Wed, 2 Sep 2015 21:34:35 +0300 Subject: [PATCH] On the fly conversion mode. Allows to convert romaji even when there's already kana symbols in string. --- HiraKana/HiraKana.cs | 13 ++++++++++++- HiraKana/ShortHand.cs | 10 ++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/HiraKana/HiraKana.cs b/HiraKana/HiraKana.cs index 33df5d3..abc4fea 100644 --- a/HiraKana/HiraKana.cs +++ b/HiraKana/HiraKana.cs @@ -5,7 +5,7 @@ namespace HiraKana { /* Conversion class */ - class KanaTools + public class KanaTools { // Codes for kana symbols private static readonly int UPPERCASE_START = 0x41; @@ -36,6 +36,17 @@ public KanaTools useObsoleteKana(Boolean flag) } /* Public API */ + public String onTheFlyToKana(String input, Boolean hiragana = true, Boolean katakana = false) + { + String result = romajiToHiragana(input); + + if(katakana) + { + return hiraganaToKatakana(result); + } + + return result; + } public String toHiragana(String input) { diff --git a/HiraKana/ShortHand.cs b/HiraKana/ShortHand.cs index 7fd0e88..2e38640 100644 --- a/HiraKana/ShortHand.cs +++ b/HiraKana/ShortHand.cs @@ -20,6 +20,7 @@ public class Romaji { String romaji; KanaTools tools; + Boolean ime = false; /* Constructor and settings */ public Romaji(String romaji) @@ -31,6 +32,7 @@ public Romaji(String romaji) public Romaji useImeMode(Boolean mode) { tools.useIme(mode); + ime = true; return this; } @@ -43,11 +45,19 @@ public Romaji useObsoleteKana(Boolean mode) /* Conversions */ public String ToHiragana() { + if(ime) + { + return tools.onTheFlyToKana(romaji, hiragana:true); + } return tools.toHiragana(romaji); } public String ToKatakana() { + if(ime) + { + return tools.onTheFlyToKana(romaji, katakana:true); + } return tools.toKatakana(romaji); }