attr: valid, ret byte len not char count
This commit is contained in:
parent
599b712f36
commit
d43d6c908f
1 changed files with 7 additions and 1 deletions
|
@ -14,7 +14,7 @@ pub fn valid<I: Iterator<Item = char>>(chars: I) -> usize {
|
||||||
let mut n = 0;
|
let mut n = 0;
|
||||||
let mut state = Start;
|
let mut state = Start;
|
||||||
for c in chars {
|
for c in chars {
|
||||||
n += 1;
|
n += c.len_utf8();
|
||||||
state = state.step(c);
|
state = state.step(c);
|
||||||
match state {
|
match state {
|
||||||
Done | Invalid => break,
|
Done | Invalid => break,
|
||||||
|
@ -520,6 +520,12 @@ mod test {
|
||||||
assert_eq!(super::valid(src.chars()), src.len());
|
assert_eq!(super::valid(src.chars()), src.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn valid_unicode() {
|
||||||
|
let src = r#"{a="б"}"#;
|
||||||
|
assert_eq!(super::valid(src.chars()), src.len());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valid_empty() {
|
fn valid_empty() {
|
||||||
let src = "{}";
|
let src = "{}";
|
||||||
|
|
Loading…
Reference in a new issue