| 209 | } |
| 210 | |
| 211 | fn cmd_utf8_ranges(args: &Args) -> Result<()> { |
| 212 | use syntax::ParserBuilder; |
| 213 | use syntax::hir::{self, HirKind}; |
| 214 | use utf8_ranges::Utf8Sequences; |
| 215 | |
| 216 | let hir = ParserBuilder::new() |
| 217 | .build() |
| 218 | .parse(&format!("[{}]", args.arg_class))?; |
| 219 | let cls = match hir.into_kind() { |
| 220 | HirKind::Class(hir::Class::Unicode(cls)) => cls, |
| 221 | _ => return Err( |
| 222 | format!("unexpected HIR, expected Unicode class").into(), |
| 223 | ), |
| 224 | }; |
| 225 | let mut char_count = 0; |
| 226 | for (i, range) in cls.iter().enumerate() { |
| 227 | if i > 0 { |
| 228 | println!("----------------------------"); |
| 229 | } |
| 230 | char_count += (range.end() as u32) - (range.start() as u32) + 1; |
| 231 | for seq in Utf8Sequences::new(range.start(), range.end()) { |
| 232 | for utf8_range in seq.into_iter() { |
| 233 | print!("[{:02X}-{:02X}]", utf8_range.start, utf8_range.end); |
| 234 | } |
| 235 | println!(); |
| 236 | } |
| 237 | } |
| 238 | println!("codepoint count: {}", char_count); |
| 239 | Ok(()) |
| 240 | } |
| 241 | |
| 242 | impl Args { |
| 243 | fn parse_one(&self) -> Result<Hir> { |