String.h

Classes

SubString -- SubString help class to be used in at, before, ... (full description)
String -- String: the storage and methods of handling collections of characters. (full description)
Global Functions -- Global concatenation operators (full description)
Global Functions -- Global comparison operators (full description)
Global Functions -- Splitting (full description)
Global Functions -- Some general functions (full description)
Global Functions -- Casing and related functions (full description)
Global Functions -- IO (full description)

class SubString

Interface

Public Members
operator const string() const
SubString &operator=(const SubString &str)
SubString &operator=(const String &str)
SubString &operator=(const Char *s)
SubString &operator=(const Char c)
const Char *chars() const
string::size_type length() const
Private Members
SubString(const string &str, string::size_type pos, string::size_type len)

Description

Synopsis

The SubString class can only be used by the String class to be able to operate the aips++ defined replacement operators at, before, after, through, from. The class is used transparently in operations like:
	string.at(2,3) = "five";
If the SubString starts at a position outside the length of the original string (like e.g. in after(1000000)), a zero length string is created (not an exception thrown like in standard string operations).

Member Description

operator const string() const

Make a string

SubString &operator=(const SubString &str)
SubString &operator=(const String &str)
SubString &operator=(const Char *s)
SubString &operator=(const Char c)

Assignment

const Char *chars() const

Get as (const) C array

string::size_type length() const

Obtain length

SubString(const string &str, string::size_type pos, string::size_type len)

Constructor (there are no public constructors)

class String : public string

Interface

