This add-on registers a string type that is in most situations compatible with the std::string, except that it uses reference counting. This means that if you have an application function that takes a std::string by reference, you can register it with AngelScript to take a script string by reference. This works because the CScriptString wraps the std::string type, with the std::string type at the first byte of the CScriptString object.
Register the type with RegisterScriptString(asIScriptEngine*). Register the utility functions with RegisterScriptStringUtils(asIScriptEngine*).
class CScriptString { public: // Constructors CScriptString(); CScriptString(const CScriptString &other); CScriptString(const char *s); CScriptString(const std::string &s); // Memory management void AddRef(); void Release(); // Assignment CScriptString &operator=(const CScriptString &other); // Concatenation CScriptString &operator+=(const CScriptString &other); friend CScriptString *operator+(const CScriptString &a, const CScriptString &b); // Memory buffer std::string buffer; };
class string
{
// Constructors
string();
string(const string &in other);
// Returns the length of the string
uint length() const;
// Assignment and concatenation
string &opAssign(const string &in other);
string &opAddAssign(const string &in other);
string @opAdd(const string &in right) const;
// Access individual characters
// uint8 &operator [] (uint)
// const uint8 &operator [] (uint) const
// Comparison operators
bool opEquals(const string &in right) const;
int opCmp(const string &in right) const;
// Automatic conversion from number types to string type
string &opAssign(double val);
string &opAddAssign(double val);
string @opAdd(double val) const;
string @opAdd_r(double val) const;
string &opAssign(float val);
string &opAddAssign(float val);
string @opAdd(float val) const;
string @opAdd_r(float val) const;
string &opAssign(int val);
string &opAddAssign(int val);
string @opAdd(int val) const;
string @opAdd_r(int val) const;
string &opAssign(uint val);
string &opAddAssign(uint val);
string @opAdd(uint val) const;
string @opAdd_r(uint val) const;
}
// Get a substring of a string string @ substring(const string &in str, int start, int length);
// Find the first occurrance of the substring int findFirst(const string &in str, const string &in sub); int findFirst(const string &in str, const string &in sub, int startAt)
// Find the last occurrance of the substring int findLast(const string &in str, const string &in sub); int findLast(const string &in str, const string &in sub, int startAt);
// Find the first character from the set int findFirstOf(const string &in str, const string &in set); int findFirstOf(const string &in str, const string &in set, int startAt);
// Find the first character not in the set int findFirstNotOf(const string &in str, const string &in set); int findFirstNotOf(const string &in str, const string &in set, int startAt);
// Find the last character from the set int findLastOf(const string &in str, const string &in set); int findLastOf(const string &in str, const string &in set, int startAt);
// Find the last character not in the set int findLastNotOf(const string &in str, const string &in set); int findLastNotOf(const string &in str, const string &in set, int startAt);
// Split the string into an array of substrings string@[]@ split(const string &in str, const string &in delimiter);
// Join an array of strings into a larger string separated by a delimiter string@ join(const string@[] &in str, const string &in delimiter);
1.5.9