casacore
|
String: the storage and methods of handling collections of characters.
More...
#include <String.h>
Public Types | |
typedef string::traits_type | traits_type |
typedef string::value_type | value_type |
typedef string::allocator_type | allocator_type |
typedef string::size_type | size_type |
typedef string::difference_type | difference_type |
typedef string::reference | reference |
typedef string::const_reference | const_reference |
typedef string::pointer | pointer |
typedef string::const_pointer | const_pointer |
typedef string::iterator | iterator |
typedef string::const_iterator | const_iterator |
typedef string::reverse_iterator | reverse_iterator |
typedef string::const_reverse_iterator | const_reverse_iterator |
Public Member Functions | |
String () | |
Default constructor. More... | |
String (const string &str, size_type pos=0, size_type n=npos) | |
Construct from std string Construct from (part of) other string: acts as copy constructor. More... | |
String (const Char *s, size_type n) | |
Construct from char* with given length. More... | |
String (const Char *s) | |
Construct from char array. More... | |
String (size_type n, Char c) | |
Construct from a single char (repeated n times) More... | |
template<class InputIterator > | |
String (InputIterator begin, InputIterator end) | |
Construct from iterator. More... | |
String (Char c) | |
From single char (** Casacore addition). More... | |
String (const SubString &str) | |
Construct from a SubString. More... | |
String (ostringstream &os) | |
Construct from a stream. More... | |
~String () | |
Destructor. More... | |
String & | operator= (const string &str) |
Assignments (they are all deep copies according to standard) More... | |
String & | operator= (const SubString &str) |
String & | operator= (const Char *s) |
String & | operator= (Char c) |
SubString | operator() (size_type pos, size_type len) |
Casacore addition: synonym for at(pos, len) More... | |
String & | operator+= (const string &str) |
Concatenate. More... | |
String & | operator+= (const Char *s) |
String & | operator+= (Char c) |
const_reference | operator[] (size_type pos) const |
Indexing. More... | |
reference | operator[] (size_type pos) |
const_reference | elem (size_type pos) const |
*** Casacore addition More... | |
Char | firstchar () const |
Char | lastchar () const |
iterator | begin () |
Iterators. More... | |
const_iterator | begin () const |
iterator | end () |
const_iterator | end () const |
reverse_iterator | rbegin () |
const_reverse_iterator | rbegin () const |
reverse_iterator | rend () |
const_reverse_iterator | rend () const |
size_type | size () const |
Capacity, size. More... | |
size_type | length () const |
size_type | max_size () const |
size_type | capacity () const |
Int | allocation () const |
** Casacore addition – works as a capacity(n) – Note Int More... | |
String & | resize (size_type n) |
Resize by truncating or extending with copies of c (default Char()) More... | |
String & | resize (size_type n, Char c) |
String & | reserve (size_type res_arg=0) |
void | alloc (size_type n) |
** Casacore addition – works as a resize(n) More... | |
void | clear () |
Clear the string Warning: clear() executed as erase() due to missing clear() in gcc More... | |
Bool | empty () const |
Test for empty. More... | |
const_reference | at (size_type n) const |
Addressing. More... | |
reference | at (size_type n) |
String & | append (const string &str) |
Append. More... | |
String & | append (const string &str, size_type pos, size_type n) |
String & | append (const Char *s, size_type n) |
String & | append (const Char *s) |
String & | append (size_type n, Char c) |
template<class InputIterator > | |
String & | append (InputIterator first, InputIterator last) |
String & | append (Char c) |
** Casacore addition More... | |
String & | assign (const string &str) |
Assign. More... | |
String & | assign (const string &str, size_type pos, size_type n) |
String & | assign (const Char *s, size_type n) |
String & | assign (const Char *s) |
String & | assign (size_type n, Char c) |
template<class InputIterator > | |
String & | assign (InputIterator first, InputIterator last) |
String & | assign (Char c) |
** Casacore addition More... | |
String & | insert (size_type pos1, const string &str) |
Insert. More... | |
String & | insert (size_type pos1, const string &str, size_type pos2, size_type n) |
String & | insert (size_type pos, const Char *s, size_type n) |
String & | insert (size_type pos, const Char *s) |
String & | insert (size_type pos, size_type n, Char c) |
String & | insert (size_type pos, Char c) |
** Casacore addition More... | |
iterator | insert (iterator p, Char c) |
void | insert (iterator p, size_type n, Char c) |
template<class InputIterator > | |
void | insert (iterator p, InputIterator first, InputIterator last) |
String & | insert (iterator p, const string &str) |
** Casacore additions More... | |
String & | insert (iterator p, const Char *s, size_type n) |
String & | insert (iterator p, const Char *s) |
Int | compare (const string &str) const |
Compare. More... | |
Int | compare (size_type pos1, size_type n1, const string &str) const |
Int | compare (size_type pos1, size_type n1, const string &str, size_type pos2, size_type n2) const |
Int | compare (const Char *s) const |
Int | compare (size_type pos1, size_type n1, const Char *s, size_type n2=npos) const |
String & | erase (size_type pos, size_type n=npos) |
Erase. More... | |
iterator | erase (iterator position) |
iterator | erase (iterator first, iterator last) |
String & | replace (size_type pos1, size_type n1, const string &str) |
Replace. More... | |
String & | replace (size_type pos1, size_type n1, const string &str, size_type pos2, size_type n2) |
String & | replace (size_type pos, size_type n1, const Char *s, size_type n2) |
String & | replace (size_type pos, size_type n1, const Char *s) |
String & | replace (size_type pos, size_type n1, size_type n2, Char c) |
String & | replace (size_type pos, size_type n1, Char c) |
** Casacore addition More... | |
String & | replace (iterator i1, iterator i2, const string &str) |
String & | replace (iterator i1, iterator i2, const Char *s, size_type n) |
String & | replace (iterator i1, iterator i2, const Char *s) |
String & | replace (iterator i1, iterator i2, size_type n, Char c) |
String & | replace (iterator i1, iterator i2, Char c) |
** Casacore addition More... | |
template<class InputIterator > | |
String & | replace (iterator i1, iterator i2, InputIterator j1, InputIterator j2) |
size_type | copy (Char *s, size_type n, size_type pos=0) const |
Copy. More... | |
void | swap (string &s) |
Swap. More... | |
const Char * | c_str () const |
Get char array. More... | |
const Char * | data () const |
As pointer to char array More... | |
const Char * | chars () const |
** Casacore synonym More... | |
allocator_type | get_allocator () const |
Get allocator used Warning: gcc has no get_allocator() More... | |
String | substr (size_type pos=0, size_type n=npos) const |
Get a sub string. More... | |
template<typename T > | |
Bool | fromString (T &value, Bool chk=True) const |
Convert a String to a value. More... | |
template<typename T > | |
T | fromString () const |
void | trim () |
Remove beginning and ending whitespace. More... | |
void | trim (char c[], uInt n) |
Remove specified chars from beginning and end of string. More... | |
void | ltrim (char c) |
Remove specified character from beginning of string. More... | |
void | rtrim (char c) |
Remove specified character from end of string. More... | |
Bool | startsWith (const string &beginString) const |
Does the string start with the specified string? More... | |
size_type | find (const string &str, size_type pos=0) const |
Search functions. More... | |
size_type | find (const Char *s, size_type pos=0) const |
size_type | find (const Char *s, size_type pos, size_type n) const |
size_type | find (Char c, size_type pos=0) const |
size_type | find (const Regex &r, size_type pos=0) const |
size_type | rfind (const string &str, size_type pos=npos) const |
size_type | rfind (const Char *s, size_type pos=npos) const |
size_type | rfind (const Char *s, size_type pos, size_type n) const |
size_type | rfind (Char c, size_type pos=npos) const |
size_type | find_first_of (const string &str, size_type pos=0) const |
size_type | find_first_of (const Char *s, size_type pos=0) const |
size_type | find_first_of (const Char *s, size_type pos, size_type n) const |
size_type | find_first_of (Char c, size_type pos=0) const |
size_type | find_last_of (const string &str, size_type pos=npos) const |
size_type | find_last_of (const Char *s, size_type pos=npos) const |
size_type | find_last_of (const Char *s, size_type pos, size_type n) const |
size_type | find_last_of (Char c, size_type pos=npos) const |
size_type | find_first_not_of (const string &str, size_type pos=0) const |
size_type | find_first_not_of (const Char *s, size_type pos=0) const |
size_type | find_first_not_of (const Char *s, size_type pos, size_type n) const |
size_type | find_first_not_of (Char c, size_type pos=0) const |
size_type | find_last_not_of (const string &str, size_type pos=npos) const |
size_type | find_last_not_of (const Char *s, size_type pos=npos) const |
size_type | find_last_not_of (const Char *s, size_type pos, size_type n) const |
size_type | find_last_not_of (Char c, size_type pos=npos) const |
Bool | contains (Char c) const |
Containment. More... | |
Bool | contains (const string &str) const |
Bool | contains (const Char *s) const |
Bool | contains (const Regex &r) const |
Bool | contains (Char c, Int pos) const |
Does the string starting at the given position contain the given substring? If the position is negative, it is counted from the end. More... | |
Bool | contains (const string &str, Int pos) const |
Bool | contains (const Char *s, Int pos) const |
Bool | contains (const Regex &r, Int pos) const |
Bool | matches (const string &str, Int pos=0) const |
Matches entire string from pos (or till pos if negative pos). More... | |
Bool | matches (Char c, Int pos=0) const |
Bool | matches (const Char *s, Int pos=0) const |
Bool | matches (const Regex &r, Int pos=0) const |
void | prepend (const string &str) |
Concatenate by prepending the argument onto String. More... | |
void | prepend (const Char *s) |
void | prepend (Char c) |
size_type | index (Char c, Int startpos=0) const |
Return the position of the target in the string or npos for failure. More... | |
size_type | index (const string &str, Int startpos=0) const |
size_type | index (const Char *s, Int startpos=0) const |
size_type | index (const Regex &r, Int startpos=0) const |
Int | freq (Char c) const |
Return the number of occurences of target in String. More... | |
Int | freq (const string &str) const |
Int | freq (const Char *s) const |
SubString | at (size_type pos, size_type len) |
Extract the string "at" the argument's position. More... | |
String | at (size_type pos, size_type len) const |
SubString | at (const string &str, Int startpos=0) |
String | at (const string &str, Int startpos=0) const |
SubString | at (const Char *s, Int startpos=0) |
String | at (const Char *s, Int startpos=0) const |
SubString | at (Char c, Int startpos=0) |
String | at (Char c, Int startpos=0) const |
SubString | at (const Regex &r, Int startpos=0) |
String | at (const Regex &r, Int startpos=0) const |
SubString | at (Int pos, Int len) |
Next ones for overloading reasons. More... | |
String | at (Int pos, Int len) const |
SubString | at (Int pos, size_type len) |
String | at (Int pos, size_type len) const |
SubString | before (size_type pos) const |
Start at startpos and extract the string "before" the argument's position, exclusive. More... | |
SubString | before (const string &str, size_type startpos=0) const |
SubString | before (const Char *s, size_type startpos=0) const |
SubString | before (Char c, size_type startpos=0) const |
SubString | before (const Regex &r, size_type startpos=0) const |
SubString | before (Int pos) const |
Next one for overloading reasons. More... | |
SubString | through (size_type pos) |
Start at startpos and extract the SubString "through" to the argument's position, inclusive. More... | |
SubString | through (const string &str, size_type startpos=0) |
SubString | through (const Char *s, size_type startpos=0) |
SubString | through (Char c, size_type startpos=0) |
SubString | through (const Regex &r, size_type startpos=0) |
SubString | through (Int pos) |
Next one for overloading reasons. More... | |
SubString | from (size_type pos) |
Start at startpos and extract the SubString "from" the argument's position, inclusive, to the String's end. More... | |
SubString | from (const string &str, size_type startpos=0) |
SubString | from (const Char *s, size_type startpos=0) |
SubString | from (Char c, size_type startpos=0) |
SubString | from (const Regex &r, size_type startpos=0) |
SubString | from (Int pos) |
Next one for overloading reasons. More... | |
SubString | after (size_type pos) |
Start at startpos and extract the SubString "after" the argument's position, exclusive, to the String's end. More... | |
SubString | after (const string &str, size_type startpos=0) |
SubString | after (const Char *s, size_type startpos=0) |
SubString | after (Char c, size_type startpos=0) |
SubString | after (const Regex &r, size_type startpos=0) |
SubString | after (Int pos) |
Next one for overloading reasons. More... | |
void | reverse () |
Maybe forget some. More... | |
void | capitalize () |
internal transformation to capitalization of String. More... | |
void | upcase () |
internal transformation to uppercase of String More... | |
void | downcase () |
internal transformation to lowercase of String More... | |
void | del (size_type pos, size_type len) |
Delete len chars starting at pos. More... | |
void | del (const string &str, size_type startpos=0) |
Delete the first occurrence of target after startpos. More... | |
void | del (const Char *s, size_type startpos=0) |
void | del (Char c, size_type startpos=0) |
void | del (const Regex &r, size_type startpos=0) |
void | del (Int pos, Int len) |
Overload problem. More... | |
Int | gsub (const string &pat, const string &repl) |
Global substitution: substitute all occurrences of pat with repl, and return the number of replacements. More... | |
Int | gsub (const Char *pat, const string &repl) |
Int | gsub (const Char *pat, const Char *repl) |
Int | gsub (const Regex &pat, const string &repl) |
Static Public Member Functions | |
static String | format (const char *picture,...) |
Create a formatted string using the given printf format string. More... | |
static Int | toInt (const String &s, Bool chk=False) |
Convert a string to an Int, Float or Double. More... | |
static Float | toFloat (const String &s, Bool chk=False) |
static Double | toDouble (const String &s, Bool chk=False) |
template<typename T > | |
static String | toString (const T &value) |
Convert a value to a String. More... | |
Static Public Attributes | |
static const size_type | npos |
Private Member Functions | |
SubString | _substr (size_type first, size_type l) const |
Helper functions for at, before etc. More... | |
void | throwFromStringError () const |
Helper function for fromString. More... | |
String: the storage and methods of handling collections of characters.
Public interface
The String class name is a continuation of the "C" language custom of refering to collections of characters as "strings of characters".
The String class is the Casacore implementation of a string class. It is from the standard library string class, and all operations and behaviour of strings as defined in the standard are available for a String. The only difference is the extension with additional functions in the Casacore String class as compared to the standard string class.
The String class may be instantiated in many ways:
String myChar('C');
String myWord("Yowza");
String myFoo("fooey", 3);
As well as the copy and default constructors and iterator based ones.
A String may be concatinated with another object (String, or char*) with either prepending or postpending. A search for the position of a character within a String may return its position, a Bool that it is contained within or a Bool confirming your guess at the character's position is correct. A check of the frequency of occurance of a string within a String will return the number of occurances.
Strings may be extracted from Strings at, before, through, from and after a starting position within the String. Deletion of characters is possible after a given position within the String. Global substitution of characters within a String is provided, as well. Splitting of Strings into a carray of Strings is possible, based upon a given separator character, with a return value of the number of elements split. The joining together of the elements of an array of Strings into one String is possible.
Finally, transformations of case and conversions of type are provided.
The standard string class provides the following functionality:
The Casacore additions are:
at(1,2) = ";"
) The String class eases the handling of characters within the Casacore environment.
typedef string::allocator_type casacore::String::allocator_type |
typedef string::const_iterator casacore::String::const_iterator |
typedef string::const_pointer casacore::String::const_pointer |
typedef string::const_reference casacore::String::const_reference |
typedef string::const_reverse_iterator casacore::String::const_reverse_iterator |
typedef string::difference_type casacore::String::difference_type |
typedef string::iterator casacore::String::iterator |
typedef string::pointer casacore::String::pointer |
typedef string::reference casacore::String::reference |
typedef string::reverse_iterator casacore::String::reverse_iterator |
typedef string::size_type casacore::String::size_type |
typedef string::traits_type casacore::String::traits_type |
typedef string::value_type casacore::String::value_type |
|
inline |
|
inline |
|
inline |
|
inlineexplicit |
|
inline |
casacore::String::String | ( | ostringstream & | os | ) |
Construct from a stream.
|
inline |
|
inline |
|
inline |
Append.
Warning: The standard has a void push_back(const Char)
which is completely undefined; It probably is a remnant of the full list of container functions pop/push back/front;
Definition at line 398 of file String.h.
Referenced by casacore::String_global_functions_concatenator::operator+().
|
inline |
Definition at line 406 of file String.h.
References casacore::C::c.
|
inline |
|
inline |
Definition at line 429 of file String.h.
References casacore::C::c.
|
inline |
Addressing.
Definition at line 384 of file String.h.
Referenced by at(), firstchar(), lastchar(), and operator()().
Start at startpos and extract the string "before" the argument's position, exclusive.
Referenced by before().
|
inline |
|
inline |
|
inline |
Get char array.
As a proper null terminated C-string
Definition at line 557 of file String.h.
Referenced by casacore::FITSExtInfo::get_keyword(), casacore::FunctionMarshallable::loadFuncType(), casacore::operator<<(), and casacore::AipsError::what().
void casacore::String::capitalize | ( | ) |
internal transformation to capitalization of String.
|
inline |
** Casacore synonym
Definition at line 561 of file String.h.
Referenced by casacore::VariableArrayFITSFieldCopier< recordType, fitsType >::copyToFITS().
|
inline |
|
inline |
Compare.
Returns 0 if strings equal and of equal size; else positive if str larger or longer; else negative.
Warning: The gcc compiler does not have the proper standard compare functions; Hence they are locally implemented;
Definition at line 483 of file String.h.
Referenced by casacore::String_global_functions_comparitor::operator!=(), casacore::String_global_functions_comparitor::operator<(), casacore::String_global_functions_comparitor::operator<=(), casacore::String_global_functions_comparitor::operator==(), casacore::String_global_functions_comparitor::operator>(), and casacore::String_global_functions_comparitor::operator>=().
Does the string starting at the given position contain the given substring? If the position is negative, it is counted from the end.
Definition at line 1024 of file String.h.
References casacore::C::c, index(), and npos.
|
inline |
Copy.
Definition at line 548 of file String.h.
References casacore::copy().
|
inline |
As pointer to char array
Definition at line 559 of file String.h.
Referenced by casacore::LSQaips::getErrors(), and casacore::LSQaips::solve().
void casacore::String::del | ( | const string & | str, |
size_type | startpos = 0 |
||
) |
void casacore::String::downcase | ( | ) |
internal transformation to lowercase of String
|
inline |
|
inline |
Test for empty.
Definition at line 377 of file String.h.
Referenced by casacore::TempLatticeImpl< T >::canReferenceArray(), casacore::TableKeyword::isFixed(), casacore::TempLatticeImpl< T >::isPaged(), casacore::TableMeasRefDesc::isRefCodeVariable(), casacore::TableQuantumDesc::isUnitVariable(), casacore::TaqlRegex::match(), and casacore::TableParse::test().
|
inline |
|
inline |
Definition at line 652 of file String.h.
References casacore::C::c.
Search functions.
Returns either npos (if not found); else position.
Warning: The Regex ones are ** Casacore additions
Definition at line 646 of file String.h.
Referenced by contains(), index(), and startsWith().
Definition at line 685 of file String.h.
References casacore::C::c.
Definition at line 669 of file String.h.
References casacore::C::c.
Definition at line 693 of file String.h.
References casacore::C::c.
Definition at line 677 of file String.h.
References casacore::C::c.
|
inline |
|
static |
Create a formatted string using the given printf format string.
Return the number of occurences of target in String.
Int casacore::String::freq | ( | const string & | str | ) | const |
|
inline |
Definition at line 595 of file String.h.
References casacore::value().
Convert a String to a value.
All characters in the string must be used. It uses a shift from an ostringstream, so that operator must exist for the data type used.
In case of an error, an exception is thrown if chk
is set. Otherwise it returns False and value
contains the value read so far.
Definition at line 585 of file String.h.
References casacore::False, throwFromStringError(), casacore::True, and casacore::value().
|
inline |
Get allocator used
Warning: gcc has no get_allocator()
Int casacore::String::gsub | ( | const string & | pat, |
const string & | repl | ||
) |
Return the position of the target in the string or npos for failure.
Definition at line 740 of file String.h.
References casacore::C::c, find(), length(), and rfind().
Referenced by contains().
Definition at line 460 of file String.h.
References casacore::C::c.
|
inline |
Definition at line 462 of file String.h.
References casacore::C::c.
Definition at line 454 of file String.h.
References casacore::C::c.
|
inline |
|
inline |
Definition at line 345 of file String.h.
References casacore::length().
Referenced by casacore::VariableArrayFITSFieldCopier< recordType, fitsType >::copyToFITS(), index(), and lastchar().
void casacore::String::ltrim | ( | char | c | ) |
Remove specified character from beginning of string.
If the character is repeated more than once on the left, all instances will be removed; e.g. ltrim(',') results in ",,xy" becoming "xy".
Definition at line 723 of file String.h.
References casacore::C::c, matches(), and String().
Matches entire string from pos (or till pos if negative pos).
Referenced by casacore::TaqlRegex::match(), and matches().
Definition at line 307 of file String.h.
References casacore::C::c.
|
inline |
Definition at line 296 of file String.h.
References casacore::C::c, and casacore::operator=().
Definition at line 294 of file String.h.
References casacore::operator=().
|
inline |
Assignments (they are all deep copies according to standard)
Definition at line 290 of file String.h.
References casacore::operator=().
|
inline |
void casacore::String::prepend | ( | Char | c | ) |
void casacore::String::prepend | ( | const Char * | s | ) |
void casacore::String::prepend | ( | const string & | str | ) |
Concatenate by prepending the argument onto String.
|
inline |
|
inline |
|
inline |
|
inline |
** Casacore addition
Definition at line 536 of file String.h.
References casacore::C::c, and casacore::replace().
Definition at line 531 of file String.h.
References casacore::replace().
Definition at line 529 of file String.h.
References casacore::replace().
Definition at line 527 of file String.h.
References casacore::replace().
|
inline |
Definition at line 539 of file String.h.
References casacore::replace().
Definition at line 533 of file String.h.
References casacore::C::c, and casacore::replace().
** Casacore addition
Definition at line 525 of file String.h.
References casacore::C::c, and casacore::replace().
Definition at line 520 of file String.h.
References casacore::replace().
|
inline |
Definition at line 518 of file String.h.
References casacore::replace().
Definition at line 522 of file String.h.
References casacore::C::c, and casacore::replace().
Replace.
Definition at line 513 of file String.h.
References casacore::replace().
|
inline |
Definition at line 515 of file String.h.
References casacore::replace().
Resize by truncating or extending with copies of c
(default Char())
Tip: The reserve length given is non-binding on the implementation
Definition at line 361 of file String.h.
Referenced by casacore::LSQaips::getErrors(), and casacore::LSQaips::solve().
Definition at line 363 of file String.h.
References casacore::C::c.
void casacore::String::reverse | ( | ) |
Definition at line 661 of file String.h.
References casacore::C::c.
void casacore::String::rtrim | ( | char | c | ) |
Remove specified character from end of string.
If the character is repeated more than once on the right, all instances will be removed; e.g. rtrim(',') results in "xy,," becoming "xy".
|
inline |
|
inline |
|
inline |
|
private |
Helper function for fromString.
Referenced by fromString().
Convert a string to an Int, Float or Double.
In case of an error, an exception is thrown if chk
is set. Otherwise the value read so far is returned (0 if nothing read).
|
inlinestatic |
Convert a value to a String.
It uses a shift into an ostringstream, so that operator must be defined for the data type used.
Definition at line 616 of file String.h.
References casacore::value().
void casacore::String::trim | ( | ) |
Remove beginning and ending whitespace.
void casacore::String::trim | ( | char | c[], |
uInt | n | ||
) |
Remove specified chars from beginning and end of string.
void casacore::String::upcase | ( | ) |
internal transformation to uppercase of String
|
static |
Definition at line 246 of file String.h.
Referenced by contains().