Public Members
String() : string("")
String(const string& str, size_type pos=0, size_type n=npos) : string(str, pos, n)
String(const Char* s, size_type n) : string(s, n)
String(const Char* s) : string(s)
String(size_type n, Char c) : string(n, c)
template<class InputIterator> String(InputIterator begin, InputIterator end) : string(begin, end)
explicit String(Char c) : string(1, c)
String(const SubString &str) : string(str.ref_p, str.pos_p, str.len_p)
String(ostringstream &os)
~String()
String& operator=(const string& str)
String& operator=(const SubString &str)
String& operator=(const Char* s)
String& operator=(Char c)
SubString operator()(size_type pos, size_type len)
String& operator+=(const string& str)
String& operator+=(const Char* s)
String& operator+=(Char c)
const_reference operator[](size_type pos) const
reference operator[](size_type pos)
const_reference elem(size_type pos) const
Char firstchar() const
Char lastchar() const
iterator begin()
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
size_type length() const
size_type max_size() const
size_type capacity() const
Int allocation() const
String& resize(size_type n)
String& resize(size_type n, Char c)
String& reserve(size_type res_arg = 0)
void alloc(size_type n)
void clear()
Bool empty() const
const_reference at(size_type n) const
reference at(size_type n)
String& append(const string& str)
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)
String& assign(const string& str)
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)
String& insert(size_type pos1, const string& str)
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)
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)
String& insert(iterator p, const Char* s, size_type n)
String& insert(iterator p, const Char* s)
Int compare(const string& str) const
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)
iterator erase(iterator position)
iterator erase(iterator first, iterator last)
String& replace(size_type pos1, size_type n1, const string& str)
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)
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)
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
void swap(string& s)
const Char *c_str() const
const Char *data() const
const Char *chars() const
allocator_type get_allocator() const
String substr(size_type pos=0, size_type n=npos) const
size_type find(const string &str, size_type pos=0) const
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 RegexBase &r, size_type pos=0) const
size_type rfind(const string &str, size_type pos=0) const
size_type rfind(const Char *s, size_type pos=0) const
size_type rfind(const Char *s, size_type pos, size_type n) const
size_type rfind(Char c, size_type pos=0) const
size_type rfind(const RegexBase &r, size_type pos=0) 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=0) const
size_type find_last_of(const Char *s, size_type pos=0) 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=0) 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=0) const
size_type find_last_not_of(const Char *s, size_type pos=0) 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=0) const
Bool contains(Char c) const
Bool contains(const string &str) const
Bool contains(const Char *s) const
Bool contains(const RegexBase &r) const
Bool contains(Char c, Int pos) const
Bool contains(const string &str, Int pos) const
Bool contains(const Char *s, Int pos) const
Bool contains(const RegexBase &r, Int pos) const
Bool matches(const string &str, Int pos = 0) const
Bool matches(Char c, Int pos = 0) const
Bool matches(const Char *s, Int pos = 0) const
Bool matches(const RegexBase &r, Int pos = 0) const
void prepend(const string &str)
void prepend(const Char *s)
void prepend(Char c)
size_type index(Char c, Int startpos = 0) const
size_type index(const string &str, Int startpos = 0) const
size_type index(const Char *s, Int startpos = 0) const
size_type index(const RegexBase &r, Int startpos = 0) const
Int freq(Char c) const
Int freq(const string &str) const
Int freq(const Char *s) const
SubString at(size_type pos, size_type len)
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 RegexBase &r, Int startpos = 0)
String at(const RegexBase &r, Int startpos = 0) const
SubString at(Int pos, Int len)
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)
SubString before(const string &str, Int startpos = 0)
SubString before(const Char *s, Int startpos = 0)
SubString before(Char c, Int startpos = 0)
SubString before(const RegexBase &r, Int startpos = 0)
SubString before(Int pos)
SubString through(size_type pos)
SubString through(const string &str, Int startpos = 0)
SubString through(const Char *s, Int startpos = 0)
SubString through(Char c, Int startpos = 0)
SubString through(const RegexBase &r, Int startpos = 0)
SubString through(Int pos)
SubString from(size_type pos)
SubString from(const string &str, Int startpos = 0)
SubString from(const Char *s, Int startpos = 0)
SubString from(Char c, Int startpos = 0)
SubString from(const RegexBase &r, Int startpos = 0)
SubString from(Int pos)
SubString after(size_type pos)
SubString after(const string &str, Int startpos = 0)
SubString after(const Char *s, Int startpos = 0)
SubString after(Char c, Int startpos = 0)
SubString after(const RegexBase &r, Int startpos = 0)
SubString after(Int pos)
void reverse()
void capitalize()
void upcase()
void downcase()
void del(size_type pos, size_type len)
void del(const string &str, size_type startpos = 0)
void del(const Char *s, size_type startpos = 0)
void del(Char c, size_type startpos = 0)
void del(const RegexBase &r, size_type startpos = 0)
void del(Int pos, Int len)
Int gsub(const string &pat, const string &repl)
Int gsub(const Char *pat, const string &repl)
Int gsub(const Char *pat, const Char *repl)
Int gsub(const RegexBase &pat, const string &repl)
static String toString(Int value)
static String toString(uInt value)
Private Members
SubString _substr(size_type first, size_type l)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25
Programs:
Tests:
  • tString.cc

Prerequisite

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 aips++ implementation of a string class. It is closely based on 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 aips++ String class as compared to the standard string class.

The String class may be instantiated in many ways:

  1. A single character - String myChar('C');
  2. A Char* argument - String myWord("Yowza");
  3. 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:

  1. Construction from (part of) String, (part of) Char*, (repeating) Char, iterator pair.
  2. Assignment from String, Char*, Char
  3. Iterators: begin() and end(); rbegin() and rend() (Note: gcc reverse iterators still weak)
  4. Capacity: size, length, max_size, resize, capacity, reserve, clear, empty
  5. Special size: String::size_type, with indicator: String::npos
  6. Element access: [pos] and at(pos) (both const and non-const)
  7. 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.
  8. C-string: get Char* with c_str() or data() and get the relevant Allocator used (Note: not fully supported in gcc)
  9. 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*
  10. Globals: Addition operators for String, Char*, Char; all comparison operators for String and Char*; getline; input and output stream operators
  11. Typedef: All relevant typedefs for standard containers and iterator handling
