Skip to content

Commit

Permalink
[utf-16] Move iterator bounds to the TextSource trait
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkthame committed Oct 30, 2023
1 parent 52cc9ee commit ccda52f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
4 changes: 1 addition & 3 deletions src/explicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ pub fn compute<'a, T: TextSource<'a> + ?Sized>(
original_classes: &[BidiClass],
levels: &mut [Level],
processing_classes: &mut [BidiClass],
) where
<T as TextSource<'a>>::IndexLenIter: Iterator<Item = (usize, usize)>,
{
) {
assert_eq!(text.len(), original_classes.len());

// <http://www.unicode.org/reports/tr9/#X1>
Expand Down
10 changes: 2 additions & 8 deletions src/implicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ pub fn resolve_neutral<'a, D: BidiDataSource, T: TextSource<'a> + ?Sized>(
levels: &[Level],
original_classes: &[BidiClass],
processing_classes: &mut [BidiClass],
) where
<T as TextSource<'a>>::CharIndexIter: Iterator<Item = (usize, char)>,
<T as TextSource<'a>>::CharIter: Iterator<Item = char>,
{
) {
// e = embedding direction
let e: BidiClass = levels[sequence.runs[0].start].bidi_class();
let not_e = if e == BidiClass::L {
Expand Down Expand Up @@ -487,10 +484,7 @@ fn identify_bracket_pairs<'a, T: TextSource<'a> + ?Sized, D: BidiDataSource>(
data_source: &D,
run_sequence: &IsolatingRunSequence,
original_classes: &[BidiClass],
) -> Vec<BracketPair>
where
<T as TextSource<'a>>::CharIndexIter: Iterator<Item = (usize, char)>,
{
) -> Vec<BracketPair> {
let mut ret = vec![];
let mut stack = vec![];

Expand Down
21 changes: 6 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ use crate::BidiClass::*;
/// (For internal unicode-bidi use; API may be unstable.)
/// This trait is sealed and cannot be implemented for types outside this crate.
pub trait TextSource<'text>: private::Sealed {
type CharIter;
type CharIndexIter;
type IndexLenIter;
type CharIter: Iterator<Item = char>;
type CharIndexIter: Iterator<Item = (usize, char)>;
type IndexLenIter: Iterator<Item = (usize, usize)>;

/// Return the length of the text in code units.
#[doc(hidden)]
Expand Down Expand Up @@ -283,10 +283,7 @@ fn compute_initial_info<'a, D: BidiDataSource, T: TextSource<'a> + ?Sized>(
data_source: &D,
text: &'a T,
default_para_level: Option<Level>,
) -> (Vec<BidiClass>, Vec<ParagraphInfo>, Vec<bool>)
where
<T as TextSource<'a>>::CharIndexIter: Iterator<Item = (usize, char)>,
{
) -> (Vec<BidiClass>, Vec<ParagraphInfo>, Vec<bool>) {
let mut original_classes = Vec::with_capacity(text.len());

// The stack contains the starting code unit index for each nested isolate we're inside.
Expand Down Expand Up @@ -835,11 +832,7 @@ fn compute_bidi_info_for_para<'a, D: BidiDataSource, T: TextSource<'a> + ?Sized>
original_classes: &[BidiClass],
processing_classes: &mut [BidiClass],
levels: &mut Vec<Level>,
) where
<T as TextSource<'a>>::CharIndexIter: Iterator<Item = (usize, char)>,
<T as TextSource<'a>>::CharIter: Iterator<Item = char>,
<T as TextSource<'a>>::IndexLenIter: Iterator<Item = (usize, usize)>,
{
) {
let new_len = levels.len() + para.range.len();
levels.resize(new_len, para.level);
if para.level == LTR_LEVEL && is_pure_ltr {
Expand Down Expand Up @@ -886,9 +879,7 @@ fn reorder_levels<'a, T: TextSource<'a> + ?Sized>(
line_levels: &mut [Level],
line_text: &'a T,
para_level: Level,
) where
<T as TextSource<'a>>::CharIndexIter: Iterator<Item = (usize, char)>,
{
) {
// Reset some whitespace chars to paragraph level.
// <http://www.unicode.org/reports/tr9/#L1>
let mut reset_from: Option<usize> = Some(0);
Expand Down

0 comments on commit ccda52f

Please sign in to comment.