GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
ChaiScript_Language::string Class Reference

ChaiScript representation of std::string. It is an std::string but only some member are exposed to ChaiScript. More...

#include <chaiscript_prelude_docs.hpp>

Public Member Functions

int find (string s) const
 Finds the first instance of substr.
int rfind (string s) const
 Finds the last instance of substr.
int find_first_of (string list) const
 Finds the first of characters in list in the string.
int find_last_of (string list) const
 Finds the last of characters in list in the string.
int find_first_not_of (string list) const
 Finds the first non-matching character to list in the str string.
int find_last_not_of (string list) const
 Finds the last non-matching character to list in the list string.
string lstrim () const
 Removes whitespace from the front of the string, returning a new string.
string rtrim () const
 Removes whitespace from the back of the string, returning a new string.
string trim () const
 Removes whitespace from the front and back of the string, returning a new string.
const char & operator[] (int t_index) const
 Returns the character at the given index in the string, const version.
char & operator[] (int t_index)
 Returns the character at the given index in the string.
const char * c_str () const
 Returns underlying const char * for C api compatibility.
const char * data () const
 Returns a pointer to the raw data in the string.
void clear ()
 Resets the string to empty.
bool empty () const
 Returns true if the string is empty.
int size () const
 Returns the size of the string in bytes.
Range range ()
 Returns an object that implements the Range concept for the characters of this string.
Const_Range range () const
 Returns an object that implements the Const_Range concept for the characters of this string.

Detailed Description

ChaiScript representation of std::string. It is an std::string but only some member are exposed to ChaiScript.

Because the ChaiScript string object is an std::string, it is directly convertible to and from std::string using the chaiscript::boxed_cast and chaiscript::var functions.

With the exception of string::trim, string::rtrim, string::ltrim, all members are direct pass-throughs to the std::string of the same name.

Note
Object and function notations are equivalent in ChaiScript. This means that "bob".find("b") and find("bob", "b") are exactly the same. Most examples below follow the second formation of the function calls.
See also
def for extending existing C++ classes in ChaiScript
chaiscript::bootstrap::standard_library::string_type

Member Function Documentation

◆ c_str()

const char * ChaiScript_Language::string::c_str ( ) const

Returns underlying const char * for C api compatibility.

◆ clear()

void ChaiScript_Language::string::clear ( )

Resets the string to empty.

◆ data()

const char * ChaiScript_Language::string::data ( ) const

Returns a pointer to the raw data in the string.

◆ empty()

bool ChaiScript_Language::string::empty ( ) const

Returns true if the string is empty.

◆ find()

int ChaiScript_Language::string::find ( string s) const

Finds the first instance of substr.

eval> find("abab", "ab")
0
int find(string s) const
Finds the first instance of substr.

◆ find_first_not_of()

int ChaiScript_Language::string::find_first_not_of ( string list) const

Finds the first non-matching character to list in the str string.

eval> find_first_not_of("abcd", "fec")
0
int find_first_not_of(string list) const
Finds the first non-matching character to list in the str string.

◆ find_first_of()

int ChaiScript_Language::string::find_first_of ( string list) const

Finds the first of characters in list in the string.

eval> find_first_of("abab", "bec")
1
int find_first_of(string list) const
Finds the first of characters in list in the string.

◆ find_last_not_of()

int ChaiScript_Language::string::find_last_not_of ( string list) const

Finds the last non-matching character to list in the list string.

eval> find_last_not_of("abcd", "fec")
3
int find_last_not_of(string list) const
Finds the last non-matching character to list in the list string.

◆ find_last_of()

int ChaiScript_Language::string::find_last_of ( string list) const

Finds the last of characters in list in the string.

eval> find_last_of("abab", "bec")
3
int find_last_of(string list) const
Finds the last of characters in list in the string.

◆ lstrim()

string ChaiScript_Language::string::lstrim ( ) const

Removes whitespace from the front of the string, returning a new string.

Note
This function is implemented as a ChaiScript function using the def member function notation.
eval> ltrim(" bob")
bob
See also
def

◆ operator[]() [1/2]

char & ChaiScript_Language::string::operator[] ( int t_index)

Returns the character at the given index in the string.

◆ operator[]() [2/2]

const char & ChaiScript_Language::string::operator[] ( int t_index) const

Returns the character at the given index in the string, const version.

◆ range() [1/2]

Range ChaiScript_Language::string::range ( )

Returns an object that implements the Range concept for the characters of this string.

◆ range() [2/2]

Const_Range ChaiScript_Language::string::range ( ) const

Returns an object that implements the Const_Range concept for the characters of this string.

◆ rfind()

int ChaiScript_Language::string::rfind ( string s) const

Finds the last instance of substr.

eval> rfind("abab", "ab")
2
int rfind(string s) const
Finds the last instance of substr.

◆ rtrim()

string ChaiScript_Language::string::rtrim ( ) const

Removes whitespace from the back of the string, returning a new string.

Note
This function is implemented as a ChaiScript function using the def member function notation.
eval> rtrim("bob ") + "|"
bob|
string rtrim() const
Removes whitespace from the back of the string, returning a new string.
See also
def

◆ size()

int ChaiScript_Language::string::size ( ) const

Returns the size of the string in bytes.

This function normally returns size_t in C++. In ChaiScript the return value is cast to int for ease of use.

◆ trim()

string ChaiScript_Language::string::trim ( ) const

Removes whitespace from the front and back of the string, returning a new string.

Note
This function is implemented as a ChaiScript function using the def member function notation.
eval> trim(" bob ") + "|"
bob|
string trim() const
Removes whitespace from the front and back of the string, returning a new string.

Equivalent to rtrim(ltrim(" bob "));

See also
def

The documentation for this class was generated from the following file: