String object/class Functions Documentation
Below are the available functions for the "string" classes that are available in CANCapture's script function blocks.
string Class - this object represents an ASCII string. It is very similar to the C++ standard template std::string class and all functions are named and used similarly. These functions are only available in V2.47 and later. Portions of the descriptions and function declarations are taken from http://www.cplusplus.com/reference/string/string/
index [] operator
The string object supports indexing of the string. For example,
str[5] = 0; uint8 x = str[4];
index + and index += operator
The string object supports the + and += operator for most datatypes. For example,
str = "x is equal to " + x + "\n";
uint length()
Retrieves the length of a string. This is the amount of actual characters before the end of the string or NULL terminator is reached. This is the same as the size member function.
uint size()
Retrieves the length of a string. This is the amount of actual characters before the end of the string or NULL terminator is reached. This is the same as the length member function.
void clear()
Clears all the characters in the string and sets it to the empty string
bool empty() const
Returns whether or not the string is empty
uint find(const string &in str, uint pos) const
Searches the string for the content specified in str and returns the position of the first occurrence in the string.
When pos is specified the search only includes characters on or after position pos, ignoring any possible occurrences in previous locations.
Notice that unlike member find_first_of, whenever more than one character is being searched for, it is not enough that only one of these characters match, but the entire sequence of characters to find must be matched.
uint rfind(const string &in str, uint pos) const
Searches the string for the content specified in str and returns the position of the last occurrence in the string.
When pos is specified, the search only includes characters between the beginning of the string and position pos, ignoring any possible occurrences after pos.
uint find_first_not_of(const string &in str, uint pos) const
Searches for the first character in the object which is not part of str and returns its position.
When pos is specified the search only includes characters on or after position pos, ignoring any content in the previous character positions.
uint find_first_of(const string &in str, uint pos) const
Searches the string for any of the characters that are part of str and returns the position of the first occurrence in the string.
When pos is specified the search only includes characters on or after position pos, ignoring any possible occurrences at previous character positions.
Notice that for a match to happen it is enough that one of the characters matches in the string (any of them). To search for an entire sequence of characters use find instead.
uint find_last_of(const string &in str, uint pos) const
Searches the string from the end for any of the characters that are part of str and returns the position of the last occurrence in the string.
When pos is specified the search only includes characters on or before position pos, ignoring any possible occurrences at character positions after it.
Notice that for a match to happen is enough that one of the characters matches in the string (any of them). To search from the end for an entire sequence of characters use rfind instead.
uint find_last_not_of(const string &in str, uint pos) const
Searches for the last character in the object which is not part of str and returns its position.
When pos is specified the search only includes characters on or before position pos, ignoring any content in the character positions after it.
string &replace(uint pos, uint count, const string &in str)
Replaces a section of the current string by some other content determined by the arguments passed.
pos identifies the starting position and count identifies the length of characters that will be replaced by str
string &erase(uint pos, uint count)
Erases a part of the string content, shortening the length of the string. Erases a sequence of count characters starting at position pos.
string &append(const string &in str)
The current string content is extended by adding a copy of str at its end.
int compare(const string &in str) const
Compares the content of this object to the content of the comparing str.
The member function returns 0 if all the characters in the compared contents compare equal, a negative value if the first character that does not match compares to less in the object than in the comparing str, and a positive value in the opposite case.
Notice that for string objects, the result of a character comparison depends only on its character code (i.e., its ASCII code), so the result has some limited alphabetical or numerical ordering meaning.
string &insert(uint pos, const string &in str)
The current string content is extended by inserting some additional content in str at a specific location within the string content at the location of pos.
uint max_size() const
Returns the maximum number of characters that the string object can hold.
uint capacity() const
Returns the size of the allocated storage space in the string object.
Notice that the capacity is not necessarily equal to the number of characters that conform the content of the string (this can be obtained with members size or length), but the capacity of the allocated space, which is either equal or greater than this content size.
Notice also that this capacity does not suppose a limit to the length of the string. If more space is required to accomodate content in the string object, the capacity is automatically expanded, or can even be explicitly modified by calling member reserve.
The real limit on the size a string object can reach is returned by member max_size.
void swap(string &inout str)
Swaps the contents of the string with those of string object str, such that after the call to this member function, the contents of this string are those which were in str before the call, and the contents of str are those which were in this string.
void resize(uint n)
Resizes the string content to n characters.
If n is smaller than the current length of the string, the content is reduced to its first n characters, the rest being dropped.
If n is greater than the current length of the string, the content is expanded by appending as many instances of the NULL character as needed to reach a size of n characters.
void reserve(uint count)
Requests that the capacity of the allocated storage space in the string be at least count.
This can expand or shrink the size of the storage space in the string, although notice that the resulting capacity after a call to this function is not necessarily equal to count but can be either equal or greater than count, therefore shrinking requests may or may not produce an actual reduction of the allocated space in a particular library implementation. In any case, it never trims the string content (for that purposes, see resize or clear, which modify the content).
double toDouble(uint pos) const
Returns the representative double value of the characters located in the string at offset of pos.
double toUInt(uint pos) const
Returns the representative uint value of the characters located in the string at offset of pos.
double toInt(uint pos) const
Returns the representative int value of the characters located in the string at offset of pos.