Skip to content

Commit

Permalink
On the fly conversion mode.
Browse files Browse the repository at this point in the history
Allows to convert romaji even when there's already kana symbols in
string.
  • Loading branch information
Xifax committed Sep 2, 2015
1 parent eee46c7 commit 408957d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion HiraKana/HiraKana.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace HiraKana
{
/* Conversion class */
class KanaTools
public class KanaTools
{
// Codes for kana symbols
private static readonly int UPPERCASE_START = 0x41;
Expand Down Expand Up @@ -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)
{
Expand Down
10 changes: 10 additions & 0 deletions HiraKana/ShortHand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Romaji
{
String romaji;
KanaTools tools;
Boolean ime = false;

/* Constructor and settings */
public Romaji(String romaji)
Expand All @@ -31,6 +32,7 @@ public Romaji(String romaji)
public Romaji useImeMode(Boolean mode)
{
tools.useIme(mode);
ime = true;
return this;
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 408957d

Please sign in to comment.