Iterate over grapheme clusters instead of chars
This commit is contained in:
parent
00be5d36c4
commit
5e06941c63
@ -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 }
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user