Auto merge of #31608 - frewsxcv:osstring-simple-functions, r=alexcrichton
https://github.com/rust-lang/rust/issues/29453
This commit is contained in:
@@ -178,6 +178,10 @@ impl Wtf8Buf {
|
||||
Wtf8Buf { bytes: <[_]>::to_vec(str.as_bytes()) }
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.bytes.clear()
|
||||
}
|
||||
|
||||
/// Creates a WTF-8 string from a potentially ill-formed UTF-16 slice of 16-bit code units.
|
||||
///
|
||||
/// This is lossless: calling `.encode_wide()` on the resulting string
|
||||
@@ -234,6 +238,11 @@ impl Wtf8Buf {
|
||||
self.bytes.reserve(additional)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn reserve_exact(&mut self, additional: usize) {
|
||||
self.bytes.reserve_exact(additional)
|
||||
}
|
||||
|
||||
/// Returns the number of bytes that this string buffer can hold without reallocating.
|
||||
#[inline]
|
||||
pub fn capacity(&self) -> usize {
|
||||
@@ -443,6 +452,11 @@ impl Wtf8 {
|
||||
self.bytes.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.bytes.is_empty()
|
||||
}
|
||||
|
||||
/// Returns the code point at `position` if it is in the ASCII range,
|
||||
/// or `b'\xFF' otherwise.
|
||||
///
|
||||
|
||||
@@ -17,6 +17,7 @@ use vec::Vec;
|
||||
use str;
|
||||
use string::String;
|
||||
use mem;
|
||||
use sys_common::{AsInner, IntoInner};
|
||||
|
||||
#[derive(Clone, Hash)]
|
||||
pub struct Buf {
|
||||
@@ -39,11 +40,51 @@ impl Debug for Buf {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoInner<Vec<u8>> for Buf {
|
||||
fn into_inner(self) -> Vec<u8> {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl AsInner<[u8]> for Buf {
|
||||
fn as_inner(&self) -> &[u8] {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Buf {
|
||||
pub fn from_string(s: String) -> Buf {
|
||||
Buf { inner: s.into_bytes() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn with_capacity(capacity: usize) -> Buf {
|
||||
Buf {
|
||||
inner: Vec::with_capacity(capacity)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn clear(&mut self) {
|
||||
self.inner.clear()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn capacity(&self) -> usize {
|
||||
self.inner.capacity()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn reserve(&mut self, additional: usize) {
|
||||
self.inner.reserve(additional)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn reserve_exact(&mut self, additional: usize) {
|
||||
self.inner.reserve_exact(additional)
|
||||
}
|
||||
|
||||
pub fn as_slice(&self) -> &Slice {
|
||||
unsafe { mem::transmute(&*self.inner) }
|
||||
}
|
||||
|
||||
@@ -18,12 +18,25 @@ use string::String;
|
||||
use result::Result;
|
||||
use option::Option;
|
||||
use mem;
|
||||
use sys_common::{AsInner, IntoInner};
|
||||
|
||||
#[derive(Clone, Hash)]
|
||||
pub struct Buf {
|
||||
pub inner: Wtf8Buf
|
||||
}
|
||||
|
||||
impl IntoInner<Wtf8Buf> for Buf {
|
||||
fn into_inner(self) -> Wtf8Buf {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl AsInner<Wtf8> for Buf {
|
||||
fn as_inner(&self) -> &Wtf8 {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Buf {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
self.as_slice().fmt(formatter)
|
||||
@@ -41,6 +54,20 @@ impl Debug for Slice {
|
||||
}
|
||||
|
||||
impl Buf {
|
||||
pub fn with_capacity(capacity: usize) -> Buf {
|
||||
Buf {
|
||||
inner: Wtf8Buf::with_capacity(capacity)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.inner.clear()
|
||||
}
|
||||
|
||||
pub fn capacity(&self) -> usize {
|
||||
self.inner.capacity()
|
||||
}
|
||||
|
||||
pub fn from_string(s: String) -> Buf {
|
||||
Buf { inner: Wtf8Buf::from_string(s) }
|
||||
}
|
||||
@@ -56,6 +83,14 @@ impl Buf {
|
||||
pub fn push_slice(&mut self, s: &Slice) {
|
||||
self.inner.push_wtf8(&s.inner)
|
||||
}
|
||||
|
||||
pub fn reserve(&mut self, additional: usize) {
|
||||
self.inner.reserve(additional)
|
||||
}
|
||||
|
||||
pub fn reserve_exact(&mut self, additional: usize) {
|
||||
self.inner.reserve_exact(additional)
|
||||
}
|
||||
}
|
||||
|
||||
impl Slice {
|
||||
|
||||
Reference in New Issue
Block a user