casacore
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
casacore::MUString Class Reference

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...
 
MUStringoperator= (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 StringlastGet () 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 String value. More...
 
uInt ptr
 0-based pointer into string More...
 
uInt len
 Length of string. More...
 
Block< uIntstack
 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...
 

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:

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.

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"); // 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;
MUString()
Default constructor creates an empty string.
static Bool unitString(UnitVal &uv, String &us, MUString &in)
Check if String unit.
static UnitVal ANGLE
Definition: UnitVal.h:264
static UnitVal TIME
Definition: UnitVal.h:259
static UnitVal NODIM
Some constants to check type of units
Definition: UnitVal.h:255
const Bool False
Definition: aipstype.h:44
int Int
Definition: aipstype.h:50
Quantum< Double > Quantity
Definition: Quantum.h:38
const Bool True
Definition: aipstype.h:43
double Double
Definition: aipstype.h:55
char Char
Definition: aipstype.h:46

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

◆ MUString() [1/5]

casacore::MUString::MUString ( )

Default constructor creates an empty string.

◆ MUString() [2/5]

casacore::MUString::MUString ( const String in)

Create from String; setting pointer at start.

◆ MUString() [3/5]

casacore::MUString::MUString ( const Char in)

◆ MUString() [4/5]

casacore::MUString::MUString ( char  in)

◆ MUString() [5/5]

casacore::MUString::MUString ( const MUString other)

Copy constructor; new pointer will be same as old.

◆ ~MUString()

casacore::MUString::~MUString ( )

Destructor.

Member Function Documentation

◆ adjustPtr()

void casacore::MUString::adjustPtr ( Int  in)
private

Member functions Make a new pointer between 0 and len inclusive.

◆ eos()

Bool casacore::MUString::eos ( ) const

test for end of string

◆ freqChar()

Int casacore::MUString::freqChar ( Char  ch) const

Get frequency of occurrence.

◆ get() [1/3]

String casacore::MUString::get ( )

Get part of string.

◆ get() [2/3]

String casacore::MUString::get ( uInt  st)

◆ get() [3/3]

String casacore::MUString::get ( uInt  st,
uInt  nd 
)

◆ getAlpha()

String casacore::MUString::getAlpha ( )

◆ getAlphaNum()

String casacore::MUString::getAlphaNum ( )

◆ getChar()

Char casacore::MUString::getChar ( )

◆ getDouble()

Double casacore::MUString::getDouble ( )

◆ getInt()

Int casacore::MUString::getInt ( )

◆ getPtr()

Int casacore::MUString::getPtr ( ) const

Get pointer.

◆ getSign()

Int casacore::MUString::getSign ( )

◆ getString() [1/2]

String casacore::MUString::getString ( const Regex ex)

◆ getString() [2/2]

String casacore::MUString::getString ( const String ex)

◆ getStringNC()

String casacore::MUString::getStringNC ( const String ex)

◆ getuInt()

uInt casacore::MUString::getuInt ( )

◆ initLast()

Int casacore::MUString::initLast ( )
private

Initialise last settings; return pointer.

◆ lastGet()

const String& casacore::MUString::lastGet ( ) const

Get String found at last get.

◆ matchPair()

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

◆ minimaxNC() [1/2]

static uInt casacore::MUString::minimaxNC ( const String in,
const Vector< String > &  tname 
)
static

◆ minimaxNC() [2/2]

static uInt casacore::MUString::minimaxNC ( const String in,
Int  N_name,
const String  tname[] 
)
static

Do minimax check on list of Strings.

◆ operator()()

String casacore::MUString::operator() ( )

Obtain remaining string (same as get()).

◆ operator=()

MUString& casacore::MUString::operator= ( const MUString other)

Copy assignment; new pointer will be same as old.

◆ pop()

void casacore::MUString::pop ( )

Restore pointer from stack (or set to start if stack empty)

◆ push()

void casacore::MUString::push ( )

Save current pointer on internal stack.

◆ setLast()

void casacore::MUString::setLast ( Int  st)
private

Set last settings.

◆ setPtr()

void casacore::MUString::setPtr ( Int  in = 0)

(Re-)set pointer

◆ skipAlpha()

void casacore::MUString::skipAlpha ( )

◆ skipAlphaNum()

void casacore::MUString::skipAlphaNum ( )

◆ skipBlank()

void casacore::MUString::skipBlank ( )

Act on whitespace; adjusting pointer if skip.

◆ skipChar() [1/3]

void casacore::MUString::skipChar ( Char  ch)

◆ skipChar() [2/3]

void casacore::MUString::skipChar ( const Regex ex)

◆ skipChar() [3/3]

void casacore::MUString::skipChar ( Int  n = 1)

Act on character(s)

◆ skipCharNC()

void casacore::MUString::skipCharNC ( Char  ch)

◆ skipDouble()

void casacore::MUString::skipDouble ( )

Act on Double field.

If no value 0 returned and False.

◆ skipInt()

void casacore::MUString::skipInt ( )

Act on integer field.

If no integer found in 0 returned; and False

◆ skipNum()

void casacore::MUString::skipNum ( )

◆ skipSign()

void casacore::MUString::skipSign ( )

Act on sign; return +1 or -1 depending on signs found (– == +)

◆ skipString() [1/2]

void casacore::MUString::skipString ( const Regex ex)

◆ skipString() [2/2]

void casacore::MUString::skipString ( const String ex)

◆ skipStringNC()

void casacore::MUString::skipStringNC ( const String ex)

◆ skipuInt()

void casacore::MUString::skipuInt ( )

◆ status()

Bool casacore::MUString::status ( ) const

Get status last get.

◆ testAlpha()

Bool casacore::MUString::testAlpha ( ) const

◆ testAlphaNum()

Bool casacore::MUString::testAlphaNum ( ) const

◆ testBlank()

Bool casacore::MUString::testBlank ( ) const

◆ testChar() [1/2]

Bool casacore::MUString::testChar ( Char  ch) const

◆ testChar() [2/2]

Bool casacore::MUString::testChar ( const Regex ex) const

◆ testCharNC()

Bool casacore::MUString::testCharNC ( Char  ch) const

◆ testDouble()

Bool casacore::MUString::testDouble ( ) const

◆ testInt()

Bool casacore::MUString::testInt ( ) const

◆ testNum()

Bool casacore::MUString::testNum ( ) const

◆ testSign()

Bool casacore::MUString::testSign ( ) const

◆ testString() [1/2]

Bool casacore::MUString::testString ( const Regex ex) const

Act on series of characters.

◆ testString() [2/2]

Bool casacore::MUString::testString ( const String ex) const

◆ testStringNC()

Bool casacore::MUString::testStringNC ( const String ex) const

◆ testuInt()

Bool casacore::MUString::testuInt ( ) const

◆ tSkipAlpha()

Bool casacore::MUString::tSkipAlpha ( )

◆ tSkipAlphaNum()

Bool casacore::MUString::tSkipAlphaNum ( )

◆ tSkipBlank()

Bool casacore::MUString::tSkipBlank ( )

◆ tSkipChar() [1/2]

Bool casacore::MUString::tSkipChar ( Char  nc)

◆ tSkipChar() [2/2]

Bool casacore::MUString::tSkipChar ( const Regex ex)

◆ tSkipCharNC()

Bool casacore::MUString::tSkipCharNC ( Char  ch)

◆ tSkipDouble()

Bool casacore::MUString::tSkipDouble ( )

◆ tSkipInt()

Bool casacore::MUString::tSkipInt ( )

◆ tSkipNum()

Bool casacore::MUString::tSkipNum ( )

◆ tSkipOneChar()

Bool casacore::MUString::tSkipOneChar ( Char  ch)

◆ tSkipOneCharNC()

Bool casacore::MUString::tSkipOneCharNC ( Char  ch)

◆ tSkipSign()

Bool casacore::MUString::tSkipSign ( )

◆ tSkipString() [1/2]

Bool casacore::MUString::tSkipString ( const Regex ex)

◆ tSkipString() [2/2]

Bool casacore::MUString::tSkipString ( const String ex)

◆ tSkipStringNC()

Bool casacore::MUString::tSkipStringNC ( const String ex)

◆ tSkipuInt()

Bool casacore::MUString::tSkipuInt ( )

◆ unpush()

void casacore::MUString::unpush ( )

Restore stack for one level.

Friends And Related Function Documentation

◆ operator<<

ostream& operator<< ( ostream &  os,
const MUString in 
)
friend

Output String starting at pointer.

Member Data Documentation

◆ len

uInt casacore::MUString::len
private

Length of string.

Definition at line 392 of file MUString.h.

◆ lget

String casacore::MUString::lget
private

String found at last get.

Definition at line 400 of file MUString.h.

◆ ptr

uInt casacore::MUString::ptr
private

0-based pointer into string

Definition at line 390 of file MUString.h.

◆ stack

Block<uInt> casacore::MUString::stack
private

Pointer stack.

Definition at line 394 of file MUString.h.

◆ stat

Bool casacore::MUString::stat
private

Status of last get.

Definition at line 398 of file MUString.h.

◆ stpt

uInt casacore::MUString::stpt
private

Pointer into stack.

Definition at line 396 of file MUString.h.

◆ str

String casacore::MUString::str
private

Data String value.

Definition at line 388 of file MUString.h.


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