Struct CapeStringConstNoCase

Source
pub struct CapeStringConstNoCase {
    data: Vec<CapeCharacter>,
}
Expand description

Class to store a platform dependent string encoding for use in case insensitive hash maps or for use of case insensitive comparisons.

For COBIA, strings go over the pipeline as null terminated. For Windows, COBIA requires UTF-16 encoding.

Because this translation is always required, there is no read-only string implementation that refers to a string slice. However, this string implementation is immutable and can therefore be used as static.

This implementation uses a Vec<u16> to store the string data.

A common use case in CAPE-OPEN is to to have a string constant for comparison with CapeString-like objects. This class is a
specialization for this purpose: the string is stored in lower case, and PartialEq does case insensitive comparison.

Another common use case in CAPE-OPEN is to make hash maps of strings for case-insentive lookups. A specialized class is available for this purpose: CapeStringHashKey.

PartialEq can be directly used to for a CapeStringConstNoCase on the left, and any object implementing CapeStringConstProvider on the right (but not vice versa)

§Examples

use cobia::*;
use cobia::prelude::*;
let s=cobia::CapeStringConstNoCase::from_string("idealGasEnthalpy");
let s2=cobia::CapeStringImpl::from_string("IDEALGASENTHALPY");
assert_eq!(s,s2);

fn test_eq(s:CapeStringConstNoCase, s3:&CapeStringIn) {
	assert_eq!(&s,s3);
}

test_eq(s,&CapeStringInFromProvider::from(&s2).as_cape_string_in()); 

Fields§

§data: Vec<CapeCharacter>

Implementations§

Source§

impl CapeStringConstNoCase

Source

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

Construct from string

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

pub fn from_cape_char_const(ptr: *const CapeCharacter, size: CapeSize) -> Self

Construct from CapeCharacter pointer

§Arguments
  • ptr - A const CapeCharacter pointer
  • size - Length of the string pointed to
Source

pub fn from(s: Option<&str>) -> Self

Create a new CapeStringConstNoCase from a string.

§Arguments
  • s - A string
Source

pub fn as_string(&self) -> String

Return as string

§Examples
use cobia;
let s=cobia::CapeStringConstNoCase::from_string("idealGasEnthalpy");
assert_eq!(s.as_string(),"idealgasenthalpy"); //note that CapeStringConstNoCase stores strings in lower case
Source§

impl CapeStringConstNoCase

Trait Implementations§

Source§

impl CapeStringConstProvider for CapeStringConstNoCase

Source§

fn as_capechar_const(&self) -> *const CapeCharacter

Return as CapeCharacter const pointer

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::CapeStringConstNoCase::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§

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::CapeStringConstNoCase::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§

impl CapeStringProviderIn for CapeStringConstNoCase

Source§

fn as_cape_string_in(&self) -> ICapeString

Convert to ICapeString
Source§

impl Clone for CapeStringConstNoCase

Source§

fn clone(&self) -> Self

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 CapeStringConstNoCase

Source§

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

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

impl Display for CapeStringConstNoCase

Source§

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

Formats the CapeStringConstNoCase error using the given formatter.

§Examples
use cobia;
let s=cobia::CapeStringConstNoCase::from_string("idealGasEnthalpy");
assert_eq!(format!("{}",s),"idealgasenthalpy"); //note that CapeStringConstNoCase stores strings in lower case
Source§

impl<T: AsRef<str>> From<T> for CapeStringConstNoCase

Source§

fn from(s: T) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
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 CapeStringConstNoCase

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.