public static string ToRomaji(string input, bool upcaseKatakana, Trie <char, string> customRomajiMapping) { if (string.IsNullOrEmpty(input)) { return(string.Empty); } var romajiTree = Trie <char, string> .Merge(HepburnTree, customRomajiMapping ?? Trie <char, string> .Empty, (a, b) => b.Value); var builder = new StringBuilder(); int position = 0; do { var pair = Convert(romajiTree, input, position); var uppercase = upcaseKatakana && WanaKana.IsKatakana(input.Substring(position, pair.Position - position)); builder.Append(uppercase ? pair.Token.ToUpper() : pair.Token); position = pair.Position; } while(position < input.Length); return(builder.ToString()); }
public static String Convert(String input, Boolean upcaseKatakana, Trie <Char, String> customRomajiMapping) { if (String.IsNullOrEmpty(input)) { return(""); } var romajiTree = (customRomajiMapping == null) ? HepburnTree : customRomajiMapping; var builder = new StringBuilder(); Int32 position = 0; do { var pair = Convert(romajiTree, input, position); var uppercase = upcaseKatakana && WanaKana.IsKatakana(input.Substring(position, pair.Position - position)); builder.Append(uppercase ? pair.Token.ToUpper() : pair.Token); position = pair.Position; } while (position < input.Length); return(builder.ToString()); }