casacore::MUString Class Reference
Pointed String class to aid analysis of quantity strings.
More...
#include <MUString.h>
List of all members.
Detailed Description
Pointed String class to aid analysis of quantity strings.
Review Status
- Reviewed By:
- UNKNOWN
- Date Reviewed:
- before2004/08/25
- Test programs:
- tMeasure
Prerequisite
Etymology
From Measure Utility String
Synopsis
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:
-
construct -- all constructors create a string with the pointer starting at the beginning of the string
-
testX(arg) -- all test methods test if the next available character(s) fulfill the specified argument test. E.g.
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.
-
skipX(arg) -- all skip methods skip all available character(s) fulfilling the specified argument. E.g.
void skipSign()
will skip all + and - found at the current and subsequent positions. Pointer updated.
-
tSkipX(arg) -- will skip as skipX, and return Bool as in testX. Pointer updated
-
getX(arg) -- will get the indicated X value from the string. Pointer updated. A get will always return a valid result. However, if the value did not exist (e.g.
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.
-
stack -- if it is necessary to save the current position of the pointer (for maybe later restoration) a
void push()
and void pop()
are available
-
pointer -- the pointer can be manipulated with
void setPtr()
and Int getPtr()
. Pointers are always protected in their value.
The following types (X in the above list) are available
-
Char -- a single character
-
CharNC -- a single character with no case
-
String -- a string
-
StringNC -- a string without case
-
Alpha -- a through z and A through Z and _ (underscore)
-
Num -- digits 0 through 9
-
AlphaNum -- a field staring with Alpha, and remainder (if any) Alpha or Num
-
Sign -- a plus or minus
-
Blank -- a space ar a tab
-
uInt -- unsigned integer
-
Int -- an optionally signed integer
-
Double -- a double value
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.
Example
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.
res = Quantity(0.0, "rad");
MUString tmp(in);
tmp.skipBlank();
Double s = tmp.getSign();
tmp.push();
Double r = tmp.getuInt();
Int tp = 0;
if (tmp.tSkipChar('.')) {
Double r1 = tmp.getuInt();
if (tmp.tSkipChar('.')) {
r += r1/60.0 + tmp.getDouble()/3600.0;
tp = 4;
} else {
tmp.pop();
r = tmp.getDouble();
};
} else if (tmp.tSkipCharNC('d')) {
tp = 1;
} else if (tmp.tSkipCharNC('h')) {
tp = 2;
} else if (tmp.tSkipChar(':')) {
tp = 3;
};
switch (tp) {
case 0: {
UnitVal u; String us;
if (!MVAngle::unitString(u,us,tmp)) return False;
r *= s;
if (u == UnitVal::NODIM) {
res = Quantity(r,"rad");
return True;
};
if (u == UnitVal::ANGLE) {
res = Quantity(r,us);
return True;
};
if (u == UnitVal::TIME) {
res = Quantity(Quantity(r/240.,us).getBaseValue(), "deg");
return True;
};
return False;
};
break;
case 1:
case 2:
case 3: {
Char tc = 'm';
if (tp == 3) tc = ':';
tmp.push();
Double r1 = tmp.getuInt();
if (tmp.tSkipChar('.')) {
tmp.pop();
r += tmp.getDouble()/3600.;
} else if (tmp.tSkipCharNC(tc)) {
r += r1/60.0 + tmp.getDouble()/3600.;
} else {
r += r1/3600.0;
};
r *= s;
};
break;
default:
break;
};
switch (tp) {
case 1:
case 4:
res = Quantity(r,"deg");
break;
case 2:
case 3:
res = Quantity(Quantity(r/240.,"h").getBaseValue(), "deg");
break;
default:
break;
};
return True;
Motivation
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.
To Do
Definition at line 229 of file MUString.h.
Constructor & Destructor Documentation
casacore::MUString::MUString |
( |
|
) |
|
Default constructor creates an empty string.
casacore::MUString::MUString |
( |
const String & |
in |
) |
|
Create from String; setting pointer at start.
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 |
( |
|
) |
|
Member Function Documentation
void casacore::MUString::adjustPtr |
( |
Int |
in |
) |
[private] |
Member functions Make a new pointer between 0 and len inclusive.
Bool casacore::MUString::eos |
( |
|
) |
const |
Int casacore::MUString::freqChar |
( |
Char |
ch |
) |
const |
Get frequency of occurrence.
String casacore::MUString::get |
( |
|
) |
|
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 |
Int casacore::MUString::getSign |
( |
|
) |
|
String casacore::MUString::getString |
( |
const Regex & |
ex |
) |
|
String casacore::MUString::getStringNC |
( |
const String & |
ex |
) |
|
uInt casacore::MUString::getuInt |
( |
|
) |
|
Int casacore::MUString::initLast |
( |
|
) |
[private] |
Initialise last settings; return pointer.
const String& casacore::MUString::lastGet |
( |
|
) |
const |
Bool casacore::MUString::matchPair |
( |
Char |
nd |
) |
|
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 uInt casacore::MUString::minimaxNC |
( |
const String & |
in, |
|
|
Int |
N_name, |
|
|
const String |
tname[] | |
|
) |
| | [static] |
Do minimax check on list of Strings.
String casacore::MUString::operator() |
( |
|
) |
|
Obtain remaining string (same as get()
).
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.
void casacore::MUString::setLast |
( |
Int |
st |
) |
[private] |
void casacore::MUString::setPtr |
( |
Int |
in = 0 |
) |
|
void casacore::MUString::skipAlpha |
( |
|
) |
|
void casacore::MUString::skipAlphaNum |
( |
|
) |
|
void casacore::MUString::skipBlank |
( |
|
) |
|
Act on whitespace; adjusting pointer if skip.
void casacore::MUString::skipChar |
( |
const Regex & |
ex |
) |
|
void casacore::MUString::skipChar |
( |
Char |
ch |
) |
|
void casacore::MUString::skipChar |
( |
Int |
n = 1 |
) |
|
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 String & |
ex |
) |
|
void casacore::MUString::skipString |
( |
const Regex & |
ex |
) |
|
void casacore::MUString::skipStringNC |
( |
const String & |
ex |
) |
|
void casacore::MUString::skipuInt |
( |
|
) |
|
Bool casacore::MUString::status |
( |
|
) |
const |
Bool casacore::MUString::testAlpha |
( |
|
) |
const |
Bool casacore::MUString::testAlphaNum |
( |
|
) |
const |
Bool casacore::MUString::testBlank |
( |
|
) |
const |
Bool casacore::MUString::testChar |
( |
const Regex & |
ex |
) |
const |
Bool casacore::MUString::testChar |
( |
Char |
ch |
) |
const |
Bool casacore::MUString::testCharNC |
( |
Char |
ch |
) |
const |
Bool casacore::MUString::testDouble |
( |
|
) |
const |
Bool casacore::MUString::testInt |
( |
|
) |
const |
Bool casacore::MUString::testNum |
( |
|
) |
const |
Bool casacore::MUString::testSign |
( |
|
) |
const |
Bool casacore::MUString::testString |
( |
const String & |
ex |
) |
const |
Bool casacore::MUString::testString |
( |
const Regex & |
ex |
) |
const |
Act on series of characters.
Bool casacore::MUString::testStringNC |
( |
const String & |
ex |
) |
const |
Bool casacore::MUString::testuInt |
( |
|
) |
const |
Bool casacore::MUString::tSkipAlpha |
( |
|
) |
|
Bool casacore::MUString::tSkipAlphaNum |
( |
|
) |
|
Bool casacore::MUString::tSkipBlank |
( |
|
) |
|
Bool casacore::MUString::tSkipChar |
( |
const Regex & |
ex |
) |
|
Bool casacore::MUString::tSkipChar |
( |
Char |
nc |
) |
|
Bool casacore::MUString::tSkipCharNC |
( |
Char |
ch |
) |
|
Bool casacore::MUString::tSkipDouble |
( |
|
) |
|
Bool casacore::MUString::tSkipInt |
( |
|
) |
|
Bool casacore::MUString::tSkipNum |
( |
|
) |
|
Bool casacore::MUString::tSkipOneChar |
( |
Char |
ch |
) |
|
Bool casacore::MUString::tSkipOneCharNC |
( |
Char |
ch |
) |
|
Bool casacore::MUString::tSkipSign |
( |
|
) |
|
Bool casacore::MUString::tSkipString |
( |
const String & |
ex |
) |
|
Bool casacore::MUString::tSkipString |
( |
const Regex & |
ex |
) |
|
Bool casacore::MUString::tSkipStringNC |
( |
const String & |
ex |
) |
|
Bool casacore::MUString::tSkipuInt |
( |
|
) |
|
void casacore::MUString::unpush |
( |
|
) |
|
Restore stack for one level.
Friends And Related Function Documentation
ostream& operator<< |
( |
ostream & |
os, |
|
|
const MUString & |
in | |
|
) |
| | [friend] |
Output String starting at pointer.
Member Data Documentation
0-based pointer into string
Definition at line 390 of file MUString.h.
The documentation for this class was generated from the following file: