class::var::ConstString

class var::ConstString
  : public api::VarWorkObject

The ConstString class is basically just a pointer to a string literal with methods added that make immuatable strings easier to work with (as compared to C).

Here are a few examples

//comparing strings

const char * c_str0 = "hello";
const char * c_str1 = "world";
ConstString const_string0 = "hello";
ConstString const_string1 = "world";

if (strcmp(c_str0, c_str1) == 0 ){
  //they are the same
}

if( const_string0 == const_string1 ){
 //they are the same
}

//finding strings

if( const_string1.find("worl") == 0 ){
 //const_string1 starts with "worl"
}

//converting to numbers
ConstString number_string = "123";

printf("Number string is %d\n", number_string.atoi());

The class var::String inherits ConstString and adds the ability to dyncamically allocate and modify strings.

Members

ConstString()
ConstString(

const char * a
)

char at(

const arg::ImplicitPosition position
) const

int compare(

const arg::StringToCompare a
) const

int compare(

const arg::Position position,
const arg::Length length,
const arg::StringToCompare s
) const

int compare(

const arg::Position position,
const arg::Length length,
const arg::StringToCompare string_to_compare,
const arg::SubPosition sub_position,
const arg::MatchLength match_length
) const

int compare(

const arg::Position position,
const arg::Length length,
const arg::StringToCompare string_to_compare,
const arg::MatchLength match_length
) const

const char * cstring() const
u32 find(

const arg::CharacterToFind a,
const arg::Position pos
) const

u32 find(

const arg::StringToFind a,
const arg::Position pos
) const

u32 find(

const arg::StringToFind a,
arg::Position pos,
const arg::Length length
) const

u32 find_not(

const arg::CharacterToFind a,
const arg::Position pos
) const

bool is_empty() const
u32 length() const
bool operator!=(

const ConstString & a
) const

bool operator<(

const ConstString & a
) const

bool operator<=(

const ConstString & a
) const

ConstString & operator=(

const char * a
)

bool operator==(

const ConstString & a
) const

bool operator>(

const ConstString & a
) const

bool operator>=(

const ConstString & a
) const

char operator[](

u32 position
) const

u32 rfind(

const arg::StringToFind a,
const arg::Position pos
) const

u32 rfind(

const arg::CharacterToFind c,
const arg::Position position
) const

u32 rfind(

const arg::StringToFind a,
const arg::Position position,
arg::Length length
) const

float to_float() const
int to_integer() const
int to_long(

const arg::NumberBase base
)

int to_unsigned_long(

const arg::NumberBase base
)

protected void set_string_pointer(

const char * s
)

enum npos

Details

ConstString()

Constructs an empty string.


ConstString(

const char * a
)

Constructs a ConstString from a pointer to a string of zero-terminated characters (c-style string).

ConstString hello("Hello");

char at(

const arg::ImplicitPosition position
) const

Returns character at the specified position.

Returns

0 if pos is past the end of the string.

ConstString hello("hello");
printf("First character is %c\n", hello.at(0));
printf("Second character is %c\n",
  hello.at(arg::Position(1))
  );

int compare(

const arg::StringToCompare a
) const

Compares the object to str.

Parameters

  • str A reference comparing string

Returns

Zero if the strings are the same


int compare(

const arg::Position position,
const arg::Length length,
const arg::StringToCompare s
) const

Compares the object to str.

Parameters

  • pos The position in this object to start the comparison

  • len The number of characters to compare

  • str A reference to the comparing string

Returns

Zero if the strings match


int compare(

const arg::Position position,
const arg::Length length,
const arg::StringToCompare string_to_compare,
const arg::SubPosition sub_position,
const arg::MatchLength match_length
) const

Compares the object to str.

Parameters

  • pos The position in this object to start the comparison

  • len The length of the compared string (this object)

  • str A reference to the comparing string

  • subpos The position in the comparing string to start comparing

  • n The number string characters to compare

Returns

Zero if the strings match


int compare(

const arg::Position position,
const arg::Length length,
const arg::StringToCompare string_to_compare,
const arg::MatchLength match_length
) const


const char * cstring() const

Returns a c-style string pointer.


u32 find(

const arg::CharacterToFind a,
const arg::Position pos
) const

Finds a character within this string.


u32 find(

const arg::StringToFind a,
const arg::Position pos
) const

Finds a var::ConstString within the object.

Parameters

  • a The String to find

  • pos The position to start searching (default is beginning)

Returns

The position of the string or var::String::npos if the String was not found


u32 find(

const arg::StringToFind a,
arg::Position pos,
const arg::Length length
) const

Finds a string within the object.

Parameters

  • a A reference to the string to search for

  • pos Where in this string to start looking

  • n The number of bytes to match

Returns

The offset in this string where the match occurred or npos if a was not found


u32 find_not(

const arg::CharacterToFind a,
const arg::Position pos
) const

Finds the first character that is not as specified.


bool is_empty() const

Tests if string is empty.

ConstString x;
if( x.is_empty() ){
  //we arrive here
}

u32 length() const

Returns the length of the string.

The string must be null-terminated.

ConstString testing("testing");
printf("length is %d\n", testing.length());

bool operator!=(

const ConstString & a
) const

Compares to a c-string (inequality).


bool operator<(

const ConstString & a
) const


bool operator<=(

const ConstString & a
) const


ConstString & operator=(

const char * a
)

Points the ConstString to a new string of zero-terminated characters.


bool operator==(

const ConstString & a
) const

Compares to another ConstString.

ConstString a("hello");
ConstString b("world");

if( a == b ){
  //won't get here
}

bool operator>(

const ConstString & a
) const


bool operator>=(

const ConstString & a
) const


char operator[](

u32 position
) const

Access a byte from the string.

This operator does not check the bounds of the access. The at() method checks the bounds.


u32 rfind(

const arg::StringToFind a,
const arg::Position pos
) const

Finds a string within the string searching from right to left.


u32 rfind(

const arg::CharacterToFind c,
const arg::Position position
) const

Finds a character within the string searching from right to left.


u32 rfind(

const arg::StringToFind a,
const arg::Position position,
arg::Length length
) const

Finds a string within the string searching from right to left.


float to_float() const

Converts to a float.

ConstString pi = "3.14";
printf("pi is %0.2f\n", pi.to_float());

int to_integer() const

Converts the string to an integer.

ConstString x = "10";
printf("X is %d\n", x.to_integer());

int to_long(

const arg::NumberBase base
)

Converts the string to a long integer using the specified number base.

ConstString number("1000");
printf("Number is 0x%X\n",
  number.to_long(
    NumberBase(10)
    )
  );

int to_unsigned_long(

const arg::NumberBase base
)

Converts the string to a long integer using the specified number base.

ConstString number("DEADBEEF");
printf("Number is 0x%X\n",
  number.to_long(
    NumberBase(16)
    )
  );

protected void set_string_pointer(

const char * s
)


enum npos
  • npos Defines an invalid string length and position

X

Thanks for Coming!

Subscribe to news and updates