Skip to content

Commit

Permalink
Edition 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone authored and progval committed Mar 3, 2023
1 parent 7b34023 commit d500740
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 95 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]

name = "unicode_names2"
edition = "2018"
version = "0.6.0"
authors = ["Huon Wilson <dbau.pp@gmail.com>",
"Kang Seonghoon <public+rust@mearie.org>",
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Time and memory efficiently mapping characters to and from their
Unicode 8.0 names, at runtime and compile-time.

```rust
extern crate unicode_names2;

fn main() {
println!("☃ is called {}", unicode_names2::name('☃')); // SNOWMAN
println!("{} is happy", unicode_names2::character("white smiling face")); //
Expand Down
1 change: 0 additions & 1 deletion examples/count.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate unicode_names2;
use std::char;

// Count how many code points have names in the standard.
Expand Down
10 changes: 0 additions & 10 deletions generator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]

name = "unicode_names2_generator"
edition = "2018"
version = "0.0.1"
authors = ["Huon Wilson <dbau.pp@gmail.com>"]

Expand All @@ -12,4 +13,3 @@ time = "0.1.10"
log = "0"
getopts = "0.2.21"
rand = "0.8.5"
rand_xorshift = "0.3.0"
6 changes: 1 addition & 5 deletions generator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
extern crate log;
extern crate getopts;
extern crate rand;

use std::{cmp, char};
use std::collections::{HashMap, hash_map};
use std::fs::{File, self};
Expand All @@ -10,7 +6,7 @@ use std::io::prelude::*;
use std::iter::repeat;
use std::path::Path;

use formatting::Context;
use crate::formatting::Context;

macro_rules! w {
($ctxt: expr, $($tt: tt)*) => {
Expand Down
2 changes: 0 additions & 2 deletions generator/src/phf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//!
//! Strongly inspired by https://github.com/sfackler/rust-phf
extern crate time;

use rand::prelude::{Rng, SeedableRng, SliceRandom, StdRng};
use std::iter::repeat;

Expand Down
10 changes: 3 additions & 7 deletions src/iter_str.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#[cfg(feature = "no_std")]
use core::prelude::*;
use core::{fmt, slice};
use core::{slice, fmt};

use generated::{
LEXICON, LEXICON_OFFSETS, LEXICON_ORDERED_LENGTHS, LEXICON_SHORT_LENGTHS, PHRASEBOOK,
PHRASEBOOK_SHORT,
};
use crate::generated::{PHRASEBOOK_SHORT, PHRASEBOOK, LEXICON_SHORT_LENGTHS, LEXICON_ORDERED_LENGTHS,
LEXICON_OFFSETS, LEXICON};

#[derive(Clone)]
pub struct IterStr {
Expand Down
3 changes: 0 additions & 3 deletions src/jamo.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! Algorithmic mapping for hangul syllables.
#[cfg(feature = "no_std")]
use core::prelude::*;

// derived from Jamo.txt
pub static CHOSEONG: &'static [&'static str] = &[
"G", "GG", "N", "D", "DD", "R", "M", "B", "BB", "S", "SS", "", "J", "JJ", "C", "K", "T", "P",
Expand Down
72 changes: 13 additions & 59 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
//! name)`).
//!
//! ```rust
//! extern crate unicode_names2;
//!
//! fn main() {
//! println!("☃ is called {:?}", unicode_names2::name('☃')); // SNOWMAN
//! println!("{:?} is happy", unicode_names2::character("white smiling face")); // ☺
Expand Down Expand Up @@ -62,30 +60,15 @@
//! unicode_names2_macros = "0.2"
//! ```
#![cfg_attr(feature = "no_std", feature(no_std, core))]
#![cfg_attr(feature = "no_std", no_std)]
#![cfg_attr(test, feature(test))]
#![deny(missing_docs, unsafe_code)]

#[cfg(feature = "no_std")]
#[macro_use]
extern crate core;

#[cfg(all(test, feature = "no_std"))]
#[macro_use]
extern crate std;

#[cfg(test)]
extern crate rand;
#[cfg(test)]
extern crate test;

#[cfg(feature = "no_std")]
use core::prelude::*;

use core::char;
use core::fmt;

