OFString Class Reference

a simple string class that implements a subset of std::string. More...

List of all members.

Public Member Functions

 OFString ()
 Default constructor.
 OFString (const OFString &str, size_t pos=0, size_t n=OFString_npos)
 Constructs a string from the given input string str.
 OFString (const char *s, size_t n)
 This constructor copies n characters starting at s, and constructs a string object initialized with the corresponding characters.
 OFString (const char *s)
 Constructs a string object from the array pointed to by the input pointer s.
 OFString (size_t rep, char c)
 Constructs a string object with the character c repeated rep times.
 ~OFString ()
 destructor
OFStringoperator= (const OFString &rhs)
 assigns the input string to the current string.
OFStringoperator= (const char *s)
 constructs a temporary string from the input s and assigns it to the current string.
OFStringoperator= (char s)
 constructs a temporary string from the input s and assigns it to the current string.
OFStringoperator+= (const OFString &rhs)
 Appends the input string to the current string.
OFStringoperator+= (const char *s)
 constructs a temporary string from the input s and appends it to the current string.
OFStringoperator+= (char s)
 constructs a temporary string from the input s and appends it to the current string.
OFStringappend (const OFString &str, size_t pos=0, size_t n=OFString_npos)
 Appends characters from the input string str to the current string object.
OFStringappend (const char *s, size_t n)
 constructs a temporary string from the input and appends it to the current string.
OFStringappend (const char *s)
 constructs a temporary string from the input and appends it to the current string.
OFStringappend (size_t rep, char c)
 constructs a temporary string from the input and appends it to the current string.
OFStringassign (const OFString &str, size_t pos=0, size_t n=OFString_npos)
 Assigns characters from the input string str to the current string object.
OFStringassign (const char *s, size_t n)
 constructs a temporary string from the input and assigns it to the current string.
OFStringassign (const char *s)
 constructs a temporary string from the input and assigns it to the current string.
OFStringassign (size_t rep, char c)
 constructs a temporary string from the input and assigns it to the current string.
