intl 0.3.1

Pure-Rust, no_std internationalization primitives (a pure-Rust ICU analog). The `unicode` module provides General_Category, character predicates, scripts, East Asian Width, numeric values, case mapping/folding, UAX #15 normalization (NFC/NFD/NFKC/NFKD), and UTS #10 collation — property tables compiled into const-fn match lookups, with feature-selectable codepoint ranges.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
//! Unicode Normalization Forms (UAX #15): NFD, NFC, NFKD, NFKC.
//!
//! Normalization is exposed as streaming iterator adaptors over
//! `Iterator<Item = char>`, so it works in `no_std` without allocation:
//!
//! ```
//! use intl::unicode::{nfc, nfd};
//!
//! // "e" + combining acute  ->  precomposed "é"
//! assert_eq!(nfc("e\u{0301}".chars()).collect::<String>(), "é");
//! // precomposed "é"  ->  "e" + combining acute
//! assert_eq!(nfd("é".chars()).collect::<String>(), "e\u{0301}");
//! ```
//!
//! Canonical reordering buffers one combining sequence at a time in a
//! fixed-size array. The bound ([`MAX_COMBINING`]) comfortably covers the
//! Stream-Safe Text Format limit (UAX #15); pathological input with a longer
//! run of combining marks is split at the bound (each part is still correctly
//! ordered internally).

use super::generated::normalization as gen;

/// Maximum number of entries buffered for one combining sequence. Exceeds the
/// Stream-Safe limit of 30 trailing non-starters.
pub const MAX_COMBINING: usize = 64;

/// Maximum length of a single codepoint's full (compatibility) decomposition.
const MAX_DECOMP: usize = 32;

// Hangul algorithmic composition/decomposition constants (UAX #15, §10.2).
const S_BASE: u32 = 0xAC00;
const L_BASE: u32 = 0x1100;
const V_BASE: u32 = 0x1161;
const T_BASE: u32 = 0x11A7;
const L_COUNT: u32 = 19;
const V_COUNT: u32 = 21;
const T_COUNT: u32 = 28;
const N_COUNT: u32 = V_COUNT * T_COUNT; // 588
const S_COUNT: u32 = L_COUNT * N_COUNT; // 11172

/// The Canonical_Combining_Class of `c`.
#[inline]
#[must_use]
pub const fn canonical_combining_class(c: char) -> u8 {
    gen::canonical_combining_class(c as u32)
}

/// The Canonical_Combining_Class of an arbitrary Unicode scalar value.
#[inline]
#[must_use]
pub const fn canonical_combining_class_u32(cp: u32) -> u8 {
    gen::canonical_combining_class(cp)
}

/// Compose a starter `a` with a following character `b`, if they form a
/// primary composite (canonical composition or Hangul).
fn compose(a: char, b: char) -> Option<char> {
    let (ua, ub) = (a as u32, b as u32);
    // Hangul L + V.
    if (L_BASE..L_BASE + L_COUNT).contains(&ua) && (V_BASE..V_BASE + V_COUNT).contains(&ub) {
        let li = ua - L_BASE;
        let vi = ub - V_BASE;
        return char::from_u32(S_BASE + (li * V_COUNT + vi) * T_COUNT);
    }
    // Hangul LV + T.
    if (S_BASE..S_BASE + S_COUNT).contains(&ua)
        && (ua - S_BASE) % T_COUNT == 0
        && (T_BASE + 1..T_BASE + T_COUNT).contains(&ub)
    {
        return char::from_u32(ua + (ub - T_BASE));
    }
    // Table-driven canonical composition.
    let pairs = gen::compose_pairs(ua)?;
    let mut i = 0;
    while i < pairs.len() {
        if pairs[i].0 == b {
            return Some(pairs[i].1);
        }
        i += 1;
    }
    None
}

/// Iterator yielding the NFD/NFKD form of an input char iterator.
///
/// `COMPAT == false` produces NFD (canonical), `true` produces NFKD
/// (compatibility). Constructed via [`nfd`] / [`nfkd`].
#[derive(Clone)]
pub struct Decompositions<I> {
    iter: I,
    compat: bool,
    // Decomposition of the current input char, drained one at a time.
    pend: [(u8, char); MAX_DECOMP],
    pend_len: u8,
    pend_pos: u8,
    // The current combining sequence (starter + trailing marks), sorted lazily.
    seq: [(u8, char); MAX_COMBINING],
    seq_len: usize,
    pos: usize,
    ready: usize,
    // A char pulled that begins the next sequence.
    carry: Option<(u8, char)>,
}

impl<I: Iterator<Item = char>> Decompositions<I> {
    fn new(iter: I, compat: bool) -> Self {
        Decompositions {
            iter,
            compat,
            pend: [(0, '\0'); MAX_DECOMP],
            pend_len: 0,
            pend_pos: 0,
            seq: [(0, '\0'); MAX_COMBINING],
            seq_len: 0,
            pos: 0,
            ready: 0,
            carry: None,
        }
    }

    /// Decompose one input char into `pend` (Hangul or table-driven; a char
    /// with no decomposition maps to itself).
    fn decompose_into(&mut self, ch: char) {
        self.pend_len = 0;
        self.pend_pos = 0;
        let u = ch as u32;
        if (S_BASE..S_BASE + S_COUNT).contains(&u) {
            let si = u - S_BASE;
            let l = L_BASE + si / N_COUNT;
            let v = V_BASE + (si % N_COUNT) / T_COUNT;
            let t = si % T_COUNT;
            self.push_pend(l);
            self.push_pend(v);
            if t != 0 {
                self.push_pend(T_BASE + t);
            }
            return;
        }
        let table = if self.compat {
            gen::decompose_compatible(u)
        } else {
            gen::decompose_canonical(u)
        };
        match table {
            Some(seq) => {
                let mut i = 0;
                while i < seq.len() {
                    self.push_pend(seq[i] as u32);
                    i += 1;
                }
            }
            None => self.push_pend(u),
        }
    }

    fn push_pend(&mut self, cp: u32) {
        let c = char::from_u32(cp).unwrap_or('\u{FFFD}');
        self.pend[self.pend_len as usize] = (gen::canonical_combining_class(cp), c);
        self.pend_len += 1;
    }

    /// Pull the next decomposed `(ccc, char)`.
    fn pull(&mut self) -> Option<(u8, char)> {
        loop {
            if self.pend_pos < self.pend_len {
                let r = self.pend[self.pend_pos as usize];
                self.pend_pos += 1;
                return Some(r);
            }
            let ch = self.iter.next()?;
            self.decompose_into(ch);
        }
    }

    /// Build and canonically order the next combining sequence. Returns `false`
    /// when the input is exhausted.
    fn build_sequence(&mut self) -> bool {
        self.seq_len = 0;
        if let Some(c) = self.carry.take() {
            self.seq[0] = c;
            self.seq_len = 1;
        }
        while let Some(c) = self.pull() {
            if c.0 == 0 {
                if self.seq_len == 0 {
                    self.seq[0] = c;
                    self.seq_len = 1;
                } else {
                    self.carry = Some(c);
                    break;
                }
            } else if self.seq_len < MAX_COMBINING {
                self.seq[self.seq_len] = c;
                self.seq_len += 1;
            } else {
                self.carry = Some(c);
                break;
            }
        }
        if self.seq_len == 0 {
            return false;
        }
        // Stable insertion sort of the trailing non-starter run by CCC.
        let start = if self.seq[0].0 == 0 { 1 } else { 0 };
        let mut i = start + 1;
        while i < self.seq_len {
            let mut j = i;
            while j > start && self.seq[j - 1].0 > self.seq[j].0 {
                self.seq.swap(j - 1, j);
                j -= 1;
            }
            i += 1;
        }
        self.pos = 0;
        self.ready = self.seq_len;
        true
    }
}

impl<I: Iterator<Item = char>> Iterator for Decompositions<I> {
    type Item = char;

    fn next(&mut self) -> Option<char> {
        loop {
            if self.pos < self.ready {
                let c = self.seq[self.pos].1;
                self.pos += 1;
                return Some(c);
            }
            if !self.build_sequence() {
                return None;
            }
        }
    }
}

#[derive(Clone, Copy, PartialEq)]
enum RecompState {
    Composing,
    Purging,
    Finished,
    // The ring filled mid-run: emit `composee` (if any) then drain the ring,
    // re-buffering the stashed `overflow` mark once a slot frees, so a
    // pathological run of >MAX_COMBINING blocked marks loses nothing.
    Overflow,
}

