32 #include "dcmtk/config/osconfig.h" 34 #include "dcmtk/ofstd/oftypes.h" 35 #include "dcmtk/ofstd/ofcast.h" 39 #define OFSTRING_GUARD(c_string) ((c_string != NULL) ? (c_string) : "") 42 #ifdef HAVE_STD_STRING 49 #define OFString std::string 50 #define OFString_npos std::string::npos 58 #define INCLUDE_CASSERT 59 #define INCLUDE_CSTRING 60 #define INCLUDE_CSTDLIB 62 #define INCLUDE_UNISTD 63 #include "dcmtk/ofstd/ofstdinc.h" 65 #include "dcmtk/ofstd/ofstream.h" 66 #include "dcmtk/ofstd/oftypes.h" 71 #define OFSTRING_OUTOFRANGE(cond) assert (!(cond)) 72 #define OFSTRING_LENGTHERROR(cond) assert (!(cond)) 73 #define OFSTRING_MEMORYALLOCERROR(cond) assert (!(cond)) 80 static const size_t OFString_npos = (OFstatic_cast(
size_t, -1));
254 size_t pos2 = 0,
size_t n = OFString_npos);
305 size_t pos2 = 0,
size_t n2 = OFString_npos);
342 const char&
at(
size_t pos)
const 344 OFSTRING_OUTOFRANGE (pos >= this->
size());
356 OFSTRING_OUTOFRANGE (pos >= this->
size());
367 if (pos == this->
size())
return '\0';
370 OFSTRING_OUTOFRANGE (pos > this->
size());
383 OFSTRING_OUTOFRANGE (pos >= this->
size());
404 const char*
data()
const;
429 return (this->
size() == 0)?(OFTrue):(OFFalse);
437 void resize(
size_t n,
char c =
'\0');
452 return ((OFString_npos - 1)/
sizeof(
char));
482 size_t copy(
char* s,
size_t n,
size_t pos = 0)
const;
527 int compare(
size_t pos1,
size_t n1,
const OFString& str,
size_t pos2,
size_t n2)
const;
534 int compare(
const char* s)
const;
544 int compare(
size_t pos1,
size_t n1,
const char* s,
size_t n2 = OFString_npos)
const;
555 size_t find(
const OFString& pattern,
size_t pos = 0)
const;
567 size_t find(
const char* pattern,
size_t pos,
size_t n)
const;
578 size_t find(
const char* pattern,
size_t pos = 0)
const;
589 size_t find(
char pattern,
size_t pos = 0)
const;
600 size_t rfind(
const OFString& pattern,
size_t pos = OFString_npos)
const;
612 size_t rfind(
const char* pattern,
size_t pos,
size_t n)
const;
623 size_t rfind(
const char* pattern,
size_t pos = OFString_npos)
const;
634 size_t rfind(
char pattern,
size_t pos = OFString_npos)
const;
657 size_t find_first_of(
const char* s,
size_t pos,
size_t n)
const;
700 size_t find_last_of(
const char* s,
size_t pos,
size_t n)
const;
710 size_t find_last_of(
const char* s,
size_t pos = OFString_npos)
const;
720 size_t find_last_of(
char s,
size_t pos = OFString_npos)
const;
851 STD_NAMESPACE ostream& operator<< (STD_NAMESPACE ostream& o,
const OFString& s);
859 STD_NAMESPACE istream& operator>> (STD_NAMESPACE istream& i,
OFString& s);
908 OFBool operator== (
const char* lhs,
const OFString& rhs);
915 OFBool operator== (
char lhs,
const OFString& rhs);
922 OFBool operator== (
const OFString& lhs,
const char* rhs);
929 OFBool operator== (
const OFString& lhs,
char rhs);
943 OFBool operator< (
const char* lhs,
const OFString& rhs);
950 OFBool operator< (
char lhs,
const OFString& rhs);
957 OFBool operator< (
const OFString& lhs,
const char* rhs);
964 OFBool operator< (
const OFString& lhs,
char rhs);
978 OFBool operator<= (
const char* lhs,
const OFString& rhs);
985 OFBool operator<= (
char lhs,
const OFString& rhs);
992 OFBool operator<= (
const OFString& lhs,
const char* rhs);
999 OFBool operator<= (
const OFString& lhs,
char rhs);
1013 OFBool operator!= (
const char* lhs,
const OFString& rhs);
1020 OFBool operator!= (
char lhs,
const OFString& rhs);
1027 OFBool operator!= (
const OFString& lhs,
const char* rhs);
1034 OFBool operator!= (
const OFString& lhs,
char rhs);
1048 OFBool operator> (
const char* lhs,
const OFString& rhs);
1055 OFBool operator> (
char lhs,
const OFString& rhs);
1062 OFBool operator> (
const OFString& lhs,
const char* rhs);
1069 OFBool operator> (
const OFString& lhs,
char rhs);
1083 OFBool operator>= (
const char* lhs,
const OFString& rhs);
1090 OFBool operator>= (
char lhs,
const OFString& rhs);
1097 OFBool operator>= (
const OFString& lhs,
const char* rhs);
1104 OFBool operator>= (
const OFString& lhs,
char rhs);
void clear()
empty the string of all contents
iterator begin() const
returns a constant iterator that points to the beginning of the string
char * theCString
the "C" string pointer
OFBool empty() const
return true if the string is empty, false otherwise.
size_t size() const
returns a count of the number of char-like objects currently in the string.
OFString & operator=(const OFString &rhs)
assigns the input string to the current string.
size_t copy(char *s, size_t n, size_t pos=0) const
replaces the string designated by s with a copy of a range of characters from the current string...
size_t rfind(const OFString &pattern, size_t pos=OFString_npos) const
scans the current string backwards, and finds the first occurrence of pattern in the string (from the...
OFString & replace(size_t pos1, size_t n1, const OFString &str, size_t pos2=0, size_t n2=OFString_npos)
replaces a range of characters in the current string with a range of characters taken from the input ...
char & at(size_t pos)
returns a non-const reference to the character at position pos of the current string.
const char * data() const
if size() is nonzero, this function returns a pointer to the initial element of an array whose first ...
size_t find_first_not_of(const OFString &str, size_t pos=0) const
determines the first location loc, between pos and the end of the current string, such that the chara...
void reserve(size_t res_arg)
directive that informs a string of a planned change in size, so that it can manage the storage alloca...
OFString substr(size_t pos=0, size_t n=OFString_npos) const
returns a copy the substring consisting of at most n characters starting at position pos of the curre...
void resize(size_t n, char c= '\0')
if n <= size(), truncates the string to length n else it pads the extra locations with c...
size_t capacity() const
returns the size of the allocated storage in the string.
size_t find_last_not_of(const OFString &str, size_t pos=OFString_npos) const
scans the current string up to the position pos and determines the highest location, loc, such that the character at loc does not match any character from the set of characters.
const char * iterator
this typedef can be used to iterate over an string.
OFString & operator+=(const OFString &rhs)
Appends the input string to the current string.
const char & at(size_t pos) const
returns a constant reference to the character at position pos of the current string.
size_t size_type
type that is used for lengths and offsets
OFString & insert(size_t pos1, const OFString &str, size_t pos2=0, size_t n=OFString_npos)
Inserts at most n characters, starting at position pos2 of the input string str, into the current str...
size_t theSize
the length of theCString
size_t find_first_of(const OFString &str, size_t pos=0) const
determines the first location, loc, between pos and the end of the current string, such that the character at loc matches at least one character from the set of characters.
OFString & erase(size_t pos=0, size_t n=OFString_npos)
Removes up to n characters from the string starting from position pos.
int compare(const OFString &str) const
determines the effective length rlen of the strings to compare as the smallest of size() and str...
size_t length() const
returns a count of the number of char-like objects currently in the string.
char operator[](size_t pos) const
returns the element at position pos of the current string.
iterator const_iterator
this is just an alias for iterator since iterator is already "const"
size_t find_last_of(const OFString &str, size_t pos=OFString_npos) const
determines the highest location, loc, up to pos, such that the character at loc matches at least one ...
OFString & assign(const OFString &str, size_t pos, size_t n)
Assigns characters from the input string str to the current string object.
size_t find(const OFString &pattern, size_t pos=0) const
determines the earliest occurrence of the input pattern in the current string object, starting from position pos in the current string.
OFString()
Default constructor.
size_t theCapacity
the capacity of str
a simple string class that implements a subset of std::string.
OFString & append(const OFString &str, size_t pos=0, size_t n=OFString_npos)
Appends characters from the input string str to the current string object.
void swap(OFString &s)
swaps the contents of the two strings.
const char * c_str() const
returns a pointer to the initial element of an array of length size()+1 whose first size() elements e...
char value_type
type that is contained in this
size_t max_size() const
returns the maximum size of a string which could possibly by allocated.
iterator end() const
returns a constant iterator that points after the last element of the string