use core::{char, fmt};
use generated::{
MAX_NAME_LENGTH, PHRASEBOOK_OFFSETS1, PHRASEBOOK_OFFSETS2, PHRASEBOOK_OFFSET_SHIFT,
};
Expand Down Expand Up @@ -332,17 +315,14 @@ fn split(hash: u64) -> (u32, u32, u32) {
///
/// assert_eq!(unicode_names2::character("nonsense"), None);
/// ```
pub fn character(name: &str) -> Option<char> {
pub fn character(search_name: &str) -> Option<char> {
// + 1 so that we properly handle the case when `name` has a
// prefix of the longest name, but isn't exactly equal.
let mut buf = [0u8; MAX_NAME_LENGTH + 1];
for (place, byte) in buf.iter_mut().zip(name.bytes()) {
*place = ASCII_UPPER_MAP[byte as usize]
let mut buf = [0; MAX_NAME_LENGTH + 1];
for (place, byte) in buf.iter_mut().zip(search_name.bytes()) {
*place = byte.to_ascii_uppercase();
}
let search_name = match buf.get(..name.len()) {
None => return None,
Some(search_name) => search_name,
};
let search_name = buf.get(..search_name.len())?;

// try `HANGUL SYLLABLE <choseong><jungseong><jongseong>`
if search_name.starts_with(HANGUL_SYLLABLE_PREFIX.as_bytes()) {
Expand Down Expand Up @@ -408,7 +388,7 @@ pub fn character(name: &str) -> Option<char> {
// point (and invalid names map to anything), so we only need to
// check the name for this codepoint matches the input and we know
// everything. (i.e. no need for probing)
let maybe_name = match ::name(codepoint) {
let maybe_name = match name(codepoint) {
None => {
if true {
debug_assert!(false)
Expand All @@ -433,39 +413,19 @@ pub fn character(name: &str) -> Option<char> {
Some(codepoint)
}

// FIXME: use the stdlib one if/when std::ascii moves into `core` (or
// some such).
static ASCII_UPPER_MAP: [u8; 256] = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
b' ', b'!', b'"', b'#', b'$', b'%', b'&', b'\'', // " // syntax highlighting :/
b'(', b')', b'*', b'+', b',', b'-', b'.', b'/', b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7',
b'8', b'9', b':', b';', b'<', b'=', b'>', b'?', b'@', b'A', b'B', b'C', b'D', b'E', b'F', b'G',
b'H', b'I', b'J', b'K', b'L', b'M', b'N', b'O', b'P', b'Q', b'R', b'S', b'T', b'U', b'V', b'W',
b'X', b'Y', b'Z', b'[', b'\\', b']', b'^', b'_', b'`', b'A', b'B', b'C', b'D', b'E', b'F',
b'G', b'H', b'I', b'J', b'K', b'L', b'M', b'N', b'O', b'P', b'Q', b'R', b'S', b'T', b'U', b'V',
b'W', b'X', b'Y', b'Z', b'{', b'|', b'}', b'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86,
0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6,
0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
];

#[cfg(test)]
mod tests {
use super::*;
use std::prelude::v1::*;
use std::char;
use rand::{
distributions::{Distribution, Standard},
prelude::{SeedableRng, StdRng},
};
use std::char;
use std::prelude::v1::*;

use super::{character, generated, is_cjk_unified_ideograph, jamo, name};
use test::{self, Bencher};
extern crate test;

use test::bench::Bencher;

static DATA: &'static str =
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/data/UnicodeData.txt"));
Expand Down Expand Up @@ -535,7 +495,6 @@ mod tests {

#[test]
fn character_negative() {
use MAX_NAME_LENGTH;
let long_name = "x".repeat(100);
assert!(long_name.len() > MAX_NAME_LENGTH); // Otherwise this test is pointless
let names = ["", "x", "öäå", "SPAACE", &long_name];
Expand Down Expand Up @@ -704,8 +663,3 @@ mod tests {
mod std {
pub use core::{clone, fmt, marker};
}

#[cfg(not(feature = "no_std"))]
mod core {
pub use std::*;
}
3 changes: 1 addition & 2 deletions src/phf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate time;
use std::rand::{StdRng, Rng, mod};
use std::rand::{StdRng, Rng};
use std::collections::HashMap;
use std::hash::sip;

Expand Down
1 change: 1 addition & 0 deletions unicode_names2_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]

name = "unicode_names2_macros"
edition = "2018"
version = "0.6.0"
authors = ["Huon Wilson <dbau.pp@gmail.com>",
"Valentin Lorentz <progval+git@progval.net>"]
Expand Down
3 changes: 0 additions & 3 deletions unicode_names2_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
#![crate_type = "dylib"]

extern crate regex;

extern crate unicode_names2;

#[macro_use]
extern crate syn;
extern crate proc_macro;

struct CharByName(syn::LitChar);

Expand Down

0 comments on commit d500740

Please sign in to comment.