/// Iterator yielding the NFC/NFKC form of an input char iterator.
///
/// Composes the output of a [`Decompositions`] stream. Constructed via
/// [`nfc`] / [`nfkc`].
#[derive(Clone)]
pub struct Recompositions<I> {
    iter: Decompositions<I>,
    state: RecompState,
    // FIFO ring buffer of non-composed combining marks awaiting output.
    ring: [char; MAX_COMBINING],
    head: usize,
    len: usize,
    composee: Option<char>,
    last_ccc: Option<u8>,
    // A blocked combining mark that did not fit in `ring` (ring was full). It is
    // held here, not dropped, and pushed once the ring has drained one slot.
    // Within a single non-starter run the marks reaching the ring arrive in
    // non-decreasing CCC order (the decomposition stream pre-orders them), so
    // draining the front and appending this at the back preserves canonical
    // order, and no later mark can compose with `composee` across the boundary.
    overflow: Option<char>,
}

impl<I: Iterator<Item = char>> Recompositions<I> {
    fn new(iter: Decompositions<I>) -> Self {
        Recompositions {
            iter,
            state: RecompState::Composing,
            ring: ['\0'; MAX_COMBINING],
            head: 0,
            len: 0,
            composee: None,
            last_ccc: None,
            overflow: None,
        }
    }

    /// Append `c` to the FIFO ring of pending combining marks. Returns `false`
    /// if the ring is full (the caller must drain before retrying) so that no
    /// mark is ever silently dropped.
    #[must_use]
    fn push_back(&mut self, c: char) -> bool {
        if self.len < MAX_COMBINING {
            self.ring[(self.head + self.len) % MAX_COMBINING] = c;
            self.len += 1;
            true
        } else {
            false
        }
    }

    fn pop_front(&mut self) -> Option<char> {
        if self.len == 0 {
            return None;
        }
        let c = self.ring[self.head];
        self.head = (self.head + 1) % MAX_COMBINING;
        self.len -= 1;
        Some(c)
    }

    /// Buffer a blocked combining mark `ch` (CCC `ch_class`), tracking it as the
    /// new last non-starter. If the ring is full, stash `ch` in `overflow` and
    /// switch to the `Overflow` drain state instead of dropping it. Returns the
    /// first char to emit when an overflow drain is started (the held
    /// `composee`, or the oldest ring mark if there is no starter), else `None`.
    fn block(&mut self, ch: char, ch_class: u8) -> Option<char> {
        self.last_ccc = Some(ch_class);
        if self.push_back(ch) {
            return None;
        }
        // Ring full: begin draining. Emit the starter first (canonical order),
        // then the ring will be drained by the `Overflow` state. The starter is
        // leaving the composition window, so reset `last_ccc`: any later starter
        // begins a fresh window. (Within this run the decomposition stream
        // delivers marks in non-decreasing CCC order, so no already-passed mark
        // could still have composed with this starter.)
        self.overflow = Some(ch);
        self.state = RecompState::Overflow;
        self.last_ccc = None;
        if let Some(k) = self.composee.take() {
            return Some(k);
        }
        // No starter held (a run of marks with no leading starter): emit the
        // oldest ring mark to free a slot; the stashed mark is pushed in the
        // `Overflow` state once room exists.
        self.pop_front()
    }
}

impl<I: Iterator<Item = char>> Iterator for Recompositions<I> {
    type Item = char;

