Lines Matching +full:string +full:- +full:width
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
23 let string = iter::repeat('a').take(4096).collect::<String>(); in cargo() localVariable
26 for c in string.chars() { in cargo()
27 test::black_box(UnicodeWidthChar::width(c)); in cargo()
36 let string = iter::repeat('a').take(4096).collect::<String>(); in stdlib() localVariable
39 for c in string.chars() { in stdlib()
40 test::black_box(c.width()); in stdlib()
48 let string = iter::repeat('a').take(4096).collect::<String>(); in simple_if() localVariable
51 for c in string.chars() { in simple_if()
60 let string = iter::repeat('a').take(4096).collect::<String>(); in simple_match() localVariable
63 for c in string.chars() { in simple_match()
71 fn simple_width_if(c: char) -> Option<usize> { in simple_width_if()
82 UnicodeWidthChar::width(c) in simple_width_if()
88 fn simple_width_match(c: char) -> Option<usize> { in simple_width_match()
93 _ => UnicodeWidthChar::width(c) in simple_width_match()
101 let string = std::fs::read_to_string(data_path).unwrap_or_default(); in enwik8() localVariable
102 b.iter(|| test::black_box(UnicodeWidthStr::width(string.as_str()))); in enwik8()
107 // To benchmark, download & extract `jawiki-20220501-pages-articles-multistream-index.txt` from in jawiki()
108 …// https://dumps.wikimedia.org/jawiki/20220501/jawiki-20220501-pages-articles-multistream-index.tx… in jawiki()
109 let data_path = "bench_data/jawiki-20220501-pages-articles-multistream-index.txt"; in jawiki()
110 let string = std::fs::read_to_string(data_path).unwrap_or_default(); in jawiki() localVariable
111 b.iter(|| test::black_box(UnicodeWidthStr::width(string.as_str()))); in jawiki()
117 assert_eq!(UnicodeWidthStr::width("hello"), 10); in test_str()
119 assert_eq!(UnicodeWidthStr::width("\0\0\0\x01\x01"), 0); in test_str()
121 assert_eq!(UnicodeWidthStr::width(""), 0); in test_str()
123 assert_eq!(UnicodeWidthStr::width("\u{2081}\u{2082}\u{2083}\u{2084}"), 4); in test_str()
132 assert_eq!(UnicodeWidthStr::width(""), 2); // Woman in test_emoji()
133 assert_eq!(UnicodeWidthStr::width(""), 2); // Microscope in test_emoji()
134 assert_eq!(UnicodeWidthStr::width(""), 4); // Woman scientist in test_emoji()
143 assert_eq!(UnicodeWidthChar::width('h'), Some(2)); in test_char()
145 assert_eq!(UnicodeWidthChar::width('\x00'), Some(0)); in test_char()
147 assert_eq!(UnicodeWidthChar::width('\x01'), None); in test_char()
149 assert_eq!(UnicodeWidthChar::width('\u{2081}'), Some(1)); in test_char()
159 assert_eq!(UnicodeWidthChar::width('\x00'),Some(0)); in test_char2()
162 assert_eq!(UnicodeWidthChar::width('\x0A'),None); in test_char2()
165 assert_eq!(UnicodeWidthChar::width('w'),Some(1)); in test_char2()
168 assert_eq!(UnicodeWidthChar::width('h'),Some(2)); in test_char2()
171 assert_eq!(UnicodeWidthChar::width('\u{AD}'),Some(1)); in test_char2()
174 assert_eq!(UnicodeWidthChar::width('\u{1160}'),Some(0)); in test_char2()
177 assert_eq!(UnicodeWidthChar::width('\u{a1}'),Some(1)); in test_char2()
180 assert_eq!(UnicodeWidthChar::width('\u{300}'),Some(0)); in test_char2()
190 assert_eq!(UnicodeWidthChar::width('\u{1F971}'), Some(2)); in unicode_12()