Skip to content

Commit

Permalink
update to Unicode 9 ; clean up no_std and related
Browse files Browse the repository at this point in the history
  • Loading branch information
kwantam committed Dec 23, 2016
1 parent c511c16 commit 96eaa4a
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 151 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ language: rust
rust: 'nightly'
sudo: false
script:
- cargo build --verbose --features no_std
- cargo test --verbose --features no_std
- cargo build --verbose --features bench
- cargo test --verbose --features bench
- cargo bench --verbose --features bench
- cargo clean
- cargo build --verbose --features default
- cargo test --verbose --features default
- cargo bench --verbose --features default
- cargo build --verbose
- cargo test --verbose
- rustdoc --test README.md -L target/debug -L target/debug/deps
- cargo doc
after_success: |
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "unicode-width"
version = "0.1.3"
version = "0.1.4"
authors = ["kwantam <[email protected]>"]

homepage = "https://github.com/unicode-rs/unicode-width"
Expand All @@ -20,3 +20,4 @@ exclude = [ "target/*", "Cargo.lock" ]
[features]
default = []
no_std = []
bench = []
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ fn main() {

## features

unicode-width supports a `no_std` feature. This eliminates dependence
on std, and instead uses equivalent functions from core.
unicode-width does not depend on libstd, so it can be used in crates
with the `#![no_std]` attribute.

## crates.io

Expand All @@ -35,5 +35,5 @@ to your `Cargo.toml`:

```toml
[dependencies]
unicode-width = "0.1.3"
unicode-width = "0.1.4"
```
7 changes: 0 additions & 7 deletions scripts/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,12 @@ def emit_table(f, name, t_data, t_type = "&'static [(char, char)]", is_pub=True,
def emit_charwidth_module(f, width_table):
f.write("pub mod charwidth {")
f.write("""
#[cfg(feature = "no_std")]
use core::option::Option::{self, Some, None};
#[cfg(feature = "no_std")]
use core::slice::SliceExt;
#[cfg(feature = "no_std")]
use core::result::Result::{Ok, Err};
#[inline]
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
#[cfg(feature = "no_std")]
use core::cmp::Ordering::{Equal, Less, Greater};
#[cfg(not(feature = "no_std"))]
use std::cmp::Ordering::{Equal, Less, Greater};
match r.binary_search_by(|&(lo, hi, _, _)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
Expand Down
15 changes: 5 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,27 @@
//!
//! ```toml
//! [dependencies]
//! unicode-width = "0.1.1"
//! unicode-width = "0.1.4"
//! ```
#![deny(missing_docs, unsafe_code)]
#![doc(html_logo_url = "https://unicode-rs.github.io/unicode-rs_sm.png",
html_favicon_url = "https://unicode-rs.github.io/unicode-rs_sm.png")]

#![cfg_attr(feature = "no_std", no_std)]
#![cfg_attr(feature = "no_std", feature(no_std, core_slice_ext, core_str_ext))]
#![cfg_attr(feature = "bench", feature(test))]
#![no_std]

#![cfg_attr(test, feature(test))]

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

#[cfg(test)]
#[cfg(feature = "bench")]
extern crate test;

use tables::charwidth as cw;
pub use tables::UNICODE_VERSION;

#[cfg(feature = "no_std")]
use core::ops::Add;
#[cfg(not(feature = "no_std"))]
use std::ops::Add;

mod tables;

Expand Down
275 changes: 152 additions & 123 deletions src/tables.rs

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[cfg(feature = "bench")]
use std::iter;
#[cfg(feature = "bench")]
use test::{self, Bencher};

#[cfg(feature = "bench")]
use super::UnicodeWidthChar;

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

#[cfg(feature = "bench")]
#[bench]
fn cargo(b: &mut Bencher) {
let string = iter::repeat('a').take(4096).collect::<String>();
Expand All @@ -27,6 +29,7 @@ fn cargo(b: &mut Bencher) {
});
}

#[cfg(feature = "bench")]
#[bench]
#[allow(deprecated)]
fn stdlib(b: &mut Bencher) {
Expand All @@ -39,6 +42,7 @@ fn stdlib(b: &mut Bencher) {
});
}

#[cfg(feature = "bench")]
#[bench]
fn simple_if(b: &mut Bencher) {
let string = iter::repeat('a').take(4096).collect::<String>();
Expand All @@ -50,6 +54,7 @@ fn simple_if(b: &mut Bencher) {
});
}

#[cfg(feature = "bench")]
#[bench]
fn simple_match(b: &mut Bencher) {
let string = iter::repeat('a').take(4096).collect::<String>();
Expand All @@ -61,6 +66,7 @@ fn simple_match(b: &mut Bencher) {
});
}

#[cfg(feature = "bench")]
#[inline]
fn simple_width_if(c: char) -> Option<usize> {
let cu = c as u32;
Expand All @@ -77,6 +83,7 @@ fn simple_width_if(c: char) -> Option<usize> {
}
}

#[cfg(feature = "bench")]
#[inline]
fn simple_width_match(c: char) -> Option<usize> {
match c as u32 {
Expand Down

0 comments on commit 96eaa4a

Please sign in to comment.