The aips++ addition are:
  1. To standard: some Char function arguments where appropriate; RegexBase arguments in search like methods.
  2. 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) = ";")
  3. 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

 // Let's start with a simple string.
 String myString("the time");
 // add some more on the end...
 myString += " for all good men";
 // prepend some on the front...
 myString.prepend("Now is ");
 // do some concatination...
 String evenMore;
 evenMore += myString + " to come to";
 // do some three way concatination
 String allKeys, finishIt(" their country.");
 allKeys = evenMore + "the aid of" + finishIt;
 // find the spot where we put something earlier
 String::size_type position = allKeys.index(finishIt);
 // find if the word is in the String...
 Bool query = myString.contains("good men");
 // ask if the position we think is true is correct...
 Bool answer = allKeys.matches(finishIt, position);
 // How many spaces are in our phrase?
 Int spacesCount = allKeys.freq(" ");
 </scrblock>
 </example>

 <motivation>
 The String class eases the handling of characters within the AIPS++ 
 environment.
 </motivation>

 <todo asof=2000/12/05">
   <li> if old string disappeared; remove the alloc() call.
   <li> add more tests (for string methods) when old String disappears
 </todo>

Member Description

String() : string("")

Default constructor

String(const string& str, size_type pos=0, size_type n=npos) : string(str, pos, n)

Construct from std string Construct from (part of) other string: acts as copy constructor

Thrown Exceptions

String(const Char* s, size_type n) : string(s, n)

Construct from char* with given length

Thrown Exceptions

String(const Char* s) : string(s)

Construct from char array

String(size_type n, Char c) : string(n, c)

Construct from a single char (repeated n times)

Thrown Exceptions

template<class InputIterator> String(InputIterator begin, InputIterator end) : string(begin, end)

Construct from iterator

explicit String(Char c) : string(1, c)

From single char (** aips++ addition).

Warning Note that there is no automatic Char-to-String conversion available. This stops inadvertent conversions of integer to string.

String(const SubString &str) : string(str.ref_p, str.pos_p, str.len_p)

Construct from a SubString

String(ostringstream &os)

Construct from a stream.

~String()

Destructor

String& operator=(const string& str)
String& operator=(const SubString &str)
String& operator=(const Char* s)
String& operator=(Char c)

Assignments (they are all deep copies according to standard)

SubString operator()(size_type pos, size_type len)

** aips++ addition: synonym for at(pos, len)

String& operator+=(const string& str)
String& operator+=(const Char* s)
String& operator+=(Char c)

Concatenate

const_reference operator[](size_type pos) const
reference operator[](size_type pos)

Indexing. The standard version is undefined if pos > size(), or pos >= size() for non-const version.

Warning The const_reference version needs the at() version for the gcc compiler: no const [] exists.

const_reference elem(size_type pos) const
Char firstchar() const
Char lastchar() const

*** aips++ addition

iterator begin()
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

Iterators

Int allocation() const

Capacity, size

** aips++ addition -- works as a capacity(n) -- Note Int

size_type size() const
size_type length() const
size_type max_size() const
size_type capacity() const

Capacity, size

void alloc(size_type n)

Resize by truncating or extending with copies of c (default Char())

Thrown Exceptions

** aips++ addition -- works as a resize(n)

String& resize(size_type n)
String& resize(size_type n, Char c)
String& reserve(size_type res_arg = 0)

Resize by truncating or extending with copies of c (default Char())

Thrown Exceptions

void clear()

Clear the string

Warning clear() executed as erase() due to missing clear() in gcc

Bool empty() const

Test for empty

const_reference at(size_type n) const
reference at(size_type n)

Addressing

Thrown Exceptions

String& append(Char c)

Append

Thrown Exceptions

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.

** aips++ addition

String& append(const string& str)
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)

Append

Thrown Exceptions

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.

String& assign(Char c)

Assign

Thrown Exceptions

** aips++ addition

String& assign(const string& str)
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)

Assign

Thrown Exceptions

String& insert(size_type pos, Char c)

Insert

Thrown Exceptions

** aips++ addition

String& insert(size_type pos1, const string& str)
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)
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)

Insert

Thrown Exceptions

String& insert(iterator p, const string& str)
String& insert(iterator p, const Char* s, size_type n)
String& insert(iterator p, const Char* s)

** aips++ additions

Int compare(const string& str) const
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

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.

String& erase(size_type pos, size_type n = npos)
iterator erase(iterator position)
iterator erase(iterator first, iterator last)

Erase

String& replace(size_type pos, size_type n1, Char c)

Replace

Thrown Exceptions

** aips++ addition

String& replace(iterator i1, iterator i2, Char c)

Replace

Thrown Exceptions

** aips++ addition

String& replace(size_type pos1, size_type n1, const string& str)
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(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)
template<class InputIterator> String& replace(iterator i1, iterator i2, InputIterator j1, InputIterator j2)

Replace

Thrown Exceptions

size_type copy(Char* s, size_type n, size_type pos = 0) const

Copy

Thrown Exceptions

void swap(string& s)

Swap

const Char *c_str() const

Get char array

As a proper null terminated C-string

const Char *data() const

Get char array

As pointer to char array

const Char *chars() const

Get char array

** aips++ synonym

allocator_type get_allocator() const

Get allocator used

Warning gcc has no get_allocator()

String substr(size_type pos=0, size_type n=npos) const

Get a sub string

Thrown Exceptions

size_type find(const string &str, size_type pos=0) const
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 RegexBase &r, size_type pos=0) const
size_type rfind(const string &str, size_type pos=0) const
size_type rfind(const Char *s, size_type pos=0) const
size_type rfind(const Char *s, size_type pos, size_type n) const
size_type rfind(Char c, size_type pos=0) const
size_type rfind(const RegexBase &r, size_type pos=0) 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=0) const
size_type find_last_of(const Char *s, size_type pos=0) 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=0) 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=0) const
size_type find_last_not_of(const Char *s, size_type pos=0) 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=0) const

Search functions. Returns either npos (if not found); else position.

Warning The RegexBase ones are ** aips++ additions

Bool contains(Char c) const
Bool contains(const string &str) const
Bool contains(const Char *s) const
Bool contains(const RegexBase &r) const

Containment. ** aips++ addition

Bool contains(Char c, Int pos) const
Bool contains(const string &str, Int pos) const
Bool contains(const Char *s, Int pos) const
Bool contains(const RegexBase &r, Int pos) const

Containment after (or before if pos negative) pos. ** aips++ addition

Bool matches(const string &str, Int pos = 0) const
Bool matches(Char c, Int pos = 0) const
Bool matches(const Char *s, Int pos = 0) const
Bool matches(const RegexBase &r, Int pos = 0) const

Matches entire string from pos (or till pos if negative pos). ** aips++ addition

void prepend(const string &str)
void prepend(const Char *s)
void prepend(Char c)

Concatenate by prepending the argument onto String. ** aips++ addition

size_type index(Char c, Int startpos = 0) const
size_type index(const string &str, Int startpos = 0) const
size_type index(const Char *s, Int startpos = 0) const
size_type index(const RegexBase &r, Int startpos = 0) const

Return the position of the target in the string or npos for failure. ** aips++ addition

Int freq(Char c) const
Int freq(const string &str) const
Int freq(const Char *s) const

Return the number of occurences of target in String. ** aips++ addition

SubString at(size_type pos, size_type len)
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 RegexBase &r, Int startpos = 0)
String at(const RegexBase &r, Int startpos = 0) const

Extract the string "at" the argument's position. ** aips++ addition

SubString at(Int pos, Int len)
String at(Int pos, Int len) const
SubString at(Int pos, size_type len)
String at(Int pos, size_type len) const

Next ones for overloading reasons.
Tip It is better to use the substr() method in stead.

SubString before(Int pos)

Start at startpos and extract the string "before" the argument's position, exclusive. ** aips++ addition

Next one for overloading reasons

SubString before(size_type pos)
SubString before(const string &str, Int startpos = 0)
SubString before(const Char *s, Int startpos = 0)
SubString before(Char c, Int startpos = 0)
SubString before(const RegexBase &r, Int startpos = 0)

