PSeitz / wana_kana_rust

Utility library for checking and converting between Japanese characters - Hiragana, Katakana - and Romaji
MIT License
70 stars 14 forks source link

Accept char iterator as input #4

Open tmfink opened 4 years ago

tmfink commented 4 years ago

Work-in-progress to handle #3.

Please let me know your thoughts on this style. I just worked on katakana_to_hiragana(). Once we figure out how the best way to do this, I will work on the other modules.

Add iterator input APIs to

PSeitz commented 4 years ago

There is a place where the next char is peeked: https://github.com/PSeitz/wana_kana_rust/blob/c45ebcdf3e8acc6421e967e792374ac390947df8/src/to_hiragana.rs#L29-L31

So it would require a peekable iterator I think https://doc.rust-lang.org/std/iter/struct.Peekable.html

There may be other similar cases.

PSeitz commented 4 years ago

On second thought, we could always just use the minimal api instead of a uniform one, which would not require Peekable here. What do you think?

tmfink commented 4 years ago

On second thought, we could always just use the minimal api instead of a uniform one, which would not require Peekable here. What do you think?

@PSeitz What do you mean by minimal vs. uniform API?

In some cases, we can get away with avoiding the "direct indexing" approach. For katakana_iter_to_hiragana_with_opt(), I added a previous_char variable to track the previous character (instead of indexing into the previous index).

PSeitz commented 4 years ago

@PSeitz What do you mean by minimal vs. uniform API?

I mean defining a single iterator api which is used by all methods, vs minimal api everywhere.