libUTL++
utl::Token Class Reference

Scanned token. More...

#include <Token.h>

Inheritance diagram for utl::Token:

Public Member Functions

 Token (uint_t id, const String &token, size_t lineNo, size_t colNo)
 Constructor. More...
 
virtual int compare (const Object &rhs) const
 Compare with another object. More...
 
virtual void copy (const Object &rhs)
 Copy another instance. More...
 
virtual void steal (Object &rhs)
 "Steal" the internal representation from another instance. More...
 
Accessors
uint_t id () const
 
size_t colNo () const
 
size_t lineNo () const
 
- Public Member Functions inherited from utl::String
 String (const char *s, bool owner=true, bool duplicate=true, bool caseSensitive=true)
 Constructor. More...
 
 String (size_t size)
 Constructor. More...
 
 String (char c)
 Constructor. More...
 
virtual size_t hash (size_t size) const
 Get the hash code for the object. More...
 
virtual void serialize (Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize to or from a stream. More...
 
virtual size_t innerAllocatedSize () const
 Get the "inner" allocated size. More...
 
virtual String toString () const
 Return a string representation of self. More...
 
bool isOwner () const
 Get the ownership flag. More...
 
void setOwner (bool owner)
 Set the ownership flag (without doing anything else). More...
 
bool isCaseSensitive () const
 Get the case-sensitive flag. More...
 
void setCaseSensitive (bool caseSensitive)
 Set the case-sensitive flag. More...
 
bool isMarked () const
 Get the marked flag. More...
 
void setMarked (bool marked=true)
 Set the marked flag. More...
 
int compareSubstring (size_t begin, const String &rhs, size_t n)
 Compare the given string against a substring of self. More...
 
int compareSubstring (size_t begin, const char *rhs, size_t len)
 Compare the given string against a substring of self. More...
 
int comparePrefix (const String &rhs) const
 Compare the given string against the beginning of self. More...
 
int comparePrefix (const char *rhs) const
 Compare the given string against the beginning of self. More...
 
int compareSuffix (const String &rhs) const
 Compare the given string against the end of self. More...
 
int compareSuffix (const char *rhs) const
 Compare the given string against the end of self. More...
 
int strcmp (const char *lhs, const char *rhs) const
 Compare two strings (case sensitive comparison iff isCaseSensitive()). More...
 
std::function< int(const char *, const char *)> strcmp () const
 Get the string comparison function (strcmp or strcasecmp). More...
 
int strncmp (const char *lhs, const char *rhs, size_t n) const
 Compare (up to) the first n bytes of two strings (case sensitive iff isCaseSensitive()). More...
 
std::function< int(const char *, const char *, size_t)> strncmp () const
 Get the length-limited string comparison function (strncmp or strncasecmp). More...
 
String backslashEscaped (const char *specials) const
 Backslash-escape a string. More...
 
String backslashEscaped (const String &specials) const
 Backslash-escape a string. More...
 
String backslashUnescaped () const
 Backslash-unescape a string. More...
 
bool empty () const
 Is the string empty?
 
size_t find (const String &str, size_t begin=0) const
 Find the first instance of the given string in self. More...
 
size_t find (const char *str, size_t begin=0) const
 Find the first instance of the given string in self. More...
 
size_t find (char c, size_t begin=0) const
 Find the first instance of the given character in self. More...
 
size_t findBM (const String &str, size_t begin=0) const
 Use Boyer-Moore algorithm to find the first instance of the given string. More...
 
size_t findBM (const char *str, size_t begin=0) const
 Use Boyer-Moore algorithm to find the first instance of the given string. More...
 
char firstChar () const
 Get the first character in the string (nul if empty). More...
 
char lastChar () const
 Get the last character in the string (nul if empty). More...
 
const char * get () const
 Get const char*. More...
 
size_t length () const
 Get the length of the string. More...
 
void lengthInvalidate () const
 Invalidate the cached length of the string. More...
 
String prefix (size_t n) const
 Get the first n characters of the string. More...
 
size_t size () const
 Get the size of the allocated character array. More...
 
String subString (size_t begin, size_t len=size_t_max) const
 Get a substring. More...
 
String suffix (size_t n) const
 Get the last n characters of the string. More...
 
String reversed () const
 Get a copy of self with the characters in reverse order. More...
 
String nextToken (size_t &idx, char delim=' ', bool processQuotes=false) const
 Return the next token in a delimited string. More...
 
Stringclear ()
 Reset to empty string. More...
 
Stringexcise ()
 Like clear(), but de-allocate the array instead of writing a nul character at position 0.
 
char * get ()
 Get char*. More...
 
char get (size_t i) const
 Get the specified character. More...
 
StringassertOwner ()
 Make sure self has its own copy of the string. More...
 
void assertOwner (size_t size, size_t increment=8)
 Make sure self has its own copy of the string. More...
 
void economize ()
 Make sure no extra space is allocated. More...
 
void reserve (size_t size, size_t increment=8)
 Grow to the specified size. More...
 
Stringappend (char c)
 Append the given character. More...
 
Stringappend (const String &s)
 Append the given string. More...
 
Stringappend (const char *s)
 Append the given string. More...
 
Stringappend (const char *s, size_t len)
 Append the given string. More...
 
String chop (size_t begin, size_t len=size_t_max)
 Chop out and return a sub-string. More...
 
void remove (size_t begin, size_t len=size_t_max)
 Remove a sub-string (like chop(), but doesn't return the removed sub-string). More...
 
Stringreplace (const String &lhs, const String &rhs)
 Replace all instances of lhs with rhs. More...
 
Stringreplace (const char *lhs, const char *rhs)
 Replace all instances of lhs with rhs. More...
 
Stringreplace (const char *lhs, const String &rhs)
 Replace all instances of lhs with rhs. More...
 
Stringreplace (const String &lhs, const char *rhs)
 Replace all instances of lhs with rhs. More...
 
Stringreplace (size_t begin, size_t len, const String &str)
 Replace a substring with a given string. More...
 
Stringreverse ()
 Reverse the ordering of the characters. More...
 
void set (const char *s, bool owner=true, bool duplicate=true, size_t length=size_t_max)
 Set a new string. More...
 
StringtoLower (size_t begin=0, size_t len=size_t_max)
 Convert characters to lowercase. More...
 
StringtoUpper (size_t begin=0, size_t len=size_t_max)
 Convert characters to uppercase. More...
 
StringpadBegin (size_t len, char c=' ')
 Pad with spaces (or another character) at the beginning. More...
 
StringpadEnd (size_t len, char c=' ')
 Pad with spaces (or another character) at the end. More...
 
Stringtrim ()
 Trim whitespace from the beginning and end. More...
 
StringtrimBegin ()
 Trim whitespace from the beginning. More...
 
StringtrimEnd ()
 Trim whitespace from the end. More...
 
String operator+ (char c) const
 Get a copy of self with the given character appended. More...
 
String operator+ (const char *str) const
 Get a copy of self with the given string appended. More...
 
String operator+ (const String &rhs) const
 Get a copy of self with the given string appended. More...
 
Stringoperator+= (char c)
 Append the given character to self. More...
 
Stringoperator+= (const char *rhs)
 Append the given string to self. More...
 
Stringoperator+= (const String &rhs)
 Append the given string to self. More...
 
Stringoperator= (const char *str)
 Make self equal to a copy of the given character array. More...
 
Stringoperator= (char c)
 Make self equal to the given character. More...
 
char & operator[] (size_t i)
 Array access operator. More...
 
const char & operator[] (size_t i) const
 Array access operator. More...
 
 operator char * ()
 Conversion to char*. More...
 
 operator const char * ()
 Conversion to const char*. More...
 
 operator const char * () const
 Conversion to const char*. More...
 
 operator void * ()
 Conversion to void*. More...
 
 operator const void * ()
 Conversion to const void*. More...
 
 operator const void * () const
 Conversion to const void*. More...
 
bool operator< (const Object &rhs) const
 
bool operator<= (const Object &rhs) const
 
bool operator> (const Object &rhs) const
 
bool operator>= (const Object &rhs) const
 
bool operator== (const Object &rhs) const
 
bool operator!= (const Object &rhs) const
 
bool operator< (const String &rhs) const
 
bool operator<= (const String &rhs) const
 
bool operator> (const String &rhs) const
 
bool operator>= (const String &rhs) const
 
bool operator== (const String &rhs) const
 
bool operator!= (const String &rhs) const
 
- Public Member Functions inherited from utl::Object
void clear ()
 Revert to initial state. More...
 
virtual void vclone (const Object &rhs)
 Make an exact copy of another instance. More...
 
virtual void dump (Stream &os, uint_t level=uint_t_max) const
 Dump a human-readable representation of self to the given output stream. More...
 
void dumpWithClassName (Stream &os, uint_t indent=4, uint_t level=uint_t_max) const
 Front-end for dump() that prints the object's class name. More...
 
virtual const ObjectgetKey () const
 Get the key for this object. More...
 
bool hasKey () const
 Determine whether or not the object has a key. More...
 
virtual const ObjectgetProxiedObject () const
 Get the proxied object (= self if none). More...
 
virtual ObjectgetProxiedObject ()
 Get the proxied object (= self if none). More...
 
bool _isA (const RunTimeClass *runTimeClass) const
 Determine whether self's class is a descendent of the given class. More...
 
 operator String () const
 Conversion to String. More...
 
size_t allocatedSize () const
 Get the total allocated size of this object. More...
 
virtual void addOwnedIt (const class FwdIt *it) const
 Notify self that it owns the given iterator. More...
 
virtual void removeOwnedIt (const class FwdIt *it) const
 Notify self that the given owned iterator has been destroyed. More...
 
bool operator< (const Object &rhs) const
 Less-than operator. More...
 
bool operator<= (const Object &rhs) const
 Less-than-or-equal-to operator. More...
 
bool operator> (const Object &rhs) const
 Greater-than operator. More...
 
bool operator>= (const Object &rhs) const
 Greater-than-or-equal-to operator. More...
 
bool operator== (const Object &rhs) const
 Equal-to operator. More...
 
bool operator!= (const Object &rhs) const
 Unequal-to operator. More...
 
void serializeIn (Stream &is, uint_t mode=ser_default)
 Serialize from an input stream. More...
 
void serializeOut (Stream &os, uint_t mode=ser_default) const
 Serialize to an output stream. More...
 
void serializeOutBoxed (Stream &os, uint_t mode=ser_default) const
 Serialize a boxed object to an output stream. More...
 
- Public Member Functions inherited from utl::FlagsMI
 FlagsMI ()
 Constructor. More...
 
virtual ~FlagsMI ()
 Destructor. More...
 
void copyFlags (const FlagsMI &rhs)
 Copy the given flags. More...
 
void copyFlags (const FlagsMI &rhs, uint_t lsb, uint_t msb)
 Copy (some of) the given flags. More...
 
void copyFlags (uint64_t flags, uint_t lsb, uint_t msb)
 Copy (some of) the given flags. More...
 
bool getFlag (uint_t flagNum) const
 Get a user-defined flag. More...
 
void setFlag (uint_t flagNum, bool val)
 Set a user-defined flag. More...
 
uint64_t getFlagsNumber (uint64_t mask, uint64_t shift=0)
 Get a multi-bit value in the flags data (which is stored as one 64-bit integer). More...
 
void setFlagsNumber (uint64_t mask, uint64_t shift, uint64_t num)
 Set a multi-bit value in the flags data (which is stored as one 64-bit integer). More...
 
uint64_t getFlags () const
 Get the flags. More...
 
void setFlags (uint64_t flags)
 Set the flags. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from utl::String
static String repeat (char c, size_t num)
 Return a string consisting of a repeated character. More...
 
static String spaces (size_t num)
 Return a string consisting of the given number of spaces. More...
 
- Static Public Member Functions inherited from utl::Object
static ObjectserializeInNullable (Stream &is, uint_t mode=ser_default)
 Serialize a nullptr-able object from an input stream. More...
 
static void serializeOutNullable (const Object *object, Stream &os, uint_t mode=ser_default)
 Serialize a nullptr-able object to an output stream. More...
 
static void serializeNullable (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a nullptr-able object to or from a stream. More...
 
static ObjectserializeInBoxed (Stream &is, uint_t mode=ser_default)
 Serialize a boxed object from an input stream. More...
 
static void serializeBoxed (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a boxed object to or from a stream. More...
 

Detailed Description

Scanned token.

Author
Adam McKee

Definition at line 22 of file Token.h.

Constructor & Destructor Documentation

◆ Token()

utl::Token::Token ( uint_t  id,
const String token,
size_t  lineNo,
size_t  colNo 
)
inline

Constructor.

Parameters
idid
tokenstring token
lineNoline number where token was found
colNocolumn number where token was found

Definition at line 34 of file Token.h.

References utl::compare(), utl::copy(), utl::deInit(), and utl::init().

Member Function Documentation

◆ compare()

virtual int utl::Token::compare ( const Object rhs) const
virtual

Compare with another object.

If no overridden version succeeds in doing the comparison, then an attempt will be made to re-start the comparison process using one or both of the objects' keys. Usually, an override of compare() should call the superclass's compare() if it doesn't know how to compare itself with the rhs object.

See also
getKey
Returns
< 0 if self < rhs, 0 if self = rhs, > 0 if self > rhs
Parameters
rhsobject to compare with

Reimplemented from utl::String.

◆ copy()

virtual void utl::Token::copy ( const Object rhs)
virtual

Copy another instance.

When you override copy(), you should usually call the superclass's copy().

Parameters
rhsobject to copy

Reimplemented from utl::String.

◆ steal()

virtual void utl::Token::steal ( Object rhs)
virtual

"Steal" the internal representation from another instance.

The default implementation just calls vclone(), so you have to override this if you want a "move" capability.

Reimplemented from utl::String.


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