    fn next(&mut self) -> Option<char> {
        loop {
            match self.state {
                RecompState::Composing => {
                    while let Some(ch) = self.iter.next() {
                        let ch_class = gen::canonical_combining_class(ch as u32);
                        let k = match self.composee {
                            None => {
                                if ch_class != 0 {
                                    return Some(ch);
                                }
                                self.composee = Some(ch);
                                continue;
                            }
                            Some(k) => k,
                        };
                        match self.last_ccc {
                            None => match compose(k, ch) {
                                Some(r) => {
                                    self.composee = Some(r);
                                    continue;
                                }
                                None => {
                                    if ch_class == 0 {
                                        self.composee = Some(ch);
                                        return Some(k);
                                    }
                                    if let Some(out) = self.block(ch, ch_class) {
                                        return Some(out);
                                    }
                                }
                            },
                            Some(l_class) => {
                                if l_class >= ch_class {
                                    // `ch` is blocked from `composee`.
                                    if ch_class == 0 {
                                        self.composee = Some(ch);
                                        self.last_ccc = None;
                                        self.state = RecompState::Purging;
                                        return Some(k);
                                    }
                                    if let Some(out) = self.block(ch, ch_class) {
                                        return Some(out);
                                    }
                                } else {
                                    match compose(k, ch) {
                                        Some(r) => {
                                            self.composee = Some(r);
                                            continue;
                                        }
                                        None => {
                                            if let Some(out) = self.block(ch, ch_class) {
                                                return Some(out);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    self.state = RecompState::Finished;
                    if let Some(k) = self.composee.take() {
                        return Some(k);
                    }
                }
                RecompState::Purging => match self.pop_front() {
                    None => self.state = RecompState::Composing,
                    s => return s,
                },
                RecompState::Overflow => {
                    // Re-buffer the stashed mark once the ring has room; it
                    // arrived last in this non-decreasing-CCC run, so appending
                    // it at the tail keeps canonical order.
                    if self.overflow.is_some() && self.len < MAX_COMBINING {
                        let m = self.overflow.take().unwrap();
                        let _ = self.push_back(m);
                    }
                    match self.pop_front() {
                        // Ring drained and the stashed mark re-buffered: the run
                        // continues, so resume composing (composee already
                        // emitted; `last_ccc` still reflects the run).
                        None => self.state = RecompState::Composing,
                        s => return s,
                    }
                }
                RecompState::Finished => match self.pop_front() {
                    None => return self.composee.take(),
                    s => return s,
                },
            }
        }
    }
}

/// Canonical decomposition (NFD) of an input character stream.
#[inline]
pub fn nfd<I: Iterator<Item = char>>(iter: I) -> Decompositions<I> {
    Decompositions::new(iter, false)
}

/// Compatibility decomposition (NFKD) of an input character stream.
#[inline]
pub fn nfkd<I: Iterator<Item = char>>(iter: I) -> Decompositions<I> {
    Decompositions::new(iter, true)
}

/// Canonical composition (NFC) of an input character stream.
#[inline]
pub fn nfc<I: Iterator<Item = char>>(iter: I) -> Recompositions<I> {
    Recompositions::new(Decompositions::new(iter, false))
}

/// Compatibility composition (NFKC) of an input character stream.
#[inline]
pub fn nfkc<I: Iterator<Item = char>>(iter: I) -> Recompositions<I> {
    Recompositions::new(Decompositions::new(iter, true))
}

/// Result of a normalization quick check (UAX #15, §9).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IsNormalized {
    /// The text is definitely in the normalization form.
    Yes,
    /// The text is definitely not in the normalization form.
    No,
    /// The quick check is inconclusive; a full normalization is required to
    /// decide (only ever returned for the composed forms NFC/NFKC).
    Maybe,
}

/// Run the quick-check algorithm using the per-codepoint QC value
/// (0 = No, 1 = Maybe, 2 = Yes) returned by `qc`.
fn quick_check<I: Iterator<Item = char>>(iter: I, qc: fn(u32) -> u8) -> IsNormalized {
    let mut last_ccc = 0u8;
    let mut result = IsNormalized::Yes;
    for ch in iter {
        let c = gen::canonical_combining_class(ch as u32);
        if c != 0 && last_ccc > c {
            return IsNormalized::No; // canonical ordering violated
        }
        match qc(ch as u32) {
            0 => return IsNormalized::No,
            1 => result = IsNormalized::Maybe,
            _ => {}
        }
        last_ccc = c;
    }
    result
}

/// Quick-check whether a character stream is already in NFC.
#[inline]
pub fn quick_check_nfc<I: Iterator<Item = char>>(iter: I) -> IsNormalized {
    quick_check(iter, gen::nfc_qc)
}

/// Quick-check whether a character stream is already in NFD.
#[inline]
pub fn quick_check_nfd<I: Iterator<Item = char>>(iter: I) -> IsNormalized {
    quick_check(iter, gen::nfd_qc)
}

/// Quick-check whether a character stream is already in NFKC.
#[inline]
pub fn quick_check_nfkc<I: Iterator<Item = char>>(iter: I) -> IsNormalized {
    quick_check(iter, gen::nfkc_qc)
}

/// Quick-check whether a character stream is already in NFKD.
#[inline]
pub fn quick_check_nfkd<I: Iterator<Item = char>>(iter: I) -> IsNormalized {
    quick_check(iter, gen::nfkd_qc)
}

/// `true` if the stream is in NFC. A `Maybe` quick-check result is resolved by
/// comparing against the fully normalized form, so the input iterator must be
/// `Clone`.
#[inline]
pub fn is_nfc<I: Iterator<Item = char> + Clone>(iter: I) -> bool {
    match quick_check(iter.clone(), gen::nfc_qc) {
        IsNormalized::Yes => true,
        IsNormalized::No => false,
        IsNormalized::Maybe => iter.clone().eq(nfc(iter)),
    }
}

/// `true` if the stream is in NFD.
#[inline]
pub fn is_nfd<I: Iterator<Item = char> + Clone>(iter: I) -> bool {
    match quick_check(iter.clone(), gen::nfd_qc) {
        IsNormalized::Yes => true,
        IsNormalized::No => false,
        IsNormalized::Maybe => iter.clone().eq(nfd(iter)),
    }
}

/// `true` if the stream is in NFKC.
#[inline]
pub fn is_nfkc<I: Iterator<Item = char> + Clone>(iter: I) -> bool {
    match quick_check(iter.clone(), gen::nfkc_qc) {
        IsNormalized::Yes => true,
        IsNormalized::No => false,
        IsNormalized::Maybe => iter.clone().eq(nfkc(iter)),
    }
}

/// `true` if the stream is in NFKD.
#[inline]
pub fn is_nfkd<I: Iterator<Item = char> + Clone>(iter: I) -> bool {
    match quick_check(iter.clone(), gen::nfkd_qc) {
        IsNormalized::Yes => true,
        IsNormalized::No => false,
        IsNormalized::Maybe => iter.clone().eq(nfkd(iter)),
    }
}

#[cfg(all(test, feature = "alloc", feature = "bmp"))]
mod tests {
    use super::*;
    use alloc::string::String;
    use alloc::vec::Vec;

    /// Regression for the recomposition ring overflow: a starter followed by a
    /// run of *blocked* combining marks longer than `MAX_COMBINING` must NOT
    /// silently drop the overflow marks (a normalization-stability / security
    /// bug, since NFC underpins IDNA and identifier comparison). The run far
    /// exceeds the Stream-Safe limit (30), so conformant text is unaffected, but
    /// the output must still be correct NFC: all marks preserved, canonical
    /// order. Uses a CJK starter (no composition with combining marks) so every
    /// mark is blocked and reaches the ring.
    #[test]
    fn nfc_does_not_drop_marks_past_max_combining() {
        // `中` (U+4E2D) + 65 combining acute accents (CCC 230, all blocked).
        let mut input = String::from("\u{4E2D}");
        for _ in 0..65 {
            input.push('\u{0301}');
        }
        let out: Vec<char> = nfc(input.chars()).collect();

        // Nothing dropped: 1 starter + all 65 marks.
        assert_eq!(out.len(), 66, "overflow marks were dropped");
        assert_eq!(out[0], '\u{4E2D}');
        assert!(out[1..].iter().all(|&c| c == '\u{0301}'));
        assert_eq!(out[1..].len(), 65);

        // Idempotent and canonically ordered (equal CCC, so already ordered).
        let out2: Vec<char> = nfc(out.iter().copied()).collect();
        assert_eq!(out, out2);

        // NFKC must behave identically here (no compatibility decomposition).
        let outk: Vec<char> = nfkc(input.chars()).collect();
        assert_eq!(outk, out);

        // Also exercise the task's exact `a` + 65×acute case: the first acute
        // composes into `á`, the remaining 64 are blocked; nothing is dropped.
        let mut a_input = String::from("a");
        for _ in 0..65 {
            a_input.push('\u{0301}');
        }
        let a_out: Vec<char> = nfc(a_input.chars()).collect();
        assert_eq!(a_out[0], '\u{00E1}'); // á (a + first acute)
        assert_eq!(a_out[1..].iter().filter(|&&c| c == '\u{0301}').count(), 64);
        assert_eq!(a_out.len(), 65); // no marks lost
    }

    /// Overflow with mixed CCC marks that do not compose: the marks must come
    /// out in canonical (CCC-ascending) order with none lost. Uses 40 dot-below
    /// (CCC 220) followed by 40 acute (CCC 230) on a CJK starter, exceeding the
    /// ring.
    #[test]
    fn nfc_overflow_preserves_canonical_order() {
        let mut input = String::from("\u{4E2D}");
        for _ in 0..40 {
            input.push('\u{0323}'); // CCC 220
        }
        for _ in 0..40 {
            input.push('\u{0301}'); // CCC 230
        }
        let out: Vec<char> = nfc(input.chars()).collect();
        assert_eq!(out.len(), 81); // starter + 80 marks, none dropped

        // CCC is non-decreasing across the whole output (canonical order).
        let mut prev = 0u8;
        for &c in &out {
            let cc = canonical_combining_class(c);
            if cc != 0 {
                assert!(cc >= prev, "canonical order violated");
                prev = cc;
            }
        }
        // Counts preserved per mark.
        assert_eq!(out.iter().filter(|&&c| c == '\u{0323}').count(), 40);
        assert_eq!(out.iter().filter(|&&c| c == '\u{0301}').count(), 40);
    }
}