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.

Methods

  • publicConstString()
  • public ConstString(
    • const char * a )
  • public charat(const arg::ImplicitPosition position) const
  • public inline floatatoff() const
  • public inline intatoi() const
  • public intcompare(const arg::StringToCompare a) const
  • public intcompare(const arg::Position position,const arg::Length length,const arg::StringToCompare s) const
  • public intcompare(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
  • public const char * cstring() const
  • public u32 find(
    • const arg::CharacterToFind a,
    • const arg::Position pos
    • ) const
  • public u32 find(
    • const arg::StringToFind a,
    • const arg::Position pos
    • ) const
  • public u32 find(const arg::StringToFind a,arg::Position pos,const arg::Length length) const
  • public u32find_not(const arg::CharacterToFind a,const arg::Position pos) const
  • public inline boolis_empty() const
  • public inline u32length() const
  • public inline booloperator!=(constConstString& a) const
  • public inline booloperator<(constConstString& a) const
  • public inline booloperator<=(constConstString& a) const
  • public inlineConstString&operator=(const char * a)
  • public inline booloperator==(constConstString& a) const
  • public inline booloperator>(constConstString& a) const
  • public inline booloperator>=(constConstString& a) const
  • public inline charoperator[](u32 idx) const
  • public u32rfind(const arg::StringToFind a,const arg::Position pos) const
  • public u32rfind(const arg::CharacterToFind c,const arg::Position position) const
  • public u32rfind(const arg::StringToFind a,const arg::Position position,arg::Length length) const
  • public floatto_float() const
  • public inline intto_integer() const
  • public inline intto_long(const arg::NumberBase base)
  • public inline intto_unsigned_long(const arg::NumberBase base)
  • protected voidset_string_pointer(const char * s)
  • enum@26

Details

publicConstString()

publicConstString(const char * a)

Constructs a ConstString from a pointer to a string of zero-terminated characters.


public charat(const arg::ImplicitPosition position) const

Returns character at pos.

Returns 0 if pos is past the end of the string.


public inline floatatoff() const

public inline intatoi() const

public intcompare(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 string_to_compare,
const arg::MatchLength match_length
) const

Compares this string to string_to_compare.

Parameters

  • position The position in this object to start the comparison
  • length The number of characters to compare
  • string_to_compare A reference to the comparing string
  • match_length Length to match (length by default)

Returns

Zero if the strings match

var::ConstString first = "HelloWorld";
var::ConstString second = "Hello";

if( first.compare(
    arg::Position(0),
    arg::Length(3),
    arg::StringToCompare(second),
    arg::MatchLength(2)
    )
  ){
  //up to first 3 bytes of 
  //first matches first 2 bytes of second
}

public intcompare(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


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

public inline const char *cstring() const

Returns a c-style string pointer.


public u32find(const arg::CharacterToFind a,const arg::Position pos) const

Finds a character within the object.


public u32find(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


public u32find(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


public u32find_not(const arg::CharacterToFind a,const arg::Position pos) const

Finds a character within the object.


public inline boolis_empty() const

Tests if string is empty.


public inline u32length() const

Returns the length of the string.


public inline booloperator!=(constConstString& a) const

Compares to a c-string (inequality).


public inline booloperator<(constConstString& a) const

public inline booloperator<=(constConstString& a) const

public inlineConstString&operator=(const char * a)

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


public inline booloperator==(constConstString& a) const

Compares to a c-string.


public inline booloperator>(constConstString& a) const

public inline booloperator>=(constConstString& a) const

public inline charoperator[](u32 idx) const

Access a byte from the string.

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


public u32rfind(const arg::StringToFind a,const arg::Position pos) const

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


public u32rfind(const arg::CharacterToFind c,const arg::Position position) const

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


public u32rfind(const arg::StringToFind a,const arg::Position position,arg::Length length) const

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


public floatto_float() const

Converts to a float.


public inline intto_integer() const

Converts to an integer.

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

public inline intto_long(const arg::NumberBase base)

public inline intto_unsigned_long(const arg::NumberBase base)

protected voidset_string_pointer(const char * s)

enum@26
  • npos Defines an invalid string length and position

X

Thanks for Coming!

Subscribe to news and updates