pub struct CapeStringImpl {
data: Vec<CapeCharacter>,
}Expand description
Default ICapeString implementation
For COBIA, strings go over the pipeline as null terminated. For Windows, COBIA requires UTF-16 encoding.
Rust uses non-null-terminated strings that are UTF-8 encoded.
Because this translation is always required, there is no read-only string implementation that refers to a string slice.
This implementation uses a Vec<u16> to store the string data.
In case the string is empty, the vector may remain empty, so
care must be taken to add a null terminated string in this scenario.
Fields§
§data: Vec<CapeCharacter>Implementations§
Source§impl CapeStringImpl
impl CapeStringImpl
const EMPTY_STRING: CapeCharacter = 0u16
const CAPE_STRING_VTABLE: ICapeString_VTable
Sourcepub fn new() -> Self
pub fn new() -> Self
Default constructor
§Examples
use cobia;
let s=cobia::CapeStringImpl::new();
assert_eq!(s.as_string(),"");Sourcepub fn from_string<T: AsRef<str>>(s: T) -> Self
pub fn from_string<T: AsRef<str>>(s: T) -> Self
Sourcepub unsafe fn from_raw_data(data: *const CapeCharacter, size: CapeSize) -> Self
pub unsafe fn from_raw_data(data: *const CapeCharacter, size: CapeSize) -> Self
Construct from raw data
§Arguments
data- A pointer to the string datasize- The size of the string data
Sourcepub fn as_string(&self) -> String
pub fn as_string(&self) -> String
Return as string
§Examples
use cobia;
let s=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
assert_eq!(s.as_string(),"idealGasEnthalpy");Sourcepub fn set<T: CapeStringConstProvider>(&mut self, s: &T)
pub fn set<T: CapeStringConstProvider>(&mut self, s: &T)
Sourcepub fn set_string<T: AsRef<str>>(&mut self, s: T)
pub fn set_string<T: AsRef<str>>(&mut self, s: T)
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check empty
Returns true if the string is empty (no data, or only the null terminator).
§Examples
use cobia;
let s=cobia::CapeStringImpl::new();
assert_eq!(s.is_empty(),true);
let s=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
assert_eq!(s.is_empty(),false);extern "C" fn string_get( me: *mut c_void, data: *mut *const CapeCharacter, size: *mut CapeSize, )
extern "C" fn string_set( me: *mut c_void, data: *const CapeCharacter, size: CapeSize, ) -> CapeResult
Sourcepub(crate) fn to_lower_case(c: CapeCharacter) -> CapeCharacter
pub(crate) fn to_lower_case(c: CapeCharacter) -> CapeCharacter
Sourcepub(crate) fn to_upper_case(c: CapeCharacter) -> CapeCharacter
pub(crate) fn to_upper_case(c: CapeCharacter) -> CapeCharacter
Sourcepub fn to_lowercase(&self) -> Self
pub fn to_lowercase(&self) -> Self
Convert to lower case.
Most CAPE-OPEN string comparisons are case insensitive. By allowing converson to lower case, we can use this in conjuntion with Eq, PartialEq, Hash, etc to make lookup tables and comparisons without the need to convert to Rust’s utf-8 encoded string (on Windows, CapeString is UTF-16 encoded and null terminated).
Note that this is a simple conversion of the first character of each code point.
§Examples
use cobia;
let s=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
assert_eq!(s.to_lowercase(),cobia::CapeStringImpl::from_string("idealgasenthalpy"));Sourcepub fn to_uppercase(&self) -> Self
pub fn to_uppercase(&self) -> Self
Convert to upper case.
Most CAPE-OPEN string comparisons are case insensitive. By allowing converson to upper case, we can use this in conjuntion with Eq, PartialEq, Hash, etc to make lookup tables and comparisons without the need to convert to Rust’s utf-8 encoded string (on Windows, CapeString is UTF-16 encoded and null terminated).
Note that this is a simple conversion of the first character of each code point.
§Examples
use cobia;
let s=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
assert_eq!(s.to_uppercase(),cobia::CapeStringImpl::from_string("IDEALGASENTHALPY"));Sourcepub fn eq_ignore_case<T: CapeStringConstProvider>(&self, other: &T) -> bool
pub fn eq_ignore_case<T: CapeStringConstProvider>(&self, other: &T) -> bool
Trait Implementations§
Source§impl CapeStringConstProvider for CapeStringImpl
impl CapeStringConstProvider for CapeStringImpl
Source§fn as_capechar_const_with_length(&self) -> (*const CapeCharacter, CapeSize)
fn as_capechar_const_with_length(&self) -> (*const CapeCharacter, CapeSize)
Return as CapeCharacter const pointer with length
The caller must ensure that the lifetime of the CapeStringImpl is longer than the pointer returned.
§Examples
use cobia;
use cobia::prelude::*;
let s=cobia::CapeStringImpl::from_string("idealGasEnthalpy"); //must remain in scope....
let (ptr,len)=s.as_capechar_const_with_length(); ///... while ptr is used
assert_eq!(len,16);Source§fn as_capechar_const(&self) -> *const CapeCharacter
fn as_capechar_const(&self) -> *const CapeCharacter
Return as CapeCharacter const pointer with length
The caller must ensure that the lifetime of the CapeStringImpl is longer than the pointer returned.
§Examples
use cobia;
use cobia::prelude::*;
let s=cobia::CapeStringImpl::from_string("idealGasEnthalpy"); //must remain in scope....
let ptr=s.as_capechar_const(); ///... while ptr is used
assert_eq!(unsafe{*ptr},'i' as u16);Source§impl CapeStringProviderIn for CapeStringImpl
impl CapeStringProviderIn for CapeStringImpl
Source§fn as_cape_string_in(&self) -> ICapeString
fn as_cape_string_in(&self) -> ICapeString
Source§impl CapeStringProviderOut for CapeStringImpl
impl CapeStringProviderOut for CapeStringImpl
Source§fn as_cape_string_out(&mut self) -> ICapeString
fn as_cape_string_out(&mut self) -> ICapeString
Source§impl Clone for CapeStringImpl
impl Clone for CapeStringImpl
Source§fn clone(&self) -> CapeStringImpl
fn clone(&self) -> CapeStringImpl
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CapeStringImpl
impl Debug for CapeStringImpl
Source§impl Default for CapeStringImpl
impl Default for CapeStringImpl
Source§impl Display for CapeStringImpl
impl Display for CapeStringImpl
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the CapeStringImpl error using the given formatter.
§Examples
use cobia;
let s=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
assert_eq!(format!("{}",s),"idealGasEnthalpy");use cobia;
let s=cobia::CapeStringImpl::new();
assert_eq!(format!("{}",s),"");Source§impl Hash for CapeStringImpl
impl Hash for CapeStringImpl
Source§impl<T: CapeStringConstProvider> PartialEq<T> for CapeStringImpl
impl<T: CapeStringConstProvider> PartialEq<T> for CapeStringImpl
Source§fn eq(&self, other: &T) -> bool
fn eq(&self, other: &T) -> bool
Case sensitive comparison
§Arguments
- other - The other string to compare to
§Return
- true if the strings are equal, false otherwise.
§Examples
use cobia;
let s1=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
let s2=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
assert_eq!(s1==s2,true);
let s3=cobia::CapeStringImpl::from_string("IdealGasEnthalpy");
assert_eq!(s1==s3,false);