OFStringinsert (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 string.
OFStringinsert (size_t pos, const char *s, size_t n)
 constructs a temporary string from the input and inserts it into the current string.
OFStringinsert (size_t pos, const char *s)
 constructs a temporary string from the input and inserts it into the current string.
OFStringinsert (size_t pos, size_t rep, char c)
 constructs a temporary string from the input and inserts it into the current string.
OFStringerase (size_t pos=0, size_t n=OFString_npos)
 Removes up to n characters from the string starting from position pos.
OFStringreplace (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 string str.
OFStringreplace (size_t pos, size_t n, const char *s, size_t n2)
 constructs a temporary string from the input and replaces the range [pos, n] in the current string with the constructed string.
OFStringreplace (size_t pos, size_t n, const char *s)
 constructs a temporary string from the input and replaces the range [pos, n] in the current string with the constructed string.
OFStringreplace (size_t pos, size_t n, size_t rep, char s)
 constructs a temporary string from the input and replaces the range [pos, n] in the current string with the constructed string.
const char & at (size_t pos) const
 returns a constant reference to the character at position pos of the current string.
char & at (size_t pos)
 returns a non-const reference to the character at position pos of the current string.
char operator[] (size_t pos) const
 returns the element at position pos of the current string.
char & operator[] (size_t pos)
 returns the element at position pos of the current string.
const char * c_str () const
 returns a pointer to the initial element of an array of length size()+1 whose first size() elements equal the corresponding elements of the current string and whose last element is a null character.
const char * data () const
 if size() is nonzero, this function returns a pointer to the initial element of an array whose first size() elements equal the corresponding elements of the string controlled by *this.
size_t size () const
 returns a count of the number of char-like objects currently in the string.
size_t length () const
 returns a count of the number of char-like objects currently in the string.
OFBool empty () const
 return true if the string is empty, false otherwise.
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 max_size () const
 returns the maximum size of a string which could possibly by allocated.
void clear ()
 empty the string of all contents
void reserve (size_t res_arg)
 directive that informs a string of a planned change in size, so that it can manage the storage allocation accordingly.
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.
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 current string.
void swap (OFString &s)
 swaps the contents of the two strings.
int compare (const OFString &str) const
 determines the effective length rlen of the strings to compare as the smallest of size() and str.size().
int compare (size_t pos1, size_t n1, const OFString &str) const
 constructs a temporary string from the input and compares it with the current string
int compare (size_t pos1, size_t n1, const OFString &str, size_t pos2, size_t n2) const
 constructs a temporary string from this object and another temporary from the input and compares the two temporaries
int compare (const char *s) const
 constructs a temporary string from the input and compares it with the current string
int compare (size_t pos1, size_t n1, const char *s, size_t n2=OFString_npos) const
 constructs a temporary string from this object and another temporary from the input and compares the two temporaries
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.
size_t find (const char *pattern, size_t pos, size_t n) const
 creates a pattern string from the input and determines the earliest occurrence of the pattern in the current string object, starting from position pos in the current string.
size_t find (const char *pattern, size_t pos=0) const
 creates a pattern string from the input and determines the earliest occurrence of the pattern in the current string object, starting from position pos in the current string.
size_t find (char pattern, size_t pos=0) const
 creates a pattern string from the input and determines the earliest occurrence of the pattern in the current string object, starting from position pos in 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 back).
size_t rfind (const char *pattern, size_t pos, size_t n) const
 scans the current string backwards, and finds the first occurrence of pattern in the string (from the back).
size_t rfind (const char *pattern, size_t pos=OFString_npos) const
 scans the current string backwards, and finds the first occurrence of pattern in the string (from the back).
size_t rfind (char pattern, size_t pos=OFString_npos) const
 scans the current string backwards, and finds the first occurrence of pattern in the string (from the back).
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.
size_t find_first_of (const char *s, size_t pos, size_t n) 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.
size_t find_first_of (const char *s, 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.
size_t find_first_of (char s, 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 the given character.
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 character from the set of characters.
size_t find_last_of (const char *s, size_t pos, size_t n) const
 determines the highest location, loc, up to pos, such that the character at loc matches at least one character from the set of characters.
size_t find_last_of (const char *s, size_t pos=OFString_npos) const
 determines the highest location, loc, up to pos, such that the character at loc matches at least one character from the set of characters.
size_t find_last_of (char s, size_t pos=OFString_npos) const
 determines the highest location, loc, up to pos, such that the character at loc matches the given character.
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 character at loc does not match any character from the set of characters.
size_t find_first_not_of (const char *s, size_t pos, size_t n) const
 determines the first location loc, between pos and the end of the current string, such that the character at loc does not match any character from the set of characters.
size_t find_first_not_of (const char *s, 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 does not match any character from the set of characters.
size_t find_first_not_of (char c, 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 does not match the given character.
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.
size_t find_last_not_of (const char *s, size_t pos, size_t n) 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.
size_t find_last_not_of (const char *s, 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.
size_t find_last_not_of (char c, 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 the given character.

Private Attributes

char * theCString
 the "C" string pointer
size_t theCapacity
 the capacity of str


Detailed Description

a simple string class that implements a subset of std::string.

It does not implement iterators or traits and is not optimized for speed.

Definition at line 84 of file ofstring.h.


Constructor & Destructor Documentation

OFString::OFString  ) 
 

Default constructor.

Constructs an empty string.

OFString::OFString const OFString str,
size_t  pos = 0,
size_t  n = OFString_npos
 

Constructs a string from the given input string str.

The effective length rlen of the constructed string is the smaller of n and str.size() - pos, and the string is constructed by copying rlen characters starting at position pos of the input string str. The function throws an out-of-range error if pos > str.size().

Parameters:
str string to copy from
pos position to start copying from
n maximum number of characters to copy

OFString::OFString const char *  s,
size_t  n
 

This constructor copies n characters starting at s, and constructs a string object initialized with the corresponding characters.

NOTE: If n > length(s), then junk characters are appended to the end of the string. i.e. n characters are copied regardless of the exact length of the array pointed to by the input pointer s.

Parameters:
s pointer to an array of char of length n. Must not be NULL.
n number of characters in array

OFString::OFString const char *  s  ) 
 

Constructs a string object from the array pointed to by the input pointer s.

It is assumed that s is not a null pointer.

Parameters:
s pointer to a zero-terminated C string. Must not be NULL.

OFString::OFString size_t  rep,
char  c
 

Constructs a string object with the character c repeated rep times.

Reports a length error if rep equals npos.

Parameters:
rep number of repetitions
c character to construct from


Member Function Documentation

OFString& OFString::append size_t  rep,
char  c
 

constructs a temporary string from the input and appends it to the current string.

Parameters:
rep number of repetitions
c character to construct from
Returns:
reference to this object

OFString& OFString::append const char *  s  ) 
 

constructs a temporary string from the input and appends it to the current string.

Parameters:
s pointer to a zero-terminated C string. Must not be NULL.
Returns:
reference to this object

OFString& OFString::append const char *  s,
size_t  n
 

constructs a temporary string from the input and appends it to the current string.

Parameters:
s pointer to an array of char of length n. Must not be NULL.
n number of characters in array
Returns:
reference to this object

OFString& 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.

At most n characters, starting at position pos of str, are appended. The function reports an out-of-range error if pos > str.size().

Parameters:
str string to append from
pos position to start copying from
n maximum number of characters to copy
Returns:
reference to this object

OFString& OFString::assign size_t  rep,
char  c
 

constructs a temporary string from the input and assigns it to the current string.

Parameters:
rep number of repetitions
c character to construct from
Returns:
reference to this object

OFString& OFString::assign const char *  s  ) 
 

constructs a temporary string from the input and assigns it to the current string.

Parameters:
s pointer to a zero-terminated C string. Must not be NULL.
Returns:
reference to this object

OFString& OFString::assign const char *  s,
size_t  n
 

constructs a temporary string from the input and assigns it to the current string.

Parameters:
s pointer to an array of char of length n. Must not be NULL.
n number of characters in array
Returns:
reference to this object

OFString& OFString::assign const OFString str,
size_t  pos = 0,
size_t  n = OFString_npos
 

Assigns characters from the input string str to the current string object.

At most n characters, starting at position pos of str, are appended. The function reports an out-of-range error if pos > str.size().

Parameters:
str string to append from
pos position to start copying from
n maximum number of characters to copy
Returns:
reference to this object

char& OFString::at size_t  pos  )  [inline]
 

returns a non-const reference to the character at position pos of the current string.

if pos >= size(), throws out_of_range exception.

Parameters:
pos position in string
Returns:
non-const reference to character in string at pos

Definition at line 346 of file ofstring.h.

const char& OFString::at size_t  pos  )  const [inline]
 

returns a constant reference to the character at position pos of the current string.

if pos >= size(), throws out_of_range exception.

Parameters:
pos position in string
Returns:
const reference to character in string at pos

Definition at line 334 of file ofstring.h.

const char* OFString::c_str  )  const [inline]
 

