summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--src/eval/str.rs6
-rw-r--r--tests/typ/code/for.typ6
3 files changed, 8 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index c1841af9..c7fa703c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,6 +29,7 @@ rustybuzz = "0.4"
serde = { version = "1", features = ["derive", "rc"] }
ttf-parser = "0.12"
unicode-bidi = "0.3.5"
+unicode-segmentation = "1.8"
unicode-xid = "0.2"
xi-unicode = "0.3"
anyhow = { version = "1", optional = true }
diff --git a/src/eval/str.rs b/src/eval/str.rs
index 59e0887a..800d1709 100644
--- a/src/eval/str.rs
+++ b/src/eval/str.rs
@@ -3,6 +3,8 @@ use std::convert::TryFrom;
use std::fmt::{self, Debug, Formatter, Write};
use std::ops::{Add, AddAssign, Deref};
+use unicode_segmentation::UnicodeSegmentation;
+
use crate::diag::StrResult;
use crate::util::EcoString;
@@ -41,9 +43,9 @@ impl Str {
self.0.as_str()
}
- /// Return an iterator over the chars as strings.
+ /// Return an iterator over the grapheme clusters as strings.
pub fn iter(&self) -> impl Iterator<Item = Str> + '_ {
- self.chars().map(Into::into)
+ self.graphemes(true).map(Into::into)
}
/// Repeat this string `n` times.
diff --git a/tests/typ/code/for.typ b/tests/typ/code/for.typ
index 63dab9b8..2569f5a7 100644
--- a/tests/typ/code/for.typ
+++ b/tests/typ/code/for.typ
@@ -58,15 +58,15 @@
#test(out, (1, 2, 3, 4, 5, "a", 6, "b", 7))
-// Chars of string.
+// Grapheme clusters of string.
#let first = true
-#let joined = for c in "abc" {
+#let joined = for c in "abc👩‍👩‍👦‍👦" {
if not first { ", " }
first = false
c
}
-#test(joined, "a, b, c")
+#test(joined, "a, b, c, 👩‍👩‍👦‍👦")
// Return value.
#test(for v in "" [], none)