ROSE
0.11.96.11
|
Input stream for command line arguments.
A cursor is an ordered set of strings and a current position in that set.
Definition at line 255 of file util/Sawyer/CommandLine.h.
#include <CommandLine.h>
Public Member Functions | |
Cursor (const std::vector< std::string > &strings) | |
Construct a cursor from an ordered set of strings. More... | |
Cursor (const std::string &string) | |
Constructs a cursor for a single string. More... | |
Cursor () | |
Constructs a not-very-useful cursor to nothing. | |
const std::vector< std::string > & | strings () const |
All strings for the cursor. | |
bool | atArgBegin () const |
True when the cursor is at the beginning of an argument. More... | |
bool | atArgEnd () const |
True when the cursor is at the end of an argument. More... | |
void | replace (const std::vector< std::string > &) |
Replace the current string with new strings. More... | |
void | consumeChars (size_t nchars) |
Advance over characters. More... | |
size_t | linearDistance () const |
Number of characters from the beginning of the cursor to its current location. More... | |
const Location & | location () const |
Property: current position of the cursor. More... | |
Cursor & | location (const Location &loc) |
Property: current position of the cursor. More... | |
bool | atEnd () const |
Returns true when the cursor is after all arguments. More... | |
bool | atEnd (const Location &location) const |
Returns true when the cursor is after all arguments. More... | |
const std::string & | arg () const |
Return the entire current program argument regardless of where the cursor is in that argument. More... | |
const std::string & | arg (const Location &location) const |
Return the entire current program argument regardless of where the cursor is in that argument. More... | |
std::string | rest () const |
Return the part of an argument at and beyond the cursor location. More... | |
std::string | rest (const Location &location) const |
Return the part of an argument at and beyond the cursor location. More... | |
std::string | substr (const Location &limit, const std::string &separator=" ") const |
Returns all characters within limits. More... | |
std::string | substr (const Location &limit1, const Location &limit2, const std::string &separator=" ") const |
Returns all characters within limits. More... | |
void | consumeArgs (size_t nargs) |
Advance the cursor to the beginning of the next string. More... | |
void | consumeArg () |
Advance the cursor to the beginning of the next string. More... | |
|
inline |
Construct a cursor from an ordered set of strings.
The cursor's initial position is the first character of the first string, or the end if the set contains no strings or contains only empty strings.
Definition at line 263 of file util/Sawyer/CommandLine.h.
|
inline |
Constructs a cursor for a single string.
The cursor's initial position is the first character of the string, or the end if the string is empty.
Definition at line 267 of file util/Sawyer/CommandLine.h.
|
inline |
Property: current position of the cursor.
The following semantics apply to the location:
idx
member will either point to a valid string in the cursor's strings vector, or it will be equal to the size of that vector. idx
member is equal to the size of the cursor's strings vector, the cursor is said to be at the end of its input and atEnd returns true. offset
member is zero whenever atEnd returns true. offset
is less than or equal to the length of the string indexed by idx
. offset
is equal to the string length, then the cursor is said to be positioned at the end of an argument and atArgEnd returns true.When a new location is provided it will be immediately adjusted so that the idx
member is not greater than the number of strings in the cursor, and its offset
member is less than or equal to the length of that string (or zero when idx
is equal to the number of strings).
Definition at line 292 of file util/Sawyer/CommandLine.h.
Property: current position of the cursor.
The following semantics apply to the location:
idx
member will either point to a valid string in the cursor's strings vector, or it will be equal to the size of that vector. idx
member is equal to the size of the cursor's strings vector, the cursor is said to be at the end of its input and atEnd returns true. offset
member is zero whenever atEnd returns true. offset
is less than or equal to the length of the string indexed by idx
. offset
is equal to the string length, then the cursor is said to be positioned at the end of an argument and atArgEnd returns true.When a new location is provided it will be immediately adjusted so that the idx
member is not greater than the number of strings in the cursor, and its offset
member is less than or equal to the length of that string (or zero when idx
is equal to the number of strings).
|
inline |
True when the cursor is at the beginning of an argument.
Returns true if the cursor points to an argument and is at the beginning of that argument. Returns false otherwise, including when atEnd returns true.
Definition at line 298 of file util/Sawyer/CommandLine.h.
References Sawyer::CommandLine::Location::idx, and Sawyer::CommandLine::Location::offset.
|
inline |
True when the cursor is at the end of an argument.
Returns true if the cursor points to an argument and is positioned past the end of that string. Returns false otherwise, including when atEnd returns true.
Definition at line 302 of file util/Sawyer/CommandLine.h.
References Sawyer::CommandLine::Location::idx, and Sawyer::CommandLine::Location::offset.
|
inline |
Returns true when the cursor is after all arguments.
When the cursor is after all arguments, then atArgBegin and atArgEnd both return false. A locaton
can be specified to override the location that's inherent to this cursor without changing this cursor.
Definition at line 308 of file util/Sawyer/CommandLine.h.
References atEnd().
Referenced by atEnd().
|
inline |
Returns true when the cursor is after all arguments.
When the cursor is after all arguments, then atArgBegin and atArgEnd both return false. A locaton
can be specified to override the location that's inherent to this cursor without changing this cursor.
Definition at line 309 of file util/Sawyer/CommandLine.h.
References Sawyer::CommandLine::Location::idx.
|
inline |
Return the entire current program argument regardless of where the cursor is in that argument.
A location
can be specified to override the location that's inherent to this cursor without changing this cursor. It is an error to call this when atEnd returns true.
Definition at line 316 of file util/Sawyer/CommandLine.h.
References arg().
Referenced by arg().
const std::string& Sawyer::CommandLine::Cursor::arg | ( | const Location & | location | ) | const |
Return the entire current program argument regardless of where the cursor is in that argument.
A location
can be specified to override the location that's inherent to this cursor without changing this cursor. It is an error to call this when atEnd returns true.
|
inline |
Return the part of an argument at and beyond the cursor location.
If the cursor is positioned at the end of an argument then an empty string is returned. A location
can be specified to override the location that's inherent to this cursor without changing this cursor. Returns an empty string if called when atEnd returns true.
Definition at line 324 of file util/Sawyer/CommandLine.h.
References rest().
Referenced by rest().
std::string Sawyer::CommandLine::Cursor::rest | ( | const Location & | location | ) | const |
Return the part of an argument at and beyond the cursor location.
If the cursor is positioned at the end of an argument then an empty string is returned. A location
can be specified to override the location that's inherent to this cursor without changing this cursor. Returns an empty string if called when atEnd returns true.
|
inline |
Returns all characters within limits.
Returns all the characters between this cursor's current location and the specified location, which may be left or right of the cursor's location. The two argument version uses the two specified locations rather than this cursor's current location. The separator
string is inserted between text that comes from two different strings.
Definition at line 333 of file util/Sawyer/CommandLine.h.
References substr().
Referenced by substr().
std::string Sawyer::CommandLine::Cursor::substr | ( | const Location & | limit1, |
const Location & | limit2, | ||
const std::string & | separator = " " |
||
) | const |
Returns all characters within limits.
Returns all the characters between this cursor's current location and the specified location, which may be left or right of the cursor's location. The two argument version uses the two specified locations rather than this cursor's current location. The separator
string is inserted between text that comes from two different strings.
void Sawyer::CommandLine::Cursor::replace | ( | const std::vector< std::string > & | ) |
Replace the current string with new strings.
Repositions the cursor to the beginning of the first inserted string. Must not be called when atEnd returns true.
void Sawyer::CommandLine::Cursor::consumeChars | ( | size_t | nchars | ) |
Advance over characters.
Advances the cursor's current location by nchars
characters. The cursor must be positioned so that at least nchars
characters can be skipped in the current string. This call does not advance the cursor to the next string.
|
inline |
Advance the cursor to the beginning of the next string.
If the cursor is already positioned at the last string then it will be positioned to the end and atEnd will return true. It is permissible to call this method when atEnd already returns true, in which case nothing happens.
Definition at line 350 of file util/Sawyer/CommandLine.h.
References Sawyer::CommandLine::Location::idx, and Sawyer::CommandLine::Location::offset.
|
inline |
Advance the cursor to the beginning of the next string.
If the cursor is already positioned at the last string then it will be positioned to the end and atEnd will return true. It is permissible to call this method when atEnd already returns true, in which case nothing happens.
Definition at line 354 of file util/Sawyer/CommandLine.h.
size_t Sawyer::CommandLine::Cursor::linearDistance | ( | ) | const |
Number of characters from the beginning of the cursor to its current location.
This is the same as calling
but faster.