#include <MUString.h>
Collaboration diagram for casa::MUString:

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. 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.
res = Quantity(0.0, "rad"); // result MUString tmp(in); // Pointed non-const String tmp.skipBlank(); Double s = tmp.getSign(); // sign tmp.push(); // Save position to rescan Double r = tmp.getuInt(); // first field Int tp = 0; // distributor if (tmp.tSkipChar('.')) { // if more than one ., dms format Double r1 = tmp.getuInt(); if (tmp.tSkipChar('.')) { r += r1/60.0 + tmp.getDouble()/3600.0; tp = 4; } else { // else value with units tmp.pop(); // Reset position r = tmp.getDouble(); }; } else if (tmp.tSkipCharNC('d')) { // dms tp = 1; } else if (tmp.tSkipCharNC('h')) { // hms tp = 2; } else if (tmp.tSkipChar(':')) { // hms tp = 3; }; switch (tp) { case 0: { UnitVal u; String us; if (!MVAngle::unitString(u,us,tmp)) return False; r *= s; if (u == UnitVal::NODIM) { // check correct dimension 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: { // get remainder od ms and hms formats 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) { // make correct units 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;
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.
Public Member Functions | |
| MUString () | |
| Default constructor creates an empty string. | |
| MUString (const MUString &other) | |
| Copy constructor; new pointer will be same as old. | |
| MUString & | operator= (const MUString &other) |
| Copy assignment; new pointer will be same as old. | |
| ~MUString () | |
| Destructor. | |
| String | operator() () |
Obtain remaining string (same as get()). | |
| void | push () |
| Save current pointer on internal stack. | |
| void | pop () |
| Restore pointer from stack (or set to start if stack empty). | |
| void | unpush () |
| Restore stack for one level. | |
| Bool | matchPair (Char nd) |
| Match a pair of opening(at pointer)/closing characters (e.g. | |
| Int | freqChar (Char ch) const |
| Get frequency of occurrence. | |
| Int | getPtr () const |
| Get pointer. | |
| void | setPtr (Int in=0) |
| (Re-)set pointer | |
| Bool | eos () const |
| test for end of string | |
| Bool | status () const |
| Get status last get. | |
| const String & | lastGet () const |
| Get String found at last get. | |
| MUString (const String &in) | |
| Create from String; setting pointer at start. | |
| MUString (const Char *in) | |
| MUString (char in) | |
| void | skipBlank () |
| Act on whitespace; adjusting pointer if skip. | |
| Bool | testBlank () const |
| Bool | tSkipBlank () |
| void | skipSign () |
| Act on sign; return +1 or -1 depending on signs found (-- == +). | |
| Bool | testSign () const |
| Bool | tSkipSign () |
| Int | getSign () |
| void | skipInt () |
| Act on integer field. | |
| Bool | testInt () const |
| Bool | tSkipInt () |
| Int | getInt () |
| void | skipuInt () |
| Bool | tSkipuInt () |
| Bool | testuInt () const |
| uInt | getuInt () |
| void | skipDouble () |
| Act on Double field. | |
| Bool | testDouble () const |
| Bool | tSkipDouble () |
| Double | getDouble () |
| void | skipChar (Int n=1) |
| Act on character(s). | |
| void | skipChar (Char ch) |
| Bool | tSkipChar (Char nc) |
| void | skipCharNC (Char ch) |
| Bool | tSkipCharNC (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. | |
| 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) |
| String | get () |
| Get part of string. | |
| String | get (uInt st) |
| String | get (uInt st, uInt nd) |
Static Public Member Functions | |
| static uInt | minimaxNC (const String &in, Int N_name, const String tname[]) |
| Do minimax check on list of Strings. | |
| 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. | |
| Int | initLast () |
| Initialise last settings; return pointer. | |
| void | setLast (Int st) |
| Set last settings. | |
Private Attributes | |
| String | str |
| Data String value. | |
| uInt | ptr |
| 0-based pointer into string | |
| uInt | len |
| Length of string. | |
| Block< uInt > | stack |
| Pointer stack. | |
| uInt | stpt |
| Pointer into stack. | |
| Bool | stat |
| Status of last get. | |
| String | lget |
| String found at last get. | |
Friends | |
| ostream & | operator<< (ostream &os, const MUString &in) |
| Output String starting at pointer. | |
| casa::MUString::MUString | ( | ) |
Default constructor creates an empty string.
| casa::MUString::MUString | ( | const Char * | in | ) |
| casa::MUString::MUString | ( | char | in | ) |
| casa::MUString::MUString | ( | const MUString & | other | ) |
Copy constructor; new pointer will be same as old.
| casa::MUString::~MUString | ( | ) |
Destructor.
Copy assignment; new pointer will be same as old.
| void casa::MUString::push | ( | ) |
Save current pointer on internal stack.
| void casa::MUString::pop | ( | ) |
Restore pointer from stack (or set to start if stack empty).
| void casa::MUString::unpush | ( | ) |
Restore stack for one level.
| void casa::MUString::skipBlank | ( | ) |
Act on whitespace; adjusting pointer if skip.
| Bool casa::MUString::testBlank | ( | ) | const |
| Bool casa::MUString::tSkipBlank | ( | ) |
| void casa::MUString::skipSign | ( | ) |
Act on sign; return +1 or -1 depending on signs found (-- == +).
| Bool casa::MUString::testSign | ( | ) | const |
| Bool casa::MUString::tSkipSign | ( | ) |
| Int casa::MUString::getSign | ( | ) |
| void casa::MUString::skipInt | ( | ) |
Act on integer field.
If no integer found in 0 returned; and False
| Bool casa::MUString::testInt | ( | ) | const |
| Bool casa::MUString::tSkipInt | ( | ) |
| Int casa::MUString::getInt | ( | ) |
| void casa::MUString::skipuInt | ( | ) |
| Bool casa::MUString::tSkipuInt | ( | ) |
| Bool casa::MUString::testuInt | ( | ) | const |
| uInt casa::MUString::getuInt | ( | ) |
| void casa::MUString::skipDouble | ( | ) |
Act on Double field.
If no value 0 returned and False.
| Bool casa::MUString::testDouble | ( | ) | const |
| Bool casa::MUString::tSkipDouble | ( | ) |
| Double casa::MUString::getDouble | ( | ) |
| void casa::MUString::skipChar | ( | Int | n = 1 |
) |
Act on character(s).
| void casa::MUString::skipChar | ( | Char | ch | ) |
| void casa::MUString::skipCharNC | ( | Char | ch | ) |
| void casa::MUString::skipChar | ( | const Regex & | ex | ) |
| void casa::MUString::skipAlpha | ( | ) |
| Bool casa::MUString::tSkipAlpha | ( | ) |
| void casa::MUString::skipNum | ( | ) |
| Bool casa::MUString::tSkipNum | ( | ) |
| void casa::MUString::skipAlphaNum | ( | ) |
| Bool casa::MUString::tSkipAlphaNum | ( | ) |
| Bool casa::MUString::testAlpha | ( | ) | const |
| Bool casa::MUString::testNum | ( | ) | const |
| Bool casa::MUString::testAlphaNum | ( | ) | const |
| Char casa::MUString::getChar | ( | ) |
| String casa::MUString::getAlpha | ( | ) |
| String casa::MUString::getAlphaNum | ( | ) |
| void casa::MUString::skipString | ( | const Regex & | ex | ) |
| void casa::MUString::skipString | ( | const String & | ex | ) |
| void casa::MUString::skipStringNC | ( | const String & | ex | ) |
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
| String casa::MUString::get | ( | ) |
Get part of string.
| Int casa::MUString::getPtr | ( | ) | const |
Get pointer.
| void casa::MUString::setPtr | ( | Int | in = 0 |
) |
(Re-)set pointer
| Bool casa::MUString::eos | ( | ) | const |
test for end of string
| Bool casa::MUString::status | ( | ) | const |
Get status last get.
| static uInt casa::MUString::minimaxNC | ( | const String & | in, | |
| Int | N_name, | |||
| const String | tname[] | |||
| ) | [static] |
Do minimax check on list of Strings.
| static uInt casa::MUString::minimaxNC | ( | const String & | in, | |
| const Vector< String > & | tname | |||
| ) | [static] |
| void casa::MUString::adjustPtr | ( | Int | in | ) | [private] |
Member functions Make a new pointer between 0 and len inclusive.
| Int casa::MUString::initLast | ( | ) | [private] |
Initialise last settings; return pointer.
| void casa::MUString::setLast | ( | Int | st | ) | [private] |
Set last settings.
| ostream& operator<< | ( | ostream & | os, | |
| const MUString & | in | |||
| ) | [friend] |
Output String starting at pointer.
String casa::MUString::str [private] |
uInt casa::MUString::ptr [private] |
uInt casa::MUString::len [private] |
Block<uInt> casa::MUString::stack [private] |
uInt casa::MUString::stpt [private] |
Bool casa::MUString::stat [private] |
String casa::MUString::lget [private] |
1.5.1