|
casacore
|
String: the storage and methods of handling collections of characters. More...
#include <String.h>
Public Member Functions | |
| String ()=default | |
| Default constructor. | |
| String (const std::string &str, size_type pos=0, size_type n=npos) | |
| Construct from std::string Construct from (part of) other string: acts as copy constructor. | |
| String (const char *s, size_type n) | |
| Construct from char* with given length. | |
| String (const char *s) | |
| Construct from char array. | |
| String (size_type n, char c) | |
| Construct from a single char (repeated n times). | |
| template<class InputIterator> | |
| String (InputIterator begin, InputIterator end) | |
| Construct from iterator. | |
| String (char c) | |
| From single char (** Casacore addition). | |
| String (const SubString &str) | |
| Construct from a SubString. | |
| String (std::ostringstream &os) | |
| Construct from a stream. | |
| ~String ()=default | |
| Destructor. | |
| String & | operator= (const std::string &str) |
| Assignments (they are all deep copies according to standard). | |
| 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). | |
| const_reference | elem (size_type pos) const |
| *** Casacore addition | |
| char | firstchar () const |
| char | lastchar () const |
| int | allocation () const |
| ** Casacore addition – works as a capacity(n) – Note Int | |
| void | alloc (size_type n) |
| ** Casacore addition – works as a resize(n) | |
| std::string & | append (char c) |
| ** Casacore addition | |
| String & | assign (char c) |
| ** Casacore addition | |
| String & | insert (size_type pos, char c) |
| ** Casacore addition | |
| String & | replace (size_type pos, size_type n1, char c) |
| ** Casacore addition | |
| String & | replace (iterator i1, iterator i2, char c) |
| ** Casacore addition | |
| const char * | chars () const |
| ** Casacore synonym | |
| DEPRECATED ("Use std::format if possible, or FormatString() if the format string can't be changed (e.g. " "runtime determined)") static String format(const char *picture | |
| Create a formatted string using the given printf format string. | |
| template<typename T> | |
| bool | fromString (T &value, bool throw_on_error=true) const |
| Convert a String to a value. | |
| template<typename T> | |
| T | fromString () const |
| void | trim () |
| Remove beginning and ending whitespace. | |
| void | trim (char c[], unsigned int n) |
| Remove specified chars from beginning and end of string. | |
| void | ltrim (char c) |
| Remove specified character from beginning of string. | |
| void | rtrim (char c) |
| Remove specified character from end of string. | |
| bool | startsWith (const std::string &beginString) const |
| Does the string start with the specified string? | |
| size_type | find (const Regex &r, size_type pos=0) const |
| bool | contains (char c) const |
| Containment. | |
| DEPRECATED("Use find(str) != npos or StringContains()") bool contains(const std | DEPRECATED ("Use find(), rfind() or IndexString()") bool contains(char c |
| Does the string starting at the given position contain the given substring? | |
| DEPRECATED("Use find(), rfind(), IndexString() and/or StringContains()") bool contains(const std | DEPRECATED ("Use substr(pos) == str if possible, consider ends_with() / starts_with() for " "positive/negative pos or use EqualStringsAndNotEmpty() if direct replacement is necessary") bool matches(char c |
| Matches entire string from pos, or till pos if negative pos. | |
| void | prepend (const char *str) |
| void | prepend (char c) |
| DEPRECATED ("Use find() or rfind(), or IndexString() if the search direction is runtime-dependent") size_type index(char c | |
| Return the position of the target in the string or npos for failure. | |
| int | freq (char c) const |
| Return the number of occurences of target in String. | |
| int | freq (const std::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 std::string &str, int startpos=0) |
| String | at (const std::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. | |
| String | at (int pos, int len) const |
| SubString | at (int pos, size_type len) |
| String | at (int pos, size_type len) const |
| DEPRECATED ("Use substr(0, pos) or create a view. Also consider if str.start_with() suffices.") SubString before(size_type pos) | |
| Start at startpos and extract the string "before" the argument's position, exclusive. | |
| SubString | before (const std::string &str, size_type startpos=0) |
| SubString | before (const char *s, size_type startpos=0) |
| SubString | before (char c, size_type startpos=0) |
| SubString | before (const Regex &r, size_type startpos=0) |
| SubString | before (int pos) |
| Next one for overloading reasons. | |
| SubString | through (size_type pos) |
| Start at startpos and extract the SubString "through" to the argument's position, inclusive. | |
| SubString | through (const std::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. | |
| SubString | from (size_type pos) |
| Start at startpos and extract the SubString "from" the argument's position, inclusive, to the String's end. | |
| SubString | from (const std::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. | |
| SubString | after (size_type pos) |
| Start at startpos and extract the SubString "after" the argument's position, exclusive, to the String's end. | |
| SubString | after (const std::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. | |
| DEPRECATED ("Use std::reverse(str.begin(), str.end())") void reverse() | |
| Maybe forget some. | |
| void | capitalize () |
| internal transformation to capitalization of String. | |
| void | upcase () |
| internal transformation to uppercase of String | |
| void | downcase () |
| internal transformation to lowercase of String | |
| void | del (size_type pos, size_type len) |
| Delete len chars starting at pos. | |
| void | del (const std::string &str, size_type startpos=0) |
| Delete the first occurrence of target after startpos. | |
| 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. | |
| int | gsub (const std::string &pat, const std::string &repl) |
| Global substitution: substitute all occurrences of pat with repl, and return the number of replacements. | |
| int | gsub (const char *pat, const std::string &repl) |
| int | gsub (const char *pat, const char *repl) |
| int | gsub (const Regex &pat, const std::string &repl) |
Static Public Member Functions | |
| static int | toInt (const String &s, bool chk=false) |
| Convert a string to an Int, Float or Double. | |
| 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. | |
Public Attributes | |
| DEPRECATED("Use find(str) != npos or StringContains()") bool contains(const std int pos | const |
| DEPRECATED("Use find(), rfind(), IndexString() and/or StringContains()") bool contains(const std int | pos |
| int | startpos |
Private Member Functions | |
| SubString | _substr (size_type first, size_type l) const |
| Helper functions for at, before etc. | |
| void | throwFromStringError () const |
| Helper function for fromString. | |
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:
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:
The String class eases the handling of characters within the Casacore environment.
|
default |
Default constructor.
Referenced by assign(), at(), at(), at(), at(), at(), at(), at(), DEPRECATED(), insert(), operator=(), operator=(), operator=(), operator=(), replace(), replace(), String(), String(), toDouble(), toFloat(), toInt(), toString(), and ~String().
|
inline |
|
inline |
|
inline |
Construct from iterator.
Definition at line 381 of file String.h.
References casacore::begin(), and casacore::end().
|
inlineexplicit |
| casacore::String::String | ( | std::ostringstream & | os | ) |
Construct from a stream.
References String().
|
default |
Destructor.
References String().
References after(), DEPRECATED(), and startpos.
References after(), const, DEPRECATED(), and startpos.
References after(), const, DEPRECATED(), and startpos.
References after(), const, DEPRECATED(), and startpos.
|
inline |
|
inline |
|
inline |
** Casacore addition – works as a capacity(n) – Note Int
Definition at line 424 of file String.h.
References allocation().
Referenced by allocation().
|
inline |
** Casacore addition
Definition at line 432 of file String.h.
References append().
Referenced by append(), casacore::operator+(), casacore::operator+(), casacore::operator+(), casacore::operator+(), and casacore::operator+().
|
inline |
| SubString casacore::String::at | ( | char | c, |
| int | startpos = 0 ) |
References at(), DEPRECATED(), and startpos.
| String casacore::String::at | ( | char | c, |
| int | startpos = 0 ) const |
References at(), const, DEPRECATED(), startpos, and String().
References at(), const, DEPRECATED(), and startpos.
References at(), const, DEPRECATED(), startpos, and String().
References at(), const, DEPRECATED(), and startpos.
References at(), const, DEPRECATED(), startpos, and String().
References at(), const, DEPRECATED(), and startpos.
References at(), const, DEPRECATED(), startpos, and String().
|
inline |
|
inline |
References at(), DEPRECATED(), and pos.
Referenced by at(), at(), at(), at(), at(), at(), at(), at(), at(), at(), at(), at(), at(), at(), firstchar(), lastchar(), and operator()().
References before(), DEPRECATED(), and startpos.
References before(), const, DEPRECATED(), and startpos.
References before(), const, DEPRECATED(), and startpos.
References before(), const, DEPRECATED(), and startpos.
Referenced by before(), before(), before(), before(), before(), and DEPRECATED().
|
inline |
| void casacore::String::capitalize | ( | ) |
internal transformation to capitalization of String.
References capitalize(), and DEPRECATED().
Referenced by capitalize().
|
inline |
|
inline |
Containment.
Definition at line 554 of file String.h.
References contains(), and find().
Referenced by contains().
| void casacore::String::del | ( | char | c, |
| size_type | startpos = 0 ) |
References del(), DEPRECATED(), and startpos.
References const, del(), DEPRECATED(), and startpos.
References const, del(), DEPRECATED(), and startpos.
Delete the first occurrence of target after startpos.
References const, del(), DEPRECATED(), and startpos.
|
inline |
| casacore::String::DEPRECATED | ( | "Use | find) or rfind(, |
| or IndexString() if the search direction is runtime-dependent" | ) |
Return the position of the target in the string or npos for failure.
Searches the first index if the startpos >= 0, or the last index if startpos < 0. Casacore addition
References DEPRECATED().
| DEPRECATED("Use find(str) != npos or StringContains()") bool contains(const std casacore::String::DEPRECATED | ( | "Use | find(), |
| rfind() or IndexString()" | ) |
Does the string starting at the given position contain the given substring?
If the position is negative, it is counted from the end. Casacore addition
References DEPRECATED().
| casacore::String::DEPRECATED | ( | "Use std::format if | possible, |
| or FormatString() if the format string can 't be changed(e.g. " "runtime determined)" | ) const |
Create a formatted string using the given printf format string.
References const, DEPRECATED(), and String().
Referenced by after(), after(), after(), after(), after(), at(), at(), at(), at(), at(), at(), at(), at(), at(), before(), before(), before(), before(), capitalize(), del(), del(), del(), del(), del(), DEPRECATED(), DEPRECATED(), DEPRECATED(), DEPRECATED(), DEPRECATED(), DEPRECATED(), downcase(), find(), freq(), freq(), freq(), from(), from(), from(), from(), from(), gsub(), gsub(), gsub(), ltrim(), prepend(), rtrim(), through(), through(), through(), through(), through(), trim(), trim(), and upcase().
| casacore::String::DEPRECATED | ( | "Use std::reverse(str.begin(), str.end())" | ) |
Maybe forget some.
** Casacore addition
internal transformation to reverse order of String.
References DEPRECATED(), and casacore::reverse().
| casacore::String::DEPRECATED | ( | "Use substr(0, pos) or create a view. Also consider if str.start_with() suffices." | ) |
Start at startpos and extract the string "before" the argument's position, exclusive.
References before(), DEPRECATED(), and pos.
| DEPRECATED("Use find(), rfind(), IndexString() and/or StringContains()") bool contains(const std casacore::String::DEPRECATED | ( | "Use substr(pos) | = = str if possible, |
| consider ends_with()/starts_with() for " "positive/negative pos or use EqualStringsAndNotEmpty() if direct replacement is necessary" | ) |
Matches entire string from pos, or till pos if negative pos.
** Casacore addition Returns false if either is empty and pos >= 0. The original implementation has multiple bugs and awkward behaviour. BUG: Returns false for two empty strings (except if pos < 0). BUG: Returns false when pattern is empty, whereas normally an empty pattern matches everything. BUG: When pos < 0, it does not behave as advertised; e.g. "xyxy" does not match with "x" when
References DEPRECATED().
| void casacore::String::downcase | ( | ) |
internal transformation to lowercase of String
References DEPRECATED(), and downcase().
Referenced by downcase().
|
inline |
References const, DEPRECATED(), find(), and pos.
Referenced by contains(), and find().
|
inline |
Definition at line 418 of file String.h.
References at(), and firstchar().
Referenced by firstchar().
| int casacore::String::freq | ( | char | c | ) | const |
| int casacore::String::freq | ( | const char * | s | ) | const |
References const, DEPRECATED(), and freq().
| int casacore::String::freq | ( | const std::string & | str | ) | const |
References const, DEPRECATED(), and freq().
References DEPRECATED(), from(), and startpos.
References const, DEPRECATED(), from(), and startpos.
References const, DEPRECATED(), from(), and startpos.
References const, DEPRECATED(), from(), and startpos.
|
inline |
|
inline |
Definition at line 482 of file String.h.
References fromString(), fromString(), and casacore::NewDelAllocator< T >::value.
Referenced by fromString().
|
inline |
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 477 of file String.h.
References fromString(), casacore::NewDelAllocator< T >::value, and casacore::StringToValue().
Referenced by fromString(), and fromString().
References const, DEPRECATED(), and gsub().
References const, DEPRECATED(), and gsub().
Definition at line 798 of file String.h.
References const, gsub(), and casacore::RegexReplaceAll().
|
inline |
Definition at line 420 of file String.h.
References at(), lastchar(), and casacore::length().
Referenced by 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".
References DEPRECATED(), and ltrim().
Referenced by ltrim().
|
inline |
| void casacore::String::prepend | ( | char | c | ) |
References prepend().
| void casacore::String::prepend | ( | const char * | str | ) |
References const, DEPRECATED(), and prepend().
| 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".
References DEPRECATED(), and rtrim().
Referenced by rtrim().
|
inline |
Does the string start with the specified string?
Definition at line 544 of file String.h.
References const, and startsWith().
Referenced by startsWith().
References DEPRECATED(), startpos, and through().
References const, DEPRECATED(), startpos, and through().
References const, DEPRECATED(), startpos, and through().
References const, DEPRECATED(), startpos, and through().
|
inline |
|
private |
Helper function for fromString.
Definition at line 506 of file String.h.
References const, String(), casacore::StringToValue(), and toDouble().
Referenced by toDouble().
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).
Definition at line 494 of file String.h.
References const, String(), casacore::StringToValue(), and toInt().
Referenced by toInt().
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 518 of file String.h.
References const, casacore::NewDelAllocator< T >::value, String(), toString(), and casacore::ValueToString().
Referenced by toString().
| void casacore::String::trim | ( | ) |
Remove beginning and ending whitespace.
References DEPRECATED(), and trim().
| void casacore::String::trim | ( | char | c[], |
| unsigned int | n ) |
Remove specified chars from beginning and end of string.
References DEPRECATED(), and trim().
| void casacore::String::upcase | ( | ) |
internal transformation to uppercase of String
References DEPRECATED(), and upcase().
Referenced by upcase().
| DEPRECATED("Use find(str) != npos or StringContains()") bool contains(const std int pos casacore::String::const |
Definition at line 568 of file String.h.
Referenced by after(), after(), after(), at(), at(), at(), at(), at(), at(), at(), before(), before(), before(), chars(), del(), del(), del(), DEPRECATED(), find(), freq(), freq(), freq(), from(), from(), from(), gsub(), gsub(), gsub(), gsub(), operator=(), prepend(), startsWith(), through(), through(), through(), toDouble(), toFloat(), toInt(), and toString().
| DEPRECATED("Use find(), rfind(), IndexString() and/or StringContains()") bool contains(const std int casacore::String::pos |
| int casacore::String::startpos |