Start at startpos and extract the string "before" the argument's position, exclusive. ** aips++ addition

SubString through(Int pos)

Start at startpos and extract the SubString "through" to the argument's position, inclusive. ** aips++ addition

Next one for overloading reasons

SubString through(size_type pos)
SubString through(const string &str, Int startpos = 0)
SubString through(const Char *s, Int startpos = 0)
SubString through(Char c, Int startpos = 0)
SubString through(const RegexBase &r, Int startpos = 0)

Start at startpos and extract the SubString "through" to the argument's position, inclusive. ** aips++ addition

SubString from(Int pos)

Start at startpos and extract the SubString "from" the argument's position, inclusive, to the String's end. ** aips++ addition

Next one for overloading reasons

SubString from(size_type pos)
SubString from(const string &str, Int startpos = 0)
SubString from(const Char *s, Int startpos = 0)
SubString from(Char c, Int startpos = 0)
SubString from(const RegexBase &r, Int startpos = 0)

Start at startpos and extract the SubString "from" the argument's position, inclusive, to the String's end. ** aips++ addition

SubString after(Int pos)

Start at startpos and extract the SubString "after" the argument's position, exclusive, to the String's end. ** aips++ addition

Next one for overloading reasons

SubString after(size_type pos)
SubString after(const string &str, Int startpos = 0)
SubString after(const Char *s, Int startpos = 0)
SubString after(Char c, Int startpos = 0)
SubString after(const RegexBase &r, Int startpos = 0)

Start at startpos and extract the SubString "after" the argument's position, exclusive, to the String's end. ** aips++ addition

void capitalize()

Maybe forget some. ** aips++ addition

internal transformation to capitalization of String.

void upcase()

Maybe forget some. ** aips++ addition

internal transformation to uppercase of String

void downcase()

Maybe forget some. ** aips++ addition

internal transformation to lowercase of String

void reverse()

Maybe forget some. ** aips++ addition

void del(size_type pos, size_type len)

Delete len chars starting at pos. ** aips++ addition

void del(Int pos, Int len)

Delete the first occurrence of target after startpos. ** aips++ addition

Overload problem

void del(const string &str, size_type startpos = 0)
void del(const Char *s, size_type startpos = 0)
void del(Char c, size_type startpos = 0)
void del(const RegexBase &r, size_type startpos = 0)

Delete the first occurrence of target after startpos. ** aips++ addition

Int gsub(const string &pat, const string &repl)
Int gsub(const Char *pat, const string &repl)
Int gsub(const Char *pat, const Char *repl)
Int gsub(const RegexBase &pat, const string &repl)

Global substitution: substitute all occurrences of pat with repl, and return the number of replacements. ** aips++ addition

static String toString(Int value)
static String toString(uInt value)

Convert a integer to a String. This is a convenience function. Use the ostringstream class for conversion of floating point data types or more sophisticated formatting options.

SubString _substr(size_type first, size_type l)

Helper functions for at, before etc

Global concatenation operators (source)

Interface

inline String operator+(const String &lhs, const String &rhs)
inline String operator+(const Char *lhs, const String &rhs)
inline String operator+(Char lhs, const String &rhs)
inline String operator+(const String &lhs, const Char *rhs)
inline String operator+(const String &lhs, Char rhs)

Description

The global concatenation operators

Member Description

inline String operator+(const String &lhs, const String &rhs)

inline String operator+(const Char *lhs, const String &rhs)

inline String operator+(Char lhs, const String &rhs)

inline String operator+(const String &lhs, const Char *rhs)

inline String operator+(const String &lhs, Char rhs)


Global comparison operators (source)

Interface

