nString Class Reference
[Data Types]
#include <nstring.h>
Detailed Description
A simple Nebula string class.Very handy when strings must be stored or manipulated. Note that many Nebula interfaces hand strings around as char pointers, not nString objects.
The current implementation does not allocate extra memory if the string has less then 13 characters.
(C) 2001 RadonLabs GmbH
Definition at line 34 of file nstring.h.
Public Member Functions | |
| nString () | |
| constructor | |
| nString (const char *str) | |
| constructor 1 | |
| nString (const nString &rhs) | |
| copy constructor | |
| ~nString () | |
| destructor | |
| nString & | operator= (const nString &rhs) |
| = operator | |
| nString & | operator= (const char *rhs) |
| = operator with string | |
| nString & | operator+= (const char *rhs) |
| += operator with char* | |
| nString & | operator+= (const nString &rhs) |
| += operator with string | |
| char | operator[] (int i) const |
| Subscript operator (read only). | |
| char & | operator[] (int i) |
| Subscript operator (writable). | |
| void | Set (const char *ptr, int length) |
| set as char ptr, with explicit length | |
| void | Set (const char *str) |
| set as char ptr | |
| void | SetInt (int val) |
| set as int value | |
| void | SetFloat (float val) |
| set as float value | |
| void | SetBool (bool val) |
| set as bool value | |
| void | SetVector3 (const vector3 &v) |
| set as vector3 value | |
| void | SetVector4 (const vector4 &v) |
| set as vector4 value | |
| void | SetMatrix44 (const matrix44 &m) |
| set as matrix44 value | |
| const char * | Get () const |
| get string as char ptr | |
| int | AsInt () const |
| return contents as integer | |
| float | AsFloat () const |
| return contents as float | |
| bool | AsBool () const |
| return contents as bool | |
| vector3 | AsVector3 () const |
| return contents as vector3 | |
| vector4 | AsVector4 () const |
| return contents as vector4 | |
| matrix44 | AsMatrix44 () const |
| return contents as matrix44 | |
| bool | IsValidInt () const |
| return true if the content is a valid integer | |
| bool | IsValidFloat () const |
| return true if the content is a valid float | |
| bool | IsValidBool () const |
| return true if the content is a valid bool | |
| bool | IsValidVector3 () const |
| return true if the content is a valid vector3 | |
| bool | IsValidVector4 () const |
| return true if the content is a valid vector4 | |
| bool | IsValidMatrix44 () const |
| return true if content is a valid matrix44 | |
| int | Length () const |
| return length of string | |
| void | Clear () |
| clear the string | |
| bool | IsEmpty () const |
| return true if string object is empty | |
| bool | IsValid () const |
| return true if string object is not empty | |
| void | Append (const char *str) |
| append character pointer | |
| void | Append (const nString &str) |
| append string | |
| void | AppendRange (const char *str, uint numChars) |
| append a range of characters | |
| void | AppendInt (int val) |
| append int value | |
| void | AppendFloat (float val) |
| append float value | |
| void | ToLower () |
| convert string to lower case | |
| void | ToUpper () |
| convert string to upper case | |
| const char * | GetFirstToken (const char *whiteSpace) |
| *** OBSOLETE *** get first token (this will destroy the string) | |
| const char * | GetNextToken (const char *whiteSpace) |
| *** OBSOLETE *** get next token (this will destroy the string) | |
| int | Tokenize (const char *whiteSpace, nArray< nString > &tokens) const |
| tokenized string into a provided nString array | |
| int | Tokenize (const char *whiteSpace, uchar fence, nArray< nString > &tokens) const |
| tokenized string, keep strings within fence characters intact | |
| nString | ExtractRange (int from, int numChars) const |
| extract substring | |
| void | Strip (const char *charSet) |
| terminate string at first occurrence of character in set | |
| int | FindStringIndex (const nString &v, int startIndex) const |
| Index of first appearance of `v' starting from index `startIndex'. | |
| int | FindCharIndex (unsigned char c, int startIndex) const |
| return index of character in string | |
| void | TerminateAtIndex (int index) |
| terminate string at given index | |
| bool | ContainsCharFromSet (const char *charSet) const |
| returns true if string contains character from set | |
| void | StripTrailingSlash () |
| strip slash at end of path, if exists | |
| nString | TrimLeft (const char *charSet) const |
| delete characters from charset at left side of string | |
| nString | TrimRight (const char *charSet) const |
| delete characters from charset at right side of string | |
| nString | Trim (const char *charSet) const |
| trim characters from charset at both sides of string | |
| nString | Substitute (const char *str, const char *substStr) const |
| substitute every occurrence of a string with another string | |
| void | SubstituteCharacter (char c, char subst) |
| substitute every occurrence of a character with another character | |
| void | UTF8toANSI () |
| convert string in place from UTF-8 to 8-bit ANSI | |
| void | ANSItoUTF8 () |
| convert ANSI to UTF-8 in place | |
| const char * | GetExtension () const |
| get pointer to extension (without the dot) | |
| bool | CheckExtension (const char *ext) const |
| check if extension matches (no dot in the extension!) | |
| void | ConvertBackslashes () |
| convert backslashes to slashes | |
| void | StripExtension () |
| remove extension | |
| nString | ExtractFileName () const |
| extract the part after the last directory separator | |
| nString | ExtractLastDirName () const |
| extract the last directory of the path | |
| nString | ExtractDirName () const |
| extract the part before the last directory separator | |
| nString | ExtractToLastSlash () const |
| extract path until last slash | |
| bool | MatchPattern (const nString &pattern) const |
| check if this string matches the given pattern | |
| void | Format (const char *fmtString,...) |
| format string printf-style | |
| void | FormatWithArgs (const char *fmtString, va_list args) |
| format string printf-style, taking a va_list | |
| void | ReplaceIllegalFilenameChars (char replacement) |
| replace illegal filename characters | |
| bool | CheckValidCharSet (const nString &charSet) const |
| return true if string only contains characters from charSet argument | |
| void | ReplaceChars (const char *charSet, char replacement) |
| replace characters within a string | |
Static Public Member Functions | |
| static nString | Concatenate (const nArray< nString > &strArray, const nString &whiteSpace) |
| concatenate array of strings into new string | |
| static nString | FromInt (int i) |
| construct a string from an int | |
| static nString | FromFloat (float f) |
| construct a string from a float | |
| static nString | FromBool (bool b) |
| construct a string from a bool | |
| static nString | FromVector3 (const vector3 &v) |
| construct a string from vector3 | |
| static nString | FromVector4 (const vector4 &v) |
| construct a string from vector4 | |
| static nString | FromMatrix44 (const matrix44 &m) |
| construct a string from matrix44 | |
Protected Types | |
| enum | { LOCALSTRINGSIZE = 14 } |
Protected Member Functions | |
| void | Copy (const nString &src) |
| copy contents | |
| void | Delete () |
| delete contents | |
| char * | GetLastSlash () const |
| get pointer to last directory separator | |
| size_t | GetFormattedStringLength (const char *format, va_list argList) const |
| calculate required length for the result of a printf-style format | |
| void | SetLength (int) |
| Set the length, accounting for the union. | |
Protected Attributes | |
| char * | string |
| char | localString [LOCALSTRINGSIZE] |
| ushort | localStrLen |
| uint | strLen |
Friends | |
| bool | operator== (const nString &a, const nString &b) |
| Is `a' equal to `b'? | |
| bool | operator!= (const nString &a, const nString &b) |
| Is `a' unequal to `b'? | |
| bool | operator< (const nString &a, const nString &b) |
| Is `a' smaller than `b'? | |
| bool | operator> (const nString &a, const nString &b) |
| Is `a' greater than `b'? | |
| bool | operator<= (const nString &a, const nString &b) |
| Is `a' smaller than or equal to `b'? | |
| bool | operator>= (const nString &a, const nString &b) |
| Is `a' greater than or equal to `b'? | |
Member Enumeration Documentation
|
|
|
Constructor & Destructor Documentation
|
|
constructor
|
|
|
constructor 1
|
|
|
copy constructor
|
|
|
destructor
|
Member Function Documentation
|
|
= operator
|
|
|
= operator with string
|
|
|
+= operator with char*
|
|
|
+= operator with string
|
|
|
Subscript operator (read only).
|
|
|
Subscript operator (writable).
|
|
||||||||||||
|
set as char ptr, with explicit length
|
|
|
set as char ptr
|
|
|
set as int value
|
|
|
set as float value
|
|
|
set as bool value
|
|
|
set as vector3 value
|
|
|
set as vector4 value
|
|
|
set as matrix44 value
|
|
|
get string as char ptr
|
|
|
return contents as integer Returns content as integer. Note: this method doesn't check whether the contents is actually a valid integer. Use the IsValidInteger() method for this! |
|
|
return contents as float Returns content as float. Note: this method doesn't check whether the contents is actually a valid float. Use the IsValidInt() method for this! |
|
|
return contents as bool
|
|
|
return contents as vector3 Returns content as vector3. Note: this method doesn't check whether the contents is actually a valid vector3. Use the IsValidVector3() method for this! |
|
|
return contents as vector4 Returns content as vector4. Note: this method doesn't check whether the contents is actually a valid vector4. Use the IsValidVector4() method for this! |
|
|
return contents as matrix44 Returns content as matrix44. Note: this method doesn't check whether the contents is actually a valid matrix44. Use the IsValidMatrix44() method for this! |
|
|
return true if the content is a valid integer
|
|
|
return true if the content is a valid float Note: this method is not 100% correct, it just checks for invalid characters. |
|
|
return true if the content is a valid bool
|
|
|
return true if the content is a valid vector3 Note: this method is not 100% correct, it just checks for invalid characters. |
|
|
return true if the content is a valid vector4 Note: this method is not 100% correct, it just checks for invalid characters. |
|
|
return true if content is a valid matrix44 Note: this method is not 100% correct, it just checks for invalid characters. |
|
|
return length of string
|
|
|
clear the string
|
|
|
return true if string object is empty
|
|
|
return true if string object is not empty
|
|
|
append character pointer
|
|
|
append string
|
|
||||||||||||
|
append a range of characters
|
|
|
append int value
|
|
|
append float value
|
|
|
convert string to lower case
|
|
|
convert string to upper case
|
|
|
*** OBSOLETE *** get first token (this will destroy the string) Get the first token in the string, delimited by one or more of the character in 'whiteSpace'. This simply invokes the strtok() function internally, and will destroy the contained string. After calling GetFirstToken(), invoke GetNextToken() until 0 returns. ATTENTION: if somebody else calls strtok() while GetFirstToken()/ GetNextToken() is underway, everything will break apart! Check out the Tokenize() method for a better alternative.
|
|
|
*** OBSOLETE *** get next token (this will destroy the string) Get the next token in the string. Call this after a GetFirstToken() or GetNextToken(). Returns 0 if no more tokens in string. This method will destroy the original string. ATTENTION: if somebody else calls strtok() while GetFirstToken()/ GetNextToken() is underway, everything will break apart! Check out the Tokenize() method for a better alternative.
|
|
||||||||||||
|
tokenized string into a provided nString array Tokenize the string into a provided nString array. Returns the number of tokens. This method is recommended over GetFirstToken()/GetNextToken(), since it is atomic. This nString object will not be destroyed (as is the case with GetFirstToken()/GetNextToken().
|
|
||||||||||||||||
|
tokenized string, keep strings within fence characters intact Tokenize a string, but keeps the string within the fence-character intact. For instance for the sentence: He said: "I don't know." A Tokenize(" ", '"', tokens) would return: token 0: He token 1: said: token 2: I don't know. |
|
||||||||||||
|
extract substring Extract sub string. |
|
|
terminate string at first occurrence of character in set Terminates the string at the first occurrence of one of the characters in charSet. |
|
||||||||||||
|
Index of first appearance of `v' starting from index `startIndex'.
|
|
||||||||||||
|
return index of character in string Return index of character in string, or -1 if not found. |
|
|
terminate string at given index Terminates the string at the given index. |
|
|
returns true if string contains character from set Returns true if string contains one of the characters from charset. |
|
|
strip slash at end of path, if exists Strips last slash, if the path name ends on a slash. |
|
|
delete characters from charset at left side of string Returns a new string which is this string, stripped on the left side by all characters in the char set. |
|
|
delete characters from charset at right side of string Returns a new string, which is this string, stripped on the right side by all characters in the char set. |
|
|
trim characters from charset at both sides of string Trim both sides of a string. |
|
||||||||||||
|
substitute every occurrence of a string with another string Substitute every occurrence of origStr with substStr. |
|
||||||||||||
|
substitute every occurrence of a character with another character Replace character with another. |
|
|
convert string in place from UTF-8 to 8-bit ANSI This converts an UTF-8 string to 8-bit-ANSI. Note that only characters in the range 0 .. 255 are converted, all other characters will be converted to a question mark. For conversion rules see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
|
convert ANSI to UTF-8 in place Convert contained ANSI string to UTF-8 in place. |
|
|
get pointer to extension (without the dot)
|
|
|
check if extension matches (no dot in the extension!) Returns true if file extension matches.
|
|
|
convert backslashes to slashes Converts backslashes to slashes. |
|
|
remove extension Remove the file extension. |
|
|
extract the part after the last directory separator Return a nString object containing the part after the last path separator. |
|
|
extract the last directory of the path Return a nString object containing the last directory of the path, i.e. a category.
|
|
|
extract the part before the last directory separator Return a nString object containing the part before the last directory separator. NOTE: I left my fix in that returns the last slash (or colon), this was necessary to tell if a dirname is a normal directory or an assign.
|
|
|
extract path until last slash Return a path string object which contains of the complete path up to the last slash. Returns an empty string if there is no slash in the path. |
|
|
check if this string matches the given pattern
|
|
||||||||||||
|
format string printf-style
|
|
||||||||||||
|
format string printf-style, taking a va_list
|
|
|
replace illegal filename characters
|
|