File: count.rs

package info (click to toggle)
rust-unicode-names2 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,140 kB
  • sloc: python: 192; makefile: 5
file content (22 lines) | stat: -rw-r--r-- 730 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
extern crate unicode_names2;
use std::char;

// Count how many code points have names in the standard.
//
// This does a full naive scan of all valid codepoints, and still only
// takes milliseconds to complete. Specifically, with optimisations,
// it takes about 14ms to run, meaning ~12ns per look-up (only 2048
// out of 1114111 fail the from_u32 check).
//
// NB. this is not actually doing any work to compute the name, just
// checking it exists, which is why it can be so efficient.

fn main() {
    let number = (0u32..0x10FFFF)
        .filter(|x| {
            char::from_u32(*x).map_or(false, |c| unicode_names2::name(c).is_some())
        })
        .count();

    println!("there are {} named code points", number)
}