Skip to content

Commit f1ae657

Browse files
committed
Allow building without depending on libstd
1 parent 7cb56f9 commit f1ae657

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
language: rust
2+
3+
script:
4+
- cargo build
5+
- cargo test
6+
- cargo test --no-default-features

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ build = "src/build.rs"
1212
regex = "1.0"
1313

1414
[dependencies]
15-
unicode-normalization = "0.1"
15+
unicode-normalization = { version = "0.1", optional = true }
16+
17+
[features]
18+
default = ["alloc", "normalization"]
19+
alloc = []
20+
normalization = ["unicode-normalization"]

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# rust-caseless
22

33
Unicode caseless matching
4+
5+
This crate can be used without libstd, when build without the default `alloc`
6+
and `normalization` features.

src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
#![cfg_attr(not(feature = "alloc"), no_std)]
2+
3+
#[cfg(feature = "normalization")]
14
use unicode_normalization::UnicodeNormalization;
25

6+
#[cfg(feature = "normalization")]
37
extern crate unicode_normalization;
48

59
include!(concat!(env!("OUT_DIR"), "/case_folding_data.rs"));
@@ -8,7 +12,9 @@ include!(concat!(env!("OUT_DIR"), "/case_folding_data.rs"));
812
pub trait Caseless {
913
fn default_case_fold(self) -> CaseFold<Self> where Self: Sized;
1014
fn default_caseless_match<J: Iterator<Item=char>>(self, other: J) -> bool;
15+
#[cfg(feature = "normalization")]
1116
fn canonical_caseless_match<J: Iterator<Item=char>>(self, other: J) -> bool;
17+
#[cfg(feature = "normalization")]
1218
fn compatibility_caseless_match<J: Iterator<Item=char>>(self, other: J) -> bool;
1319
}
1420

@@ -25,6 +31,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
2531
other.default_case_fold())
2632
}
2733

34+
#[cfg(feature = "normalization")]
2835
fn canonical_caseless_match<J: Iterator<Item=char>>(self, other: J) -> bool {
2936
// FIXME: Inner NFD can be optimized:
3037
// "Normalization is not required before case folding,
@@ -39,6 +46,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
3946
other.nfd().default_case_fold().nfd())
4047
}
4148

49+
#[cfg(feature = "normalization")]
4250
fn compatibility_caseless_match<J: Iterator<Item=char>>(self, other: J) -> bool {
4351
// FIXME: Unclear if the inner NFD can be optimized here like in canonical_caseless_match.
4452
iter_eq(self.nfd().default_case_fold().nfkd().default_case_fold().nfkd(),
@@ -47,6 +55,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
4755

4856
}
4957

58+
#[cfg(feature = "alloc")]
5059
pub fn default_case_fold_str(s: &str) -> String {
5160
s.chars().default_case_fold().collect()
5261
}
@@ -55,10 +64,12 @@ pub fn default_caseless_match_str(a: &str, b: &str) -> bool {
5564
a.chars().default_caseless_match(b.chars())
5665
}
5766

67+
#[cfg(feature = "normalization")]
5868
pub fn canonical_caseless_match_str(a: &str, b: &str) -> bool {
5969
a.chars().canonical_caseless_match(b.chars())
6070
}
6171

72+
#[cfg(feature = "normalization")]
6273
pub fn compatibility_caseless_match_str(a: &str, b: &str) -> bool {
6374
a.chars().compatibility_caseless_match(b.chars())
6475
}
@@ -116,9 +127,10 @@ impl<I> Iterator for CaseFold<I> where I: Iterator<Item = char> {
116127

117128
#[cfg(test)]
118129
mod tests {
119-
use super::default_case_fold_str;
130+
use super::*;
120131

121132
#[test]
133+
#[cfg(feature = "alloc")]
122134
fn test_strs() {
123135
assert_eq!(default_case_fold_str("Test Case"), "test case");
124136
assert_eq!(default_case_fold_str("Teſt Caſe"), "test case");

0 commit comments

Comments
 (0)