casacore
|
Pointed String class to aid analysis of quantity strings. More...
#include <MUString.h>
Public Member Functions | |
MUString () | |
Default constructor creates an empty string. More... | |
MUString (const String &in) | |
Create from String; setting pointer at start. More... | |
MUString (const Char *in) | |
MUString (char in) | |
MUString (const MUString &other) | |
Copy constructor; new pointer will be same as old. More... | |
MUString & | operator= (const MUString &other) |
Copy assignment; new pointer will be same as old. More... | |
~MUString () | |
Destructor. More... | |
String | operator() () |
Obtain remaining string (same as get() ). More... | |
void | push () |
Save current pointer on internal stack. More... | |
void | pop () |
Restore pointer from stack (or set to start if stack empty) More... | |
void | unpush () |
Restore stack for one level. More... | |
void | skipBlank () |
Act on whitespace; adjusting pointer if skip. More... | |
Bool | testBlank () const |
Bool | tSkipBlank () |
void | skipSign () |
Act on sign; return +1 or -1 depending on signs found (– == +) More... | |
Bool | testSign () const |
Bool | tSkipSign () |
Int | getSign () |
void | skipInt () |
Act on integer field. More... | |
Bool | testInt () const |
Bool | tSkipInt () |
Int | getInt () |
void | skipuInt () |
Bool | tSkipuInt () |
Bool | testuInt () const |
uInt | getuInt () |
void | skipDouble () |
Act on Double field. More... | |
Bool | testDouble () const |
Bool | tSkipDouble () |
Double | getDouble () |
void | skipChar (Int n=1) |
Act on character(s) More... | |
void | skipChar (Char ch) |
Bool | tSkipChar (Char nc) |
void | skipCharNC (Char ch) |
Bool | tSkipCharNC (Char ch) |
Bool | tSkipOneChar (Char ch) |
Bool | tSkipOneCharNC (Char ch) |
void | skipChar (const Regex &ex) |
Bool | tSkipChar (const Regex &ex) |
void | skipAlpha () |
Bool | tSkipAlpha () |
void | skipNum () |
Bool | tSkipNum () |
void | skipAlphaNum () |
Bool | tSkipAlphaNum () |
Bool | testChar (Char ch) const |
Bool | testCharNC (Char ch) const |
Bool | testChar (const Regex &ex) const |
Bool | testAlpha () const |
Bool | testNum () const |
Bool | testAlphaNum () const |
Char | getChar () |
String | getAlpha () |
String | getAlphaNum () |
Bool | testString (const Regex &ex) const |
Act on series of characters. More... | |
Bool | testString (const String &ex) const |
Bool | testStringNC (const String &ex) const |
Bool | tSkipString (const Regex &ex) |
Bool | tSkipString (const String &ex) |
Bool | tSkipStringNC (const String &ex) |
void | skipString (const Regex &ex) |
void | skipString (const String &ex) |
void | skipStringNC (const String &ex) |
String | getString (const Regex &ex) |
String | getString (const String &ex) |
String | getStringNC (const String &ex) |
Bool | matchPair (Char nd) |
Match a pair of opening(at pointer)/closing characters (e.g. More... | |
Int | freqChar (Char ch) const |
Get frequency of occurrence. More... | |
String | get () |
Get part of string. More... | |
String | get (uInt st) |
String | get (uInt st, uInt nd) |
Int | getPtr () const |
Get pointer. More... | |
void | setPtr (Int in=0) |
(Re-)set pointer More... | |
Bool | eos () const |
test for end of string More... | |
Bool | status () const |
Get status last get. More... | |
const String & | lastGet () const |
Get String found at last get. More... | |
Static Public Member Functions | |
static uInt | minimaxNC (const String &in, Int N_name, const String tname[]) |
Do minimax check on list of Strings. More... | |
static uInt | minimaxNC (const String &in, const Vector< String > &tname) |
Private Member Functions | |
void | adjustPtr (Int in) |
Member functions Make a new pointer between 0 and len inclusive. More... | |
Int | initLast () |
Initialise last settings; return pointer. More... | |
void | setLast (Int st) |
Set last settings. More... | |
Private Attributes | |
String | str |
Data | |
uInt | ptr |
0-based pointer into string More... | |
uInt | len |
Length of string. More... | |
Block< uInt > | stack |
Pointer stack. More... | |
uInt | stpt |
Pointer into stack. More... | |
Bool | stat |
Status of last get. More... | |
String | lget |
String found at last get. More... | |
Friends | |
ostream & | operator<< (ostream &os, const MUString &in) |
Output String starting at pointer. More... | |
Pointed String class to aid analysis of quantity strings.
The MUString is a class with a String and an embedded pointer. It can be used to linearly analyse a string for its semantics. Imagine for instance a string that represents an angle. It could be formatted as [+-]hh:mm:ss.ttt
or as [+-]hh[hH]mm[mM]
or as [+-]dd.mm.ss.ttt
or with .'s
replaced with dms
or as [+-]ddd.fff deg
etc.
The available methods aid in analysing this string (see example).
The following analysis method classes are avaible:
Bool testSign()
test if current character is + or -. If at end of string; False is returned, except for testBlank()
. No pointer update. Any method with NC at the end (for no-case) will test irrespective of the case. void skipSign()
will skip all + and - found at the current and subsequent positions. Pointer updated. Double getDouble()
form a string like "abc"
will return 0.0) a False status will be saved. It can be interrogated by the Bool status()
function. The string part used in producing the value is also saved, and can be obtained with const String &lastGet()
. No saving in case of a simple getChar() is done. void push()
and void pop()
are available void setPtr()
and Int getPtr()
. Pointers are always protected in their value. The following types (X in the above list) are available
General string aids are available. The main one a minimax, caseless check of an input String against a vector: static uInt minimaxNC(String in, Int N_name, String name[])
and its vector equivalent: static uInt minimaxNC(String in, Vector<String> name)
. Success is indicated by a return value less than N_name or the vector length.
See MVAngle class for example background. The following example is the conversion of different input angle formats to a Quantity. A full blown example, but gives some idea of intricacies involved.
The class was written to be able to analyse an input string for its Quantum representation as value with units, or os a date/time or as an angle.
Definition at line 229 of file MUString.h.
casacore::MUString::MUString | ( | ) |
Default constructor creates an empty string.
casacore::MUString::MUString | ( | const Char * | in | ) |
casacore::MUString::MUString | ( | char | in | ) |
casacore::MUString::MUString | ( | const MUString & | other | ) |
Copy constructor; new pointer will be same as old.
casacore::MUString::~MUString | ( | ) |
Destructor.
|
private |
Member functions Make a new pointer between 0 and len inclusive.
Bool casacore::MUString::eos | ( | ) | const |
test for end of string
String casacore::MUString::get | ( | ) |
Get part of string.
String casacore::MUString::getAlpha | ( | ) |
String casacore::MUString::getAlphaNum | ( | ) |
Char casacore::MUString::getChar | ( | ) |
Double casacore::MUString::getDouble | ( | ) |
Int casacore::MUString::getInt | ( | ) |
Int casacore::MUString::getPtr | ( | ) | const |
Get pointer.
Int casacore::MUString::getSign | ( | ) |
uInt casacore::MUString::getuInt | ( | ) |
|
private |
Initialise last settings; return pointer.
Match a pair of opening(at pointer)/closing characters (e.g.
(and)). Return False if wrong semantics. The string between the pair (excluding them) will be put in Last. If false, the ptr will be as originally; if True it will point beyond the matched closing character
|
static |
Do minimax check on list of Strings.
|
static |
Copy assignment; new pointer will be same as old.
void casacore::MUString::pop | ( | ) |
Restore pointer from stack (or set to start if stack empty)
void casacore::MUString::push | ( | ) |
Save current pointer on internal stack.
|
private |
Set last settings.
void casacore::MUString::setPtr | ( | Int | in = 0 | ) |
(Re-)set pointer
void casacore::MUString::skipAlpha | ( | ) |
void casacore::MUString::skipAlphaNum | ( | ) |
void casacore::MUString::skipBlank | ( | ) |
Act on whitespace; adjusting pointer if skip.
void casacore::MUString::skipChar | ( | Int | n = 1 | ) |
Act on character(s)
void casacore::MUString::skipChar | ( | Char | ch | ) |
void casacore::MUString::skipChar | ( | const Regex & | ex | ) |
void casacore::MUString::skipCharNC | ( | Char | ch | ) |
void casacore::MUString::skipDouble | ( | ) |
Act on Double field.
If no value 0 returned and False.
void casacore::MUString::skipInt | ( | ) |
Act on integer field.
If no integer found in 0 returned; and False
void casacore::MUString::skipNum | ( | ) |
void casacore::MUString::skipSign | ( | ) |
Act on sign; return +1 or -1 depending on signs found (– == +)
void casacore::MUString::skipString | ( | const Regex & | ex | ) |
void casacore::MUString::skipString | ( | const String & | ex | ) |
void casacore::MUString::skipStringNC | ( | const String & | ex | ) |
void casacore::MUString::skipuInt | ( | ) |
Bool casacore::MUString::status | ( | ) | const |
Get status last get.
Bool casacore::MUString::testAlpha | ( | ) | const |
Bool casacore::MUString::testAlphaNum | ( | ) | const |
Bool casacore::MUString::testBlank | ( | ) | const |
Bool casacore::MUString::testDouble | ( | ) | const |
Bool casacore::MUString::testInt | ( | ) | const |
Bool casacore::MUString::testNum | ( | ) | const |
Bool casacore::MUString::testSign | ( | ) | const |
Bool casacore::MUString::testuInt | ( | ) | const |
Bool casacore::MUString::tSkipAlpha | ( | ) |
Bool casacore::MUString::tSkipAlphaNum | ( | ) |
Bool casacore::MUString::tSkipBlank | ( | ) |
Bool casacore::MUString::tSkipDouble | ( | ) |
Bool casacore::MUString::tSkipInt | ( | ) |
Bool casacore::MUString::tSkipNum | ( | ) |
Bool casacore::MUString::tSkipSign | ( | ) |
Bool casacore::MUString::tSkipuInt | ( | ) |
void casacore::MUString::unpush | ( | ) |
Restore stack for one level.
|
private |
Length of string.
Definition at line 392 of file MUString.h.
|
private |
String found at last get.
Definition at line 400 of file MUString.h.
|
private |
0-based pointer into string
Definition at line 390 of file MUString.h.
Pointer stack.
Definition at line 394 of file MUString.h.
|
private |
Status of last get.
Definition at line 398 of file MUString.h.
|
private |
Pointer into stack.
Definition at line 396 of file MUString.h.
|
private |