| { | ||
| "git": { | ||
| "sha1": "8b080b3753b91c58113c47c99108185d0614499c" | ||
| "sha1": "55cd12ebb25c6261492e1e3dfa2e6453c54dde31" | ||
| }, | ||
| "path_in_vcs": "utils/tinystr" | ||
| } |
+10
-12
@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "tinystr" | ||
| version = "0.7.5" | ||
| version = "0.7.6" | ||
| authors = ["The ICU4X Project Developers"] | ||
@@ -39,3 +39,3 @@ include = [ | ||
| categories = ["data-structures"] | ||
| license-file = "LICENSE" | ||
| license = "Unicode-3.0" | ||
| repository = "https://github.com/unicode-org/icu4x" | ||
@@ -82,3 +82,3 @@ | ||
| [dependencies.databake] | ||
| version = "0.1.7" | ||
| version = "0.1.8" | ||
| optional = true | ||
@@ -92,3 +92,3 @@ default-features = false | ||
| [dependencies.serde] | ||
| version = "1.0.123" | ||
| version = "1.0.110" | ||
| features = ["alloc"] | ||
@@ -99,3 +99,3 @@ optional = true | ||
| [dependencies.zerovec] | ||
| version = "0.10.1" | ||
| version = "0.10.2" | ||
| optional = true | ||
@@ -105,6 +105,6 @@ default-features = false | ||
| [dev-dependencies.bincode] | ||
| version = "1.3" | ||
| version = "1.3.1" | ||
| [dev-dependencies.postcard] | ||
| version = "1.0.0" | ||
| version = "1.0.1" | ||
| features = ["use-std"] | ||
@@ -114,9 +114,7 @@ default-features = false | ||
| [dev-dependencies.rand] | ||
| version = "0.8.5" | ||
| features = ["small_rng"] | ||
| version = "0.8" | ||
| [dev-dependencies.serde_json] | ||
| version = "1.0" | ||
| version = "1.0.45" | ||
| features = ["alloc"] | ||
| default-features = false | ||
@@ -130,2 +128,2 @@ [features] | ||
| [target."cfg(not(target_arch = \"wasm32\"))".dev-dependencies.criterion] | ||
| version = "0.4" | ||
| version = "0.5.0" |
+3
-1
@@ -5,3 +5,3 @@ UNICODE LICENSE V3 | ||
| Copyright © 2020-2023 Unicode, Inc. | ||
| Copyright © 2020-2024 Unicode, Inc. | ||
@@ -42,2 +42,4 @@ NOTICE TO USER: Carefully read the following legal agreement. BY | ||
| SPDX-License-Identifier: Unicode-3.0 | ||
| — | ||
@@ -44,0 +46,0 @@ |
+52
-3
@@ -25,2 +25,33 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| /// Creates a `TinyAsciiStr<N>` from a byte slice, replacing invalid bytes. | ||
| /// | ||
| /// Null and non-ASCII bytes (i.e. those outside the range `0x01..=0x7F`) | ||
| /// will be replaced with the '?' character. | ||
| /// | ||
| /// The input slice will be truncated if its length exceeds `N`. | ||
| pub const fn from_bytes_lossy(bytes: &[u8]) -> Self { | ||
| const QUESTION: u8 = b'?'; | ||
| let mut out = [0; N]; | ||
| let mut i = 0; | ||
| // Ord is not available in const, so no `.min(N)` | ||
| let len = if bytes.len() > N { N } else { bytes.len() }; | ||
| // Indexing is protected by the len check above | ||
| #[allow(clippy::indexing_slicing)] | ||
| while i < len { | ||
| let b = bytes[i]; | ||
| if b > 0 && b < 0x80 { | ||
| out[i] = b; | ||
| } else { | ||
| out[i] = QUESTION; | ||
| } | ||
| i += 1; | ||
| } | ||
| Self { | ||
| // SAFETY: `out` only contains ASCII bytes and has same size as `self.bytes` | ||
| bytes: unsafe { AsciiByte::to_ascii_byte_array(&out) }, | ||
| } | ||
| } | ||
| /// Attempts to parse a fixed-length byte array to a `TinyAsciiStr`. | ||
@@ -524,3 +555,3 @@ /// | ||
| unsafe { | ||
| $self.bytes[i] = core::mem::transmute( | ||
| $self.bytes[i] = core::mem::transmute::<u8, AsciiByte>( | ||
| ($self.bytes[i] as u8).$later_char_to() | ||
@@ -534,3 +565,3 @@ ); | ||
| $self.bytes[0] = unsafe { | ||
| core::mem::transmute(($self.bytes[0] as u8).$first_char_to()) | ||
| core::mem::transmute::<u8, AsciiByte>(($self.bytes[0] as u8).$first_char_to()) | ||
| }; | ||
@@ -631,3 +662,3 @@ )? | ||
| #[inline] | ||
| fn from_str(s: &str) -> Result<Self, TinyStrError> { | ||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| Self::from_str(s) | ||
@@ -988,2 +1019,20 @@ } | ||
| } | ||
| #[test] | ||
| fn lossy_constructor() { | ||
| assert_eq!(TinyAsciiStr::<4>::from_bytes_lossy(b"").as_str(), ""); | ||
| assert_eq!( | ||
| TinyAsciiStr::<4>::from_bytes_lossy(b"oh\0o").as_str(), | ||
| "oh?o" | ||
| ); | ||
| assert_eq!(TinyAsciiStr::<4>::from_bytes_lossy(b"\0").as_str(), "?"); | ||
| assert_eq!( | ||
| TinyAsciiStr::<4>::from_bytes_lossy(b"toolong").as_str(), | ||
| "tool" | ||
| ); | ||
| assert_eq!( | ||
| TinyAsciiStr::<4>::from_bytes_lossy(&[b'a', 0x80, 0xFF, b'1']).as_str(), | ||
| "a??1" | ||
| ); | ||
| } | ||
| } |
+2
-2
@@ -30,3 +30,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| pub const fn from_ascii_bytes<const N: usize>(src: &[AsciiByte; N]) -> Self { | ||
| Self::from_bytes::<N>(unsafe { core::mem::transmute(src) }) | ||
| Self::from_bytes::<N>(unsafe { core::mem::transmute::<&[AsciiByte; N], &[u8; N]>(src) }) | ||
| } | ||
@@ -188,3 +188,3 @@ | ||
| pub const fn from_ascii_bytes<const N: usize>(src: &[AsciiByte; N]) -> Self { | ||
| Self::from_bytes::<N>(unsafe { core::mem::transmute(src) }) | ||
| Self::from_bytes::<N>(unsafe { core::mem::transmute::<&[AsciiByte; N], &[u8; N]>(src) }) | ||
| } | ||
@@ -191,0 +191,0 @@ |
+1
-1
@@ -54,3 +54,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| // https://github.com/unicode-org/icu4x/blob/main/docs/process/boilerplate.md#library-annotations | ||
| // https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations | ||
| #![cfg_attr(not(any(test, feature = "std")), no_std)] | ||
@@ -57,0 +57,0 @@ #![cfg_attr( |
Sorry, the diff of this file is not supported yet