Struct CapeStringImpl

Source
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

Source

const EMPTY_STRING: CapeCharacter = 0u16

Source

const CAPE_STRING_VTABLE: ICapeString_VTable

Source

pub fn new() -> Self

Default constructor

§Examples
use cobia;
let s=cobia::CapeStringImpl::new();
assert_eq!(s.as_string(),"");
Source

pub fn from_string<T: AsRef<str>>(s: T) -> Self

Construct from string

§Arguments
  • s - A string slice to be converted to a CapeStringImpl
§Examples
use cobia;
let s=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
Source

pub unsafe fn from_raw_data(data: *const CapeCharacter, size: CapeSize) -> Self

Construct from raw data

§Arguments
  • data - A pointer to the string data
  • size - The size of the string data
Source

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");
Source

pub fn set<T: CapeStringConstProvider>(&mut self, s: &T)

Set string

§Arguments
  • s - Any CAPE-OPEN string type
§Examples
use cobia;
let mut s=cobia::CapeStringImpl::new();
s.set(&cobia::CapeStringImpl::from_string("idealGasEnthalpy"));
assert_eq!(s.as_string(),"idealGasEnthalpy");
Source

pub fn set_string<T: AsRef<str>>(&mut self, s: T)

Set string

§Arguments
  • s - A string slice to be set
§Examples
use cobia;
let mut s=cobia::CapeStringImpl::new();
s.set_string("idealGasEnthalpy");
assert_eq!(s.as_string(),"idealGasEnthalpy");
Source

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);
Source

extern "C" fn string_get( me: *mut c_void, data: *mut *const CapeCharacter, size: *mut CapeSize, )

Source

extern "C" fn string_set( me: *mut c_void, data: *const CapeCharacter, size: CapeSize, ) -> CapeResult

Source

pub(crate) fn to_lower_case(c: CapeCharacter) -> CapeCharacter

Convert character to lower case

§Arguments
  • c - A UTF-16 character to convert to lower case
Source

pub(crate) fn to_upper_case(c: CapeCharacter) -> CapeCharacter

Convert character to upper case

§Arguments
  • c - A UTF-16 character to convert to upper case
Source

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"));
Source

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"));
Source

pub fn eq_ignore_case<T: CapeStringConstProvider>(&self, other: &T) -> bool

Case insentitive comparison

§Arguments
  • other - The other string to compare to
§Examples
use cobia;
let s1=cobia::CapeStringImpl::from_string("idealGasEnthalpy");
let s2=cobia::CapeStringImpl::from_string("IDEALGASENTHALPY");
assert_eq!(s1.eq_ignore_case(&s2),true);

Trait Implementations§

Source§

impl CapeStringConstProvider for CapeStringImpl

Source§

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

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

Source§

fn as_cape_string_in(&self) -> ICapeString

Convert to ICapeString
Source§

impl CapeStringProviderOut for CapeStringImpl

Source§

fn as_cape_string_out(&mut self) -> ICapeString

Convert to ICapeString
Source§

impl Clone for CapeStringImpl

Source§

fn clone(&self) -> CapeStringImpl

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CapeStringImpl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CapeStringImpl

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for CapeStringImpl

Source§

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<T: AsRef<str>> From<T> for CapeStringImpl

Source§

fn from(s: T) -> Self

Converts to this type from the input type.
Source§

impl Hash for CapeStringImpl

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: CapeStringConstProvider> PartialEq<T> for CapeStringImpl

Source§

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);
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for CapeStringImpl

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.