|
| 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 <tt>c</tt> (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 |
|
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...
|
|
|
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 | 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) |
|
String: the storage and methods of handling collections of characters.
Intended use:
Public interface
Review Status
- Reviewed By:
- UNKNOWN
- Date Reviewed:
- before2004/08/25
- Test programs:
- tString
Prerequisite
-
Regex - the regular expressions class
-
the std string class
Etymology
The String class name is a continuation of the "C" language custom of refering to collections of characters as "strings of characters".
Synopsis
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:
-
A single character -
String myChar('C');
-
A Char* argument -
String myWord("Yowza");
-
The first n chararcters of a pre-existing string -
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:
-
Construction from (part of) String, (part of) Char*, (repeating) Char, iterator pair.
-
Assignment from String, Char*, Char
-
Iterators: begin() and end(); rbegin() and rend() (Note: gcc reverse iterators still weak)
-
Capacity: size, length, max_size, resize, capacity, reserve, clear, empty
-
Special size: String::size_type, with indicator: String::npos
-
Element access: [pos] and at(pos) (both const and non-const)
-
Modifiers: += of String, Char*, Char; append of (part of) String, Char*, Char and iterator defined; assign() of (part of) String, Char* and (repeating) Char and iterator; insertion of same; replacing of same; erase of part of String; a copy and a swap.
-
C-string: get Char* with c_str() or data() and get the relevant Allocator used (Note: not fully supported in gcc)
-
Operations: find, rfind, find_first_of, find_last_of, find_first_not_of, find_last_not_of; substr (Note only readable substring); compare with (part of) String, Char*
-
Globals: Addition operators for String, Char*, Char; all comparison operators for String and Char*; getline; input and output stream operators
-
Typedef: All relevant typedefs for standard containers and iterator handling
The Casacore additions are:
-
To standard: some Char function arguments where appropriate; Regex arguments in search like methods.
-
Substring additions: at, before, after, from, through functions taking search String, Char* as arguments can give (hidden) substrings which can be assigned (as in
at(1,2) = ";"
)
-
Methods: prepend (in addition to standard append); del (as erase); global substitution of String and patterns; freq (count of occurance); split/join of strings at separator or pattern; upcase, downcase, reverse; common_suffix and _prefix; replicate; case insensitive compare; creation from stream
Example
myString += " for all good men";
myString.prepend("Now is ");
evenMore += myString + " to come to";
String allKeys, finishIt(
" their country.");
allKeys = evenMore + "the aid of" + finishIt;
Bool query = myString.contains(
"good men");
Bool answer = allKeys.matches(finishIt, position);
Int spacesCount = allKeys.freq(
" ");
Motivation
The String class eases the handling of characters within the Casacore environment.
To Do
-
if old string disappeared; remove the alloc() call.
-
add more tests (for string methods) when old String disappears
Definition at line 225 of file String.h.