mirror of
https://github.com/openharmony/third_party_rust_unicode-normalization.git
synced 2026-06-30 21:38:03 -04:00
Add no_std + alloc support
This commit is contained in:
@@ -7,9 +7,11 @@ sudo: false
|
||||
script:
|
||||
- cargo build --verbose
|
||||
- cargo test --verbose
|
||||
- cargo test --verbose --no-default-features
|
||||
- cargo package
|
||||
- cd target/package/unicode-normalization-*
|
||||
- cargo test --verbose
|
||||
- cargo test --verbose --no-default-features
|
||||
notifications:
|
||||
email:
|
||||
on_success: never
|
||||
|
||||
@@ -25,3 +25,8 @@ exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "tests/*" ]
|
||||
[dependencies.tinyvec]
|
||||
version = "0.3.3"
|
||||
features = ["alloc"]
|
||||
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = []
|
||||
|
||||
@@ -4,10 +4,15 @@
|
||||
//
|
||||
// If you're caught using this outside this crates tests/, you get to clean up the mess.
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use crate::no_std_prelude::*;
|
||||
|
||||
use crate::stream_safe::StreamSafe;
|
||||
|
||||
pub fn stream_safe(s: &str) -> String {
|
||||
StreamSafe::new(s.chars()).collect()
|
||||
}
|
||||
|
||||
pub mod quick_check {
|
||||
pub use crate::quick_check::*;
|
||||
}
|
||||
|
||||
+3
-3
@@ -7,9 +7,9 @@
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
use std::fmt::{self, Write};
|
||||
use std::iter::Fuse;
|
||||
use std::ops::Range;
|
||||
use core::fmt::{self, Write};
|
||||
use core::iter::Fuse;
|
||||
use core::ops::Range;
|
||||
use tinyvec::TinyVec;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
+10
-1
@@ -42,6 +42,13 @@
|
||||
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(not(feature = "std"), no_std)]
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
extern crate core;
|
||||
|
||||
extern crate tinyvec;
|
||||
|
||||
@@ -54,7 +61,9 @@ pub use crate::quick_check::{
|
||||
pub use crate::recompose::Recompositions;
|
||||
pub use crate::stream_safe::StreamSafe;
|
||||
pub use crate::tables::UNICODE_VERSION;
|
||||
use std::str::Chars;
|
||||
use core::str::Chars;
|
||||
|
||||
mod no_std_prelude;
|
||||
|
||||
mod decompose;
|
||||
mod lookups;
|
||||
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub use alloc::{
|
||||
str::Chars,
|
||||
string::{String, ToString},
|
||||
vec::Vec,
|
||||
};
|
||||
+2
-2
@@ -12,8 +12,8 @@
|
||||
use crate::lookups::{
|
||||
canonical_fully_decomposed, compatibility_fully_decomposed, composition_table,
|
||||
};
|
||||
use std::char;
|
||||
use std::ops::FnMut;
|
||||
|
||||
use core::{char, ops::FnMut};
|
||||
|
||||
/// Compute canonical Unicode decomposition for character.
|
||||
/// See [Unicode Standard Annex #15](http://www.unicode.org/reports/tr15/)
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
use crate::decompose::Decompositions;
|
||||
use std::fmt::{self, Write};
|
||||
use core::fmt::{self, Write};
|
||||
use tinyvec::TinyVec;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
+6
-2
@@ -107,7 +107,11 @@ mod tests {
|
||||
use super::{classify_nonstarters, StreamSafe};
|
||||
use crate::lookups::canonical_combining_class;
|
||||
use crate::normalize::decompose_compatible;
|
||||
use std::char;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use crate::no_std_prelude::*;
|
||||
|
||||
use core::char;
|
||||
|
||||
fn stream_safe(s: &str) -> String {
|
||||
StreamSafe::new(s.chars()).collect()
|
||||
@@ -131,7 +135,7 @@ mod tests {
|
||||
None => continue,
|
||||
};
|
||||
let c = classify_nonstarters(ch);
|
||||
let mut s = vec![];
|
||||
let mut s = Vec::new();
|
||||
decompose_compatible(ch, |c| s.push(c));
|
||||
|
||||
assert_eq!(s.len(), c.decomposition_len);
|
||||
|
||||
+4
-1
@@ -10,7 +10,10 @@
|
||||
|
||||
use super::char::is_combining_mark;
|
||||
use super::UnicodeNormalization;
|
||||
use std::char;
|
||||
use core::char;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use crate::no_std_prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_nfd() {
|
||||
|
||||
Reference in New Issue
Block a user