inline Bool operator==(const String &x, const String &y)
inline Bool operator!=(const String &x, const String &y)
inline Bool operator>(const String &x, const String &y)
inline Bool operator>=(const String &x, const String &y)
inline Bool operator<(const String &x, const String &y)
inline Bool operator<=(const String &x, const String &y)
inline Bool operator==(const String &x, const Char *t)
inline Bool operator!=(const String &x, const Char *t)
inline Bool operator>(const String &x, const Char *t)
inline Bool operator>=(const String &x, const Char *t)
inline Bool operator<(const String &x, const Char *t)
inline Bool operator<=(const String &x, const Char *t)
inline Bool operator==(const String &x, const Char t)
inline Bool operator!=(const String &x, const Char t)
inline Bool operator>(const String &x, const Char t)
inline Bool operator>=(const String &x, const Char t)
inline Bool operator<(const String &x, const Char t)
inline Bool operator<=(const String &x, const Char t)
inline Int compare(const string &x, const string &y)
inline Int compare(const string &x, const Char *y)
inline Int compare(const string &x, const Char y)
Int fcompare(String x, String y)

Description

The global comparison operators

Member Description

inline Bool operator==(const String &x, const String &y)

inline Bool operator!=(const String &x, const String &y)

inline Bool operator>(const String &x, const String &y)

inline Bool operator>=(const String &x, const String &y)

inline Bool operator<(const String &x, const String &y)

inline Bool operator<=(const String &x, const String &y)

inline Bool operator==(const String &x, const Char *t)

inline Bool operator!=(const String &x, const Char *t)

inline Bool operator>(const String &x, const Char *t)

inline Bool operator>=(const String &x, const Char *t)

inline Bool operator<(const String &x, const Char *t)

inline Bool operator<=(const String &x, const Char *t)

inline Bool operator==(const String &x, const Char t)

inline Bool operator!=(const String &x, const Char t)

inline Bool operator>(const String &x, const Char t)

inline Bool operator>=(const String &x, const Char t)

inline Bool operator<(const String &x, const Char t)

inline Bool operator<=(const String &x, const Char t)

Int fcompare(String x, String y)

** aips++ additions of global compares. Returns 0 if equal; lt or gt 0 if strings unequal or of unequal lengths.

this version ignores case. ** aips++ addition. Result is 0 if equal strings of equal lengths; else lt or gt 0 to indicate differences.

inline Int compare(const string &x, const string &y)
inline Int compare(const string &x, const Char *y)
inline Int compare(const string &x, const Char y)

** aips++ additions of global compares. Returns 0 if equal; lt or gt 0 if strings unequal or of unequal lengths.


Splitting (source)

Interface

Int split(const string &str, string res[], Int maxn, const string &sep)
Int split(const string &str, string res[], Int maxn, const Char sep)
Int split(const string &str, string res[], Int maxn, const RegexBase &sep)

Description

Global function which splits the String into string array res at separator and returns the number of elements. ** aips++ addition

Member Description

Int split(const string &str, string res[], Int maxn, const string &sep)

Int split(const string &str, string res[], Int maxn, const Char sep)

Int split(const string &str, string res[], Int maxn, const RegexBase &sep)


Some general functions (source)

Interface

String common_prefix(const string &x, const string &y, Int startpos = 0)
String common_suffix(const string &x, const string &y, Int startpos = -1)
String replicate(Char c, String::size_type n)
String replicate(const string &str, String::size_type n)
String join(string src[], Int n, const string &sep)

Description

Functions to find special patterns, join and replicate

Member Description

String common_prefix(const string &x, const string &y, Int startpos = 0)

String common_suffix(const string &x, const string &y, Int startpos = -1)

String replicate(Char c, String::size_type n)

String replicate(const string &str, String::size_type n)

String join(string src[], Int n, const string &sep)


Casing and related functions (source)

Interface

String reverse(string str)
String upcase(string str)
String downcase(string str)
String capitalize(string str)

Description

Case conversion and rearrangement functions

Member Description

String reverse(string str)

Global function which returns a transformation to reverse order of String.

String upcase(string str)

Global function which returns a transformation to uppercase of String.

String downcase(string str)

Global function which returns a transformation to lowercase of String.

String capitalize(string str)

Global function which returns a transformation to capitalization of String.

IO (source)

Interface

ostream &operator<<(ostream &s, const String &x)

Description

Member Description

ostream &operator<<(ostream &s, const String &x)

Output