ChaiScript
Public Member Functions | List of all members
ChaiScript_Language::string Class Reference

ChaiScript representation of std::string. More...

#include <chaiscript_prelude_docs.hpp>

Public Member Functions

int find (string s) const
 Finds the first instance of substr. More...
 
int rfind (string s) const
 Finds the last instance of substr. More...
 
int find_first_of (string list) const
 Finds the first of characters in list in the string. More...
 
int find_last_of (string list) const
 Finds the last of characters in list in the string. More...
 
int find_first_not_of (string list) const
 Finds the first non-matching character to list in the str string. More...
 
int find_last_not_of (string list) const
 Finds the last non-matching character to list in the list string. More...
 
string lstrim () const
 Removes whitespace from the front of the string, returning a new string. More...
 
string rtrim () const
 Removes whitespace from the back of the string, returning a new string. More...
 
string trim () const
 Removes whitespace from the front and back of the string, returning a new string. More...
 
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. More...
 
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

◆ find()

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

Finds the first instance of substr.

eval> find("abab", "ab")
0

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ rfind()

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

Finds the last instance of substr.

eval> rfind("abab", "ab")
2

◆ 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|
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|

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

See also
def

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