Commit 20cd9f2b authored by Wacton's avatar Wacton

TransliterationException thrown when non-kana character encountered

parent cd8dbeba
......@@ -59,6 +59,7 @@
<Compile Include="Kanas\Sokuon.cs" />
<Compile Include="Kanas\Syllabary.cs" />
<Compile Include="Kanas\Tokushuon.cs" />
<Compile Include="Romaji\TransliterationException.cs" />
<Compile Include="Romaji\Transliterator.cs" />
<Compile Include="Kanas\Youon.cs" />
<Compile Include="Names\EntryElement.cs" />
......
using System;
namespace Wacton.Desu.Romaji
{
public class TransliterationException : Exception
{
public TransliterationException(string message)
: base(message)
{
}
}
}
......@@ -59,13 +59,22 @@
}
this.punctuations.Add(' ', " ");
this.punctuations.Add(' ', " ");
this.punctuations.Add('・', "-");
this.punctuations.Add('、', ", ");
this.punctuations.Add('〜', "~");
}
/// <summary>
/// Returns the romaji transliteration of a string of kana characters. Throws a TransliterationException if the string contains a non-kana character.
/// </summary>
public string GetRomaji(string kanaCharacters)
{
if (string.IsNullOrEmpty(kanaCharacters))
{
return string.Empty;
}
var syllables = new List<string>();
var i = 0;
......@@ -84,7 +93,13 @@
var romaji = syllable.GetRomaji();
if (string.IsNullOrEmpty(romaji))
{
return null;
var currentCharacter = GetCharacter(kanaCharacters, i);
if (currentCharacter.HasValue)
{
throw new TransliterationException($"\"{currentCharacter}\" is not a recognised kana character");
}
throw new TransliterationException("Unknown error occurred during transliteration");
}
syllables.Add(romaji);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment