Skip to content

Commit 96eaa4a

Browse files
committed
update to Unicode 9 ; clean up no_std and related
1 parent c511c16 commit 96eaa4a

File tree

7 files changed

+176
-151
lines changed

7 files changed

+176
-151
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ language: rust
22
rust: 'nightly'
33
sudo: false
44
script:
5-
- cargo build --verbose --features no_std
6-
- cargo test --verbose --features no_std
5+
- cargo build --verbose --features bench
6+
- cargo test --verbose --features bench
7+
- cargo bench --verbose --features bench
78
- cargo clean
8-
- cargo build --verbose --features default
9-
- cargo test --verbose --features default
10-
- cargo bench --verbose --features default
9+
- cargo build --verbose
10+
- cargo test --verbose
1111
- rustdoc --test README.md -L target/debug -L target/debug/deps
1212
- cargo doc
1313
after_success: |

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "unicode-width"
4-
version = "0.1.3"
4+
version = "0.1.4"
55
authors = ["kwantam <kwantam@gmail.com>"]
66

77
homepage = "https://github.com/unicode-rs/unicode-width"
@@ -20,3 +20,4 @@ exclude = [ "target/*", "Cargo.lock" ]
2020
[features]
2121
default = []
2222
no_std = []
23+
bench = []

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ fn main() {
2525

2626
## features
2727

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

3131
## crates.io
3232

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

3636
```toml
3737
[dependencies]
38-
unicode-width = "0.1.3"
38+
unicode-width = "0.1.4"
3939
```

scripts/unicode.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,12 @@ def emit_table(f, name, t_data, t_type = "&'static [(char, char)]", is_pub=True,
199199
def emit_charwidth_module(f, width_table):
200200
f.write("pub mod charwidth {")
201201
f.write("""
202-
#[cfg(feature = "no_std")]
203202
use core::option::Option::{self, Some, None};
204-
#[cfg(feature = "no_std")]
205-
use core::slice::SliceExt;
206-
#[cfg(feature = "no_std")]
207203
use core::result::Result::{Ok, Err};
208204
209205
#[inline]
210206
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
211-
#[cfg(feature = "no_std")]
212207
use core::cmp::Ordering::{Equal, Less, Greater};
213-
#[cfg(not(feature = "no_std"))]
214-
use std::cmp::Ordering::{Equal, Less, Greater};
215208
match r.binary_search_by(|&(lo, hi, _, _)| {
216209
if lo <= c && c <= hi { Equal }
217210
else if hi < c { Less }

src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,27 @@
3939
//!
4040
//! ```toml
4141
//! [dependencies]
42-
//! unicode-width = "0.1.1"
42+
//! unicode-width = "0.1.4"
4343
//! ```
4444
4545
#![deny(missing_docs, unsafe_code)]
4646
#![doc(html_logo_url = "https://unicode-rs.github.io/unicode-rs_sm.png",
4747
html_favicon_url = "https://unicode-rs.github.io/unicode-rs_sm.png")]
4848

49-
#![cfg_attr(feature = "no_std", no_std)]
50-
#![cfg_attr(feature = "no_std", feature(no_std, core_slice_ext, core_str_ext))]
49+
#![cfg_attr(feature = "bench", feature(test))]
50+
#![no_std]
5151

52-
#![cfg_attr(test, feature(test))]
53-
54-
#[cfg(all(test, feature = "no_std"))]
52+
#[cfg(test)]
5553
#[macro_use]
5654
extern crate std;
5755

58-
#[cfg(test)]
56+
#[cfg(feature = "bench")]
5957
extern crate test;
6058

6159
use tables::charwidth as cw;
6260
pub use tables::UNICODE_VERSION;
6361

64-
#[cfg(feature = "no_std")]
6562
use core::ops::Add;
66-
#[cfg(not(feature = "no_std"))]
67-
use std::ops::Add;
6863

6964
mod tables;
7065

src/tables.rs

Lines changed: 152 additions & 123 deletions
Large diffs are not rendered by default.

src/tests.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[cfg(feature = "bench")]
1112
use std::iter;
13+
#[cfg(feature = "bench")]
1214
use test::{self, Bencher};
13-
15+
#[cfg(feature = "bench")]
1416
use super::UnicodeWidthChar;
1517

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

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

32+
#[cfg(feature = "bench")]
3033
#[bench]
3134
#[allow(deprecated)]
3235
fn stdlib(b: &mut Bencher) {
@@ -39,6 +42,7 @@ fn stdlib(b: &mut Bencher) {
3942
});
4043
}
4144

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

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

69+
#[cfg(feature = "bench")]
6470
#[inline]
6571
fn simple_width_if(c: char) -> Option<usize> {
6672
let cu = c as u32;
@@ -77,6 +83,7 @@ fn simple_width_if(c: char) -> Option<usize> {
7783
}
7884
}
7985

86+
#[cfg(feature = "bench")]
8087
#[inline]
8188
fn simple_width_match(c: char) -> Option<usize> {
8289
match c as u32 {

0 commit comments

Comments
 (0)