pub struct basic_string<CharT: AbiType + 'static> { /* private fields */ }Expand description
cpp class: template<class CharT, class Traits, class Allocator> std::basic_string<CharT, Traits, Allocator>
Implementations§
Source§impl<CharT: AbiType + 'static> basic_string<CharT>
impl<CharT: AbiType + 'static> basic_string<CharT>
pub const npos: usize = 18_446_744_073_709_551_615usize
Sourcepub fn substr(&self, pos: usize, len: usize) -> Self
pub fn substr(&self, pos: usize, len: usize) -> Self
如果pos超出范围,会返回空字符串.
use hicc_std::string;
let mut s = string::from(c"abc");
let substr = s.substr(1, 2);
assert_eq!(substr.as_cstr(), c"bc");Sourcepub fn append_str(&mut self, s: &Self, subpos: usize, sublen: usize)
pub fn append_str(&mut self, s: &Self, subpos: usize, sublen: usize)
如果subpos超出范围则不做任何改变.
use hicc_std::string;
let mut s1 = string::from(c"abc");
let s2 = string::from(c"def");
s1.append_str(&s2, 0, 2);
assert_eq!(s1.as_cstr(), c"abcde");Sourcepub fn insert_str(&mut self, pos: usize, s: &Self, subpos: usize, sublen: usize)
pub fn insert_str(&mut self, pos: usize, s: &Self, subpos: usize, sublen: usize)
如果subpos超出范围不做任何改变, 如果pos超出范围则追加到最后.
use hicc_std::string;
let mut s1 = string::from(c"abc");
let mut s2 = string::from(c"def");
s1.insert_str(0, &s2, 0, string::npos);
assert_eq!(s1.as_cstr(), c"defabc");
s1.insert_str(100, &s2, 0, string::npos);
assert_eq!(s1.as_cstr(), c"defabcdef");Sourcepub fn insert(&mut self, pos: usize, n: usize, c: CharT::InputType)
pub fn insert(&mut self, pos: usize, n: usize, c: CharT::InputType)
如果pos超出范围则追加到最后.
use hicc_std::string;
let mut s = string::from(c"abc");
s.insert(0, 3, b'd' as i8);
assert_eq!(s.as_cstr(), c"dddabc");
s.insert(110, 3, b'd' as i8);
assert_eq!(s.as_cstr(), c"dddabcddd");Sourcepub fn replace_str(
&mut self,
pos: usize,
len: usize,
s: &Self,
subpos: usize,
sublen: usize,
)
pub fn replace_str( &mut self, pos: usize, len: usize, s: &Self, subpos: usize, sublen: usize, )
如果pos或者subpos超出范围则不做任何改变.
use hicc_std::string;
let mut s1 = string::from(c"abc");
let mut s2 = string::from(c"de");
s1.replace_str(0, string::npos, &s2, 0, string::npos);
assert_eq!(s1.as_cstr(), c"de");Sourcepub fn replace(&mut self, pos: usize, len: usize, n: usize, c: CharT::InputType)
pub fn replace(&mut self, pos: usize, len: usize, n: usize, c: CharT::InputType)
如果pos超出范围则不做任何改变.
use hicc_std::string;
let mut s = string::from(c"abc");
s.replace(0, string::npos, 1, b'd' as i8);
assert_eq!(s.as_cstr(), c"d");Sourcepub fn assign_str(&mut self, s: &Self, subpos: usize, sublen: usize)
pub fn assign_str(&mut self, s: &Self, subpos: usize, sublen: usize)
如果subpos超出范围则不做任何改变.
use hicc_std::string;
let mut s1 = string::from(c"abc");
let mut s2 = string::from(c"de");
s1.assign_str(&s2, 0, string::npos);
assert_eq!(s1.as_cstr(), c"de");Sourcepub fn erase(&mut self, pos: usize, len: usize)
pub fn erase(&mut self, pos: usize, len: usize)
如果pos超出范围则不做任何改变.
use hicc_std::string;
let mut s = string::from(c"abc");
s.erase(1, 1);
assert_eq!(s.as_cstr(), c"ac");Sourcepub fn pop_back(&mut self)
pub fn pop_back(&mut self)
如果为空则不做任何改变.
use hicc_std::string;
let mut s = string::from(c"abc");
s.pop_back();
assert_eq!(s.as_cstr(), c"ab");Sourcepub fn get(&self, pos: usize) -> Option<CharT::OutputRef<'_>>
pub fn get(&self, pos: usize) -> Option<CharT::OutputRef<'_>>
use hicc_std::string;
let s = string::from(c"abc");
assert_eq!(s.get(0), Some(&(b'a' as i8)));
assert_eq!(s.get(3), None);Sourcepub fn get_mut(&mut self, pos: usize) -> Option<CharT::OutputRefMut<'_>>
pub fn get_mut(&mut self, pos: usize) -> Option<CharT::OutputRefMut<'_>>
use hicc_std::string;
let mut s = string::from(c"abc");
assert!(s.get_mut(0).is_some());
assert_eq!(*s.get_mut(0).unwrap(), b'a' as i8);
assert_eq!(s.get(3), None);Sourcepub fn c_str(
&self,
) -> <CharT as AbiType>::OutputPtr<'static, *const <CharT as AbiType>::InputType, 1usize>
pub fn c_str( &self, ) -> <CharT as AbiType>::OutputPtr<'static, *const <CharT as AbiType>::InputType, 1usize>
use std::ffi::CStr;
use hicc_std::string;
let s = string::from(c"abc");
let cstr = unsafe { CStr::from_ptr(s.c_str()) };
assert_eq!(cstr, c"abc");Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
use hicc_std::string;
let s = string::new();
assert!(s.is_empty());Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
use hicc_std::string;
let s = string::new();
assert_eq!(s.size(), 0);Sourcepub fn max_size(&self) -> usize
pub fn max_size(&self) -> usize
use hicc_std::string;
let s = string::new();
println!("s.max_size = {}", s.max_size());Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
use hicc_std::string;
let s = string::new();
println!("s.capacity = {}", s.capacity());Sourcepub fn resize(&mut self, n: usize, c: <CharT as AbiType>::InputType)
pub fn resize(&mut self, n: usize, c: <CharT as AbiType>::InputType)
use hicc_std::string;
let mut s = string::from(c"a");
s.resize(3, b'c' as i8);
assert_eq!(s.as_cstr(), c"acc");Sourcepub fn reserve(&mut self, n: usize)
pub fn reserve(&mut self, n: usize)
use hicc_std::string;
let mut s = string::from(c"abc");
s.reserve(100);
println!("s.capacity = {}", s.capacity());Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
use hicc_std::string;
let mut s = string::from(c"abc");
s.clear();
assert!(s.is_empty());Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
use hicc_std::string;
let mut s = string::from(c"abc");
s.reserve(100);
println!("before shrink_to_fit: capacity = {}", s.capacity());
s.assign(10, b'c' as i8);
s.shrink_to_fit();
println!("after shrink_to_fit: capacity = {}", s.capacity());Sourcepub fn compare(
&self,
other: &<basic_string<CharT> as AbiType>::InputType,
) -> i32
pub fn compare( &self, other: &<basic_string<CharT> as AbiType>::InputType, ) -> i32
use hicc_std::string;
let s1 = string::from(c"abc");
let s2 = string::from(c"abd");
assert!(s1 < s2);
assert!(s1 != s2);Sourcepub fn find_str(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_str( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(c"abcdef");
let s2 = string::from(c"bcd");
assert_eq!(s1.find_str(&s2, 0), 1);Sourcepub fn find(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
pub fn find(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
use hicc_std::string;
let s = string::from(c"abcdef");
assert_eq!(s.find(b'c' as i8, 1), 2);Sourcepub fn rfind_str(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn rfind_str( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(c"abcdef");
let s2 = string::from(c"bcd");
assert_eq!(s1.rfind_str(&s2, string::npos), 1);Sourcepub fn rfind(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
pub fn rfind(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
use hicc_std::string;
let s = string::from(c"abcdef");
assert_eq!(s.rfind(b'c' as i8, string::npos), 2);Sourcepub fn find_first_of(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_first_of( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(c"abcdef");
let s2 = string::from(c"dfb");
assert_eq!(s1.find_first_of(&s2, 0), 1);Sourcepub fn find_first(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
pub fn find_first(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
use hicc_std::string;
let s = string::from(c"abcabc");
assert_eq!(s.find_first(b'c' as i8, 0), 2);Sourcepub fn find_last_of(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_last_of( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(c"abcdef");
let s2 = string::from(c"dfb");
assert_eq!(s1.find_last_of(&s2, string::npos), 5);Sourcepub fn find_last(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
pub fn find_last(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
use hicc_std::string;
let s = string::from(c"abcabc");
assert_eq!(s.find_last(b'c' as i8, string::npos), 5);Sourcepub fn find_first_not_of(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_first_not_of( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(c"abcdef");
let s2 = string::from(c"abc");
assert_eq!(s1.find_first_not_of(&s2, 0), 3);Sourcepub fn find_first_not(
&self,
c: <CharT as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_first_not( &self, c: <CharT as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s = string::from(c"abcabc");
assert_eq!(s.find_first_not(b'a' as i8, 0), 1);Sourcepub fn find_last_not_of(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_last_not_of( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(c"abcdef");
let s2 = string::from(c"def");
assert_eq!(s1.find_last_not_of(&s2, string::npos), 2);Sourcepub fn find_last_not(
&self,
c: <CharT as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_last_not( &self, c: <CharT as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s = string::from(c"abcabc");
assert_eq!(s.find_last_not(b'c' as i8, string::npos), 4);Sourcepub fn append(&mut self, n: usize, c: <CharT as AbiType>::InputType)
pub fn append(&mut self, n: usize, c: <CharT as AbiType>::InputType)
use hicc_std::string;
let mut s = string::from(c"abc");
s.append(1, b'd' as i8);
assert_eq!(s.as_cstr(), c"abcd");Sourcepub fn assign(&mut self, n: usize, c: <CharT as AbiType>::InputType)
pub fn assign(&mut self, n: usize, c: <CharT as AbiType>::InputType)
use hicc_std::string;
let mut s = string::from(c"abc");
s.assign(1, b'd' as i8);
assert_eq!(s.as_cstr(), c"d");Sourcepub fn push_back(&mut self, c: <CharT as AbiType>::InputType)
pub fn push_back(&mut self, c: <CharT as AbiType>::InputType)
use hicc_std::string;
let mut s = string::from(c"abc");
s.push_back(b'd' as i8);
assert_eq!(s.as_cstr(), c"abcd");Sourcepub fn swap(&mut self, other: &mut <basic_string<CharT> as AbiType>::InputType)
pub fn swap(&mut self, other: &mut <basic_string<CharT> as AbiType>::InputType)
use hicc_std::string;
let mut s1 = string::from(c"abc");
let mut s2 = string::from(c"de");
s1.swap(&mut s2);
assert_eq!(s1.as_cstr(), c"de");
assert_eq!(s2.as_cstr(), c"abc");Source§impl<T: Sized + 'static> basic_string<Pod<T>>
impl<T: Sized + 'static> basic_string<Pod<T>>
Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
use hicc_std::string;
let mut s = string::with_cstr(c"bcd");
assert_eq!(s.as_slice(), &[b'b' as i8, b'c' as i8, b'd' as i8]);Sourcepub fn as_slice_mut(&mut self) -> &mut [T]
pub fn as_slice_mut(&mut self) -> &mut [T]
use hicc_std::string;
let mut s = string::with_cstr(c"abc");
s.as_slice_mut().iter_mut().for_each(|mut c| { *c += 1; });
assert_eq!(s.as_slice(), &[b'b' as i8, b'c' as i8, b'd' as i8]);Source§impl basic_string<Pod<i8>>
impl basic_string<Pod<i8>>
Source§impl basic_string<Pod<i16>>
impl basic_string<Pod<i16>>
Trait Implementations§
Source§impl<CharT: AbiType + 'static> AbiClass for basic_string<CharT>
impl<CharT: AbiType + 'static> AbiClass for basic_string<CharT>
Source§fn get_raw_obj(&self) -> *const ()
fn get_raw_obj(&self) -> *const ()
仅内部使用.指针携带附加信息,不能转换为
c++类指针.Source§unsafe fn into_unique(self) -> Self
unsafe fn into_unique(self) -> Self
Safety Read more
Source§fn as_mut(&mut self) -> ClassRefMut<'_, Self>
fn as_mut(&mut self) -> ClassRefMut<'_, Self>
Source§fn as_mut_ptr(&mut self) -> ClassMutPtr<'_, Self>
fn as_mut_ptr(&mut self) -> ClassMutPtr<'_, Self>
AbiType::InputMutPtr<'_, T>参数类型实际是&ClassMutPtr<'_, T>,
当需要传递这类参数时可调用此接口.Source§fn into_ref(self) -> ClassRef<'static, Self>
fn into_ref(self) -> ClassRef<'static, Self>
T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.Source§fn into_mut(self) -> ClassRefMut<'static, Self>
fn into_mut(self) -> ClassRefMut<'static, Self>
T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.Source§fn into_ptr(self) -> ClassPtr<'static, Self>
fn into_ptr(self) -> ClassPtr<'static, Self>
T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.Source§fn into_mut_ptr(self) -> ClassMutPtr<'static, Self>
fn into_mut_ptr(self) -> ClassMutPtr<'static, Self>
T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.Source§impl<CharT: AbiType + 'static> Debug for basic_string<CharT>
impl<CharT: AbiType + 'static> Debug for basic_string<CharT>
Source§impl<CharT: AbiType + 'static> Drop for basic_string<CharT>
impl<CharT: AbiType + 'static> Drop for basic_string<CharT>
Source§impl<T: AbiType> PartialEq for basic_string<T>
impl<T: AbiType> PartialEq for basic_string<T>
Source§impl<T: AbiType> PartialOrd for basic_string<T>
impl<T: AbiType> PartialOrd for basic_string<T>
impl<CharT: AbiType + Sync> Send for basic_string<CharT>
impl<CharT: AbiType + Sync> Sync for basic_string<CharT>
Auto Trait Implementations§
impl<CharT> Freeze for basic_string<CharT>
impl<CharT> RefUnwindSafe for basic_string<CharT>
impl<CharT> Unpin for basic_string<CharT>
impl<CharT> UnwindSafe for basic_string<CharT>
Blanket Implementations§
Source§impl<T> AbiType for Twhere
T: AbiClass,
impl<T> AbiType for Twhere
T: AbiClass,
type InputType = T
type InputPtr<'a, P, const N: usize> = &'a ClassPtr<'a, T, N> where T: 'a
type InputMutPtr<'a, P, const N: usize> = &'a ClassMutPtr<'a, T, N> where T: 'a
type OutputType = T
type OutputRef<'a> = ClassRef<'a, T> where T: 'a
type OutputRefMut<'a> = ClassRefMut<'a, T> where T: 'a
type OutputPtr<'a, P, const N: usize> = ClassPtr<'a, T, N> where T: 'a
type OutputMutPtr<'a, P, const N: usize> = ClassMutPtr<'a, T, N> where T: 'a
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more