mirror of
https://github.com/openharmony/third_party_rust_os_str_bytes.git
synced 2026-06-30 22:08:37 -04:00
Minor improvements
This commit is contained in:
@@ -1,2 +1 @@
|
|||||||
edition = "2018"
|
|
||||||
max_width = 79
|
max_width = 79
|
||||||
|
|||||||
+4
-7
@@ -160,19 +160,16 @@ macro_rules! if_raw {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(windows, path = "windows/mod.rs")]
|
||||||
|
#[cfg_attr(not(windows), path = "common/mod.rs")]
|
||||||
|
mod imp;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
|
|
||||||
if_raw! {
|
if_raw! {
|
||||||
pub mod raw;
|
pub mod raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
#[path = "common/mod.rs"]
|
|
||||||
mod imp;
|
|
||||||
#[cfg(windows)]
|
|
||||||
#[path = "windows/mod.rs"]
|
|
||||||
mod imp;
|
|
||||||
|
|
||||||
/// The error that occurs when a byte sequence is not representable in the
|
/// The error that occurs when a byte sequence is not representable in the
|
||||||
/// platform encoding.
|
/// platform encoding.
|
||||||
///
|
///
|
||||||
|
|||||||
+1
-1
@@ -61,7 +61,7 @@ impl OsStringBytes for OsString {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_vec(self) -> Vec<u8> {
|
fn into_vec(self) -> Vec<u8> {
|
||||||
OsStrBytes::to_bytes(self.as_os_str()).into_owned()
|
OsStrBytes::to_bytes(&*self).into_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,15 +112,14 @@ where
|
|||||||
|
|
||||||
self.iter.next().map(|code_point| {
|
self.iter.next().map(|code_point| {
|
||||||
code_point.map(|code_point| {
|
code_point.map(|code_point| {
|
||||||
if let Some(offset) =
|
code_point
|
||||||
code_point.checked_sub(MIN_SURROGATE_CODE)
|
.checked_sub(MIN_SURROGATE_CODE)
|
||||||
{
|
.map(|offset| {
|
||||||
self.surrogate =
|
self.surrogate =
|
||||||
Some((offset & 0x3FF) as u16 | MIN_LOW_SURROGATE);
|
Some((offset & 0x3FF) as u16 | MIN_LOW_SURROGATE);
|
||||||
(offset >> 10) as u16 | MIN_HIGH_SURROGATE
|
(offset >> 10) as u16 | MIN_HIGH_SURROGATE
|
||||||
} else {
|
})
|
||||||
code_point as u16
|
.unwrap_or(code_point as u16)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,10 +42,6 @@ pub(in super::super) fn starts_with(
|
|||||||
string: &[u8],
|
string: &[u8],
|
||||||
mut prefix: &[u8],
|
mut prefix: &[u8],
|
||||||
) -> Option<bool> {
|
) -> Option<bool> {
|
||||||
if prefix.is_empty() {
|
|
||||||
return Some(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(&byte) = string.get(prefix.len()) {
|
if let Some(&byte) = string.get(prefix.len()) {
|
||||||
if is_continuation(byte) {
|
if is_continuation(byte) {
|
||||||
let index = prefix.len().checked_sub(SURROGATE_LENGTH)?;
|
let index = prefix.len().checked_sub(SURROGATE_LENGTH)?;
|
||||||
|
|||||||
+2
-2
@@ -57,7 +57,7 @@ pub(crate) fn test_bytes(string: &[u8]) -> Result<(), EncodingError> {
|
|||||||
pub(crate) fn test_vec(string: &[u8]) -> Result<(), EncodingError> {
|
pub(crate) fn test_vec(string: &[u8]) -> Result<(), EncodingError> {
|
||||||
let os_string = from_vec(string.to_vec())?;
|
let os_string = from_vec(string.to_vec())?;
|
||||||
assert_eq!(string.len(), os_string.len());
|
assert_eq!(string.len(), os_string.len());
|
||||||
assert_eq!(string, os_string.into_vec().as_slice());
|
assert_eq!(string, &*os_string.into_vec());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,5 +72,5 @@ pub(crate) fn test_utf8_vec(string: &str) {
|
|||||||
let os_string = string.to_string().into();
|
let os_string = string.to_string().into();
|
||||||
let string = string.as_bytes();
|
let string = string.as_bytes();
|
||||||
assert_eq!(Ok(&os_string), from_vec(string.to_vec()).as_ref());
|
assert_eq!(Ok(&os_string), from_vec(string.to_vec()).as_ref());
|
||||||
assert_eq!(string, os_string.into_vec().as_slice());
|
assert_eq!(string, &*os_string.into_vec());
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -67,7 +67,7 @@ fn test_random_vec() -> Result<(), getrandom::Error> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lossless() -> Result<(), getrandom::Error> {
|
fn test_lossless() -> Result<(), getrandom::Error> {
|
||||||
for _ in 1..ITERATIONS {
|
for _ in 0..ITERATIONS {
|
||||||
let mut string = vec![0; SMALL_LENGTH];
|
let mut string = vec![0; SMALL_LENGTH];
|
||||||
getrandom(&mut string)?;
|
getrandom(&mut string)?;
|
||||||
if let Ok(os_string) = OsStr::from_bytes(&string) {
|
if let Ok(os_string) = OsStr::from_bytes(&string) {
|
||||||
@@ -95,7 +95,7 @@ fn test_raw() -> Result<(), getrandom::Error> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
for _ in 1..ITERATIONS {
|
for _ in 0..ITERATIONS {
|
||||||
let mut string = random_os_string(SMALL_LENGTH)?;
|
let mut string = random_os_string(SMALL_LENGTH)?;
|
||||||
let prefix = string.to_bytes().into_owned();
|
let prefix = string.to_bytes().into_owned();
|
||||||
let suffix = random_os_string(SMALL_LENGTH)?;
|
let suffix = random_os_string(SMALL_LENGTH)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user