returns a pointer to the initial element of an array of length size()+1 whose first size() elements equal the corresponding elements of the current string and whose last element is a null character.

Returns:
C string for this string

Definition at line 384 of file ofstring.h.

Referenced by DcmUIDHandler::c_str(), DVInterface::getAnnotationText(), DVPSCurve::getCurveAxisUnitsX(), DVPSCurve::getCurveAxisUnitsY(), DVPSCurve::getCurveDescription(), DVPSCurve::getCurveLabel(), DiOverlayPlane::getDescription(), DiBaseLUT::getExplanation(), DVInstanceCache::getFilename(), OFConfigFileNode::getKeyword(), DiOverlayPlane::getLabel(), DcmPresentationContextItem::getTransferSyntaxKey(), DVPSFilmSession::getUID(), OFConfigFileNode::getValue(), and DiMonoImage::getVoiTransformationExplanation().

size_t OFString::capacity  )  const [inline]
 

returns the size of the allocated storage in the string.

Returns:
size of the allocated storage in the string

Definition at line 434 of file ofstring.h.

int OFString::compare size_t  pos1,
size_t  n1,
const char *  s,
size_t  n2 = OFString_npos
const
 

constructs a temporary string from this object and another temporary from the input and compares the two temporaries

Parameters:
pos1 position to start copying from this object
n1 maximum number of characters to copy from this object
s pointer to an array of char of length n. Must not be NULL.
n2 number of characters in array s
Returns:
comparison result

int OFString::compare const char *  s  )  const
 

constructs a temporary string from the input and compares it with the current string

Parameters:
s pointer to a zero-terminated C string. Must not be NULL.
Returns:
comparison result

int OFString::compare size_t  pos1,
size_t  n1,
const OFString str,
size_t  pos2,
size_t  n2
const
 

constructs a temporary string from this object and another temporary from the input and compares the two temporaries

Parameters:
pos1 position to start copying from this object
n1 maximum number of characters to copy from this object
str string to create second temporary from
pos2 position to start copying from in str
n2 maximum number of characters to copy from str
Returns:
comparison result

int OFString::compare size_t  pos1,
size_t  n1,
const OFString str
const
 

constructs a temporary string from the input and compares it with the current string

Parameters:
pos1 position to start copying from in str
n1 maximum number of characters to copy from str
str string to copy from
Returns:
comparison result

int OFString::compare const OFString str  )  const
 

determines the effective length rlen of the strings to compare as the smallest of size() and str.size().

The function then compares the two strings by calling strcmp(data(), str.data(), rlen). Returns: the nonzero result if the result of the comparison is nonzero. Otherwise, returns a value < 0 if size() < str.size(), a value of 0 if size() == str.size(), or a value > 0 if size() > str.size().

Parameters:
str string to compare to
Returns:
comparison result as described above

size_t OFString::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.

The range copied begins at position pos of the current string and extends for n characters or up to the end of the current string, whichever comes first. Does not append a null object to the end of the string designated by s.

Parameters:
s character array to copy to
n size of character array
pos position in string to start copying from
Returns:
number of characters copied

const char* OFString::data  )  const
 

if size() is nonzero, this function returns a pointer to the initial element of an array whose first size() elements equal the corresponding elements of the string controlled by *this.

If size() is zero, the member returns a non-null pointer that is copyable and can have zero added to it.

Returns:
pointer to char array for this string

OFBool OFString::empty void   )  const [inline]
 

return true if the string is empty, false otherwise.

Returns:
true if the string is empty, false otherwise.

Definition at line 419 of file ofstring.h.

Referenced by DiOverlayPlane::getDescription(), DiBaseLUT::getExplanation(), and DiOverlayPlane::getLabel().

OFString& OFString::erase size_t  pos = 0,
size_t  n = OFString_npos
 

Removes up to n characters from the string starting from position pos.

Parameters:
pos position to start from
n number of characters to remove
Returns:
reference to this object

size_t OFString::find char  pattern,
size_t  pos = 0
const
 

creates a pattern string from the input and determines the earliest occurrence of the pattern in the current string object, starting from position pos in the current string.

If find can determine such an occurrence, it returns the starting index of pattern in the current string. Otherwise, it returns string::npos.

Parameters:
pattern character
pos position to start searching from
Returns:
index of pattern in string

size_t OFString::find const char *  pattern,
size_t  pos = 0
const
 

creates a pattern string from the input and determines the earliest occurrence of the pattern in the current string object, starting from position pos in the current string.

If find can determine such an occurrence, it returns the starting index of pattern in the current string. Otherwise, it returns string::npos.

Parameters:
pattern pointer to a zero-terminated C string. Must not be NULL.
pos position to start searching from
Returns:
index of pattern in string

size_t OFString::find const char *  pattern,
size_t  pos,
size_t  n
const
 

creates a pattern string from the input and determines the earliest occurrence of the pattern in the current string object, starting from position pos in the current string.

If find can determine such an occurrence, it returns the starting index of pattern in the current string. Otherwise, it returns string::npos.

Parameters:
pattern pointer to an array of char of length n. Must not be NULL.
pos position to start searching from
n number of characters in array
Returns:
index of pattern in string

size_t OFString::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.

If find can determine such an occurrence, it returns the starting index of pattern in the current string. Otherwise, it returns string::npos.

Parameters:
pattern pattern to find
pos position to start searching from
Returns:
index of pattern as described above

size_t OFString::find_first_not_of char  c,
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 does not match the given character.

If such a location is found, it is returned. Otherwise, the function returns string::npos.

Parameters:
c character to find
pos position to start searching from
Returns:
index of character

size_t OFString::find_first_not_of const char *  s,
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 does not match any character from the set of characters.

If such a location is found, it is returned. Otherwise, the function returns string::npos.

Parameters:
s set of characters to find, pointer to a zero-terminated C string. Must not be NULL.
pos position to start searching from
Returns:
index of pattern in string

size_t OFString::find_first_not_of const char *  s,
size_t  pos,
size_t  n
const
 

determines the first location loc, between pos and the end of the current string, such that the character at loc does not match any character from the set of characters.

If such a location is found, it is returned. Otherwise, the function returns string::npos.

Parameters:
s set of characters to find, pointer to an array of char of length n. Must not be NULL.
pos position to start searching from
n number of characters in array
Returns:
index of pattern in string

size_t OFString::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 character at loc does not match any character from the set of characters.

If such a location is found, it is returned. Otherwise, the function returns string::npos.

Parameters:
str set of characters to find
pos position to start searching from
Returns:
index of character as described above

size_t OFString::find_first_of char  s,
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 the given character.

If such a location can be determined, it is returned. Otherwise, the function returns string::npos.

Parameters:
s character to find
pos position to start searching from
Returns:
index of character

size_t OFString::find_first_of const char *  s,
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.

If such a location can be determined, it is returned. Otherwise, the function returns string::npos.

Parameters:
s set of characters to find, pointer to a zero-terminated C string. Must not be NULL.
pos position to start searching from
Returns:
index of pattern in string

size_t OFString::find_first_of const char *  s,
size_t  pos,
size_t  n
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.

If such a location can be determined, it is returned. Otherwise, the function returns string::npos.

Parameters:
s set of characters to find, pointer to an array of char of length n. Must not be NULL.
pos position to start searching from
n number of characters in array
Returns:
index of pattern in string

size_t OFString::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.

If such a location can be determined, it is returned. Otherwise, the function returns string::npos.

Parameters:
str set of characters to find
pos position to start searching from
Returns:
index of character as described above

size_t OFString::find_last_not_of char  c,
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 the given character.

If such a location is found, it is returned. Otherwise, the function returns string::npos.

Parameters:
c character to find
pos position to start searching from
Returns:
index of character

size_t OFString::find_last_not_of const char *  s,
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.

If such a location is found, it is returned. Otherwise, the function returns string::npos.

Parameters:
s set of characters to find, pointer to a zero-terminated C string. Must not be NULL.
pos position to start searching from
Returns:
index of pattern in string

size_t OFString::find_last_not_of const char *  s,
size_t  pos,
size_t  n
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.

If such a location is found, it is returned. Otherwise, the function returns string::npos.

Parameters:
s set of characters to find, pointer to an array of char of length n. Must not be NULL.
pos position to start searching from
n number of characters in array
Returns:
index of pattern in string

size_t OFString::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.

If such a location is found, it is returned. Otherwise, the function returns string::npos.

Parameters:
str set of characters to find
pos position to start searching from
Returns:
index of character as described above

size_t OFString::find_last_of char  s,
size_t  pos = OFString_npos
const
 

determines the highest location, loc, up to pos, such that the character at loc matches the given character.

If such a location can be determined, it is returned. Otherwise, the function returns string::npos.

Parameters:
s character to find
pos position to start searching from
Returns:
index of character

size_t OFString::find_last_of const char *  s,
size_t  pos = OFString_npos
const
 

determines the highest location, loc, up to pos, such that the character at loc matches at least one character from the set of characters.

If such a location can be determined, it is returned. Otherwise, the function returns string::npos.

Parameters:
s set of characters to find, pointer to a zero-terminated C string. Must not be NULL.
pos position to start searching from
Returns:
index of pattern in string

size_t OFString::find_last_of const char *  s,
size_t  pos,
size_t  n
const
 

determines the highest location, loc, up to pos, such that the character at loc matches at least one character from the set of characters.

If such a location can be determined, it is returned. Otherwise, the function returns string::npos.

Parameters:
s set of characters to find, pointer to an array of char of length n. Must not be NULL.
pos position to start searching from
n number of characters in array
Returns:
index of pattern in string

size_t OFString::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 character from the set of characters.

If such a location can be determined, it is returned. Otherwise, the function returns string::npos.

Parameters:
str set of characters to find
pos position to start searching from
Returns:
index of character as described above

OFString& OFString::insert size_t  pos,
size_t  rep,
char  c
 

constructs a temporary string from the input and inserts it into the current string.

Parameters:
pos position to insert at
rep number of repetitions
c character to construct from
Returns:
reference to this object