aboutsummaryrefslogtreecommitdiff
path: root/src/passwordmaker/grapheme.rs
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2022-10-09 00:06:35 +0200
committerAndreas Grois <andi@grois.info>2022-10-09 00:06:35 +0200
commit5e51b706d54a26470f33d1342f4666d5aab921fc (patch)
tree97307b8419b6572dcffc2842ef1474b4aa89f397 /src/passwordmaker/grapheme.rs
Initial Commit: PasswordMaker itself.
It's compiling, and the public interface is semi-OK now. The internals are still a bit gory, but they'll likely see an iteartion later on anyhow.
Diffstat (limited to 'src/passwordmaker/grapheme.rs')
-rw-r--r--src/passwordmaker/grapheme.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/passwordmaker/grapheme.rs b/src/passwordmaker/grapheme.rs
new file mode 100644
index 0000000..ee10146
--- /dev/null
+++ b/src/passwordmaker/grapheme.rs
@@ -0,0 +1,11 @@
+use unicode_segmentation::UnicodeSegmentation;
+#[derive(Clone)]
+pub(super) struct Grapheme<'a>(&'a str);
+
+impl<'a> Grapheme<'a> {
+ pub(super) fn iter_from_str(string : &'a str) -> impl Iterator<Item=Grapheme<'a>> {
+ string.graphemes(true).map(Self::extract_grapheme_unchecked)
+ }
+ pub(super) fn get<'b>(&'b self) -> &'a str { self.0 }
+ fn extract_grapheme_unchecked(s : &str) -> Grapheme { Grapheme(s) }
+} \ No newline at end of file