Repository navigation
TString
#include <certpp/string.hpp> --- certpp
Template: template <typename T = char>
A template class representing a string of characters of type T. By default, T is char, but it can be specialized for other character types. @tparam T The character type of the string. Defaults to char.
Default constructor initializes an empty TString.
Copy constructor.
-
other--- The TString instance to copy from.
Move constructor.
-
other--- The TString instance to move from.
Constructs a TString from a null-terminated C-style string.
-
cStr--- The null-terminated string to copy from.
Constructs a TString from a character array with a specified limit. The array is not required to be null-terminated; up to limit characters are copied.
-
data--- Pointer to the character array to copy from. -
limit--- The maximum number of characters to copy.
Template copy constructor for converting between different character types.
-
cStr--- The TString instance of a different character type to copy from.
Destructor. Clears the TString and releases any allocated memory.
Returns the capacity of the TString.
Returns the size of the TString.
Checks if the TString is empty.
Returns a pointer to the underlying character array. This can be null when empty.
Returns a mutable pointer to the underlying character array. This can be null when empty.
Returns a reference to the underlying character array as a span. This can be empty when the TString is empty.
Returns a const reference to the underlying character array as a span. This can be empty when the TString is empty.
Conversion operator to bool. Returns true if the TString is not empty, false otherwise.
Logical NOT operator. Returns true if the TString is empty, false otherwise.
Subscript operator for accessing characters by index.
-
index--- The index of the character to access.
Returns: The character at the specified index.
Copy assignment operator.
-
other--- The TString instance to copy from.
Move assignment operator.
-
other--- The TString instance to move from.
Assignment operator for C-style strings.
-
cStr--- The C-style string to assign from.
Reserves capacity for the TString. Returns true if the reservation was successful, false otherwise.
-
capacity--- The desired capacity to reserve.
Trims the excess capacity of the TString. Returns true if the TString's capacity is minimal after the call (whether or not there was anything to trim), false only on actual allocation failure.
Resizes the TString to the specified size. Returns true if the resizing was successful, false otherwise.
-
size--- The new size to resize the TString to.
Clears the TString, setting its size to zero. Returns true if the clearing was successful, false otherwise.
Appends the specified string to the TString. Returns the current instance.
-
str--- The string to append. -
limit--- The maximum number of characters to append from the string.
Returns: The current instance after appending.
Appends the specified TString to the current TString. Returns the current instance.
-
other--- The TString to append.
Returns: The current instance after appending.
Appends the specified TString of a different character type to the current TString. Returns the current instance. @tparam U The character type of the TString to append.
-
other--- The TString to append.
Returns: The current instance after appending.
Appends the specified character to the TString. Returns the current instance.
-
ch--- The character to append.
Erases a portion of the TString starting from the specified position. Returns the current instance.
-
start--- The starting position to begin erasing. -
count--- The number of characters to erase. If not specified, erases until the end.
Returns: The current instance after erasing.
Finds the first occurrence of the specified character starting from the given position. Returns the offset of the character if found, or -1 if not found.
-
ch--- The character to find. -
skipBefore--- The count to skip from the beginning when searching for the character.
Returns: The offset of the character if found, or -1 if not found.
Finds the first occurrence of the specified substring starting from the given position. Returns the offset of the substring if found, or -1 if not found.
-
str--- The substring to find. -
skipBefore--- The count to skip from the beginning when searching for the substring.
Returns: The offset of the substring if found, or -1 if not found.
Finds the last occurrence of the specified character starting from the given position from the end. Returns the offset of the character if found, or -1 if not found.
-
ch--- The character to find. -
skipFromEnd--- The count to skip from the end when searching for the character.
Returns: The offset of the character if found, or -1 if not found.
Finds the last occurrence of the specified substring starting from the given position from the end. Returns the offset of the substring if found, or -1 if not found.
-
str--- The substring to find. -
skipBefore--- The count to skip from the beginning when searching for the substring.
Returns: The offset of the substring if found, or -1 if not found.
Returns a substring of the current TString starting from the specified position with the given length. If the start position is out of bounds, an empty TString is returned. If the requested length exceeds the available size, it is adjusted accordingly.
-
start--- The starting position of the substring. -
length--- The length of the substring.
Returns: A TString representing the substring.
Returns a substring of the current TString starting from the specified position to the end. If the start position is out of bounds, an empty TString is returned.
-
start--- The starting position of the substring.
Returns: A TString representing the substring from the start position to the end.
Returns a trimmed version of the current TString, removing leading and trailing whitespace characters. If the current TString is empty, an empty TString is returned.
Returns: A TString representing the trimmed version of the current TString.
Trims the current TString in place, removing leading and trailing whitespace characters. If the current TString is empty, the current instance remains unchanged.
Returns: The current instance after trimming.
Returns a lowercase version of the current TString. If the current TString is empty, an empty TString is returned.
Returns: A TString representing the lowercase version of the current TString.
Returns an uppercase version of the current TString. If the current TString is empty, an empty TString is returned.
Returns: A TString representing the uppercase version of the current TString.
Reverses the current TString in place. If the current TString is empty, the current instance is returned.
Returns: The current instance after reversing.
Compares the current TString with another TString.
-
other--- The TString to compare with.
Returns: A negative value if the current TString is less than other, a positive value if greater, 0 if equal (magnitude beyond the sign isn't meaningful).
Compares the current TString with another TString, ignoring ASCII case (i.e. 'A'-'Z' are folded to 'a'-'z' before comparing; non-ASCII/non-letter characters compare as-is).
-
other--- The TString to compare with.
Returns: A negative value if the current TString is less than other, a positive value if greater, 0 if equal (the same "sign only" contract as compare()).
Compares the current TString with a raw character array, optionally limited to at most limit characters (a null terminator within that limit still ends the comparand, same as countOf()).
-
data--- The raw character array to compare with; may be null. -
limit--- The maximum number of characters of data to consider. Defaults to unlimited, i.e. data is treated as a full null-terminated string.
Returns: A negative value if the current TString is less than data, a positive value if greater, 0 if equal (the same "sign only" contract as compare(const SelfType&)).
Compares the current TString with a raw character array, ignoring ASCII case; see compareIgnoreCase(const SelfType&) and compare(const T*, limit) for the exact rules.
-
data--- The raw character array to compare with; may be null. -
limit--- The maximum number of characters of data to consider. Defaults to unlimited, i.e. data is treated as a full null-terminated string.
Returns: A negative value if the current TString is less than data, a positive value if greater, 0 if equal (the same "sign only" contract as compare()).
Checks if the current TString is equal to another TString.
-
other--- The other TString to compare with.
Returns: true if both TStrings are equal, false otherwise.
Checks if the current TString is not equal to another TString.
-
other--- The other TString to compare with.
Returns: true if both TStrings are not equal, false otherwise.
Appends another TString to the current TString.
-
other--- The TString to append.
Returns: A reference to the current TString after appending.
Appends a C-style string to the current TString.
-
data--- The C-style string to append.
Returns: A reference to the current TString after appending.
Converts the current TString to a TString of a different character type. @tparam U The destination character type.
Returns: A TString of the destination character type.
CString is the alias a caller names (CWideString for wchar_t). size() excludes the terminator, find() returns an offset_t that is negative when there is no match, and the growing calls report allocation failure with a bool.
// given: const CString& subject
CString line("CN=");
line.append(subject);
const offset_t eq = line.find('=');
if (eq < 0) {
return;
}
CString value = line.subString(static_cast<size_t>(eq) + 1);
if (value.empty()) {
return;
}
if (value.compareIgnoreCase(value.toUpper()) != 0) {
return;
}
// convertTo() transcodes through TStringConverter rather than truncating each unit.
CWideString wide = value.convertTo<wchar_t>();
if (wide.empty()) {
return;
}Reference generated from certpp/string.hpp at commit 0834b29 (v1.0.1). The header is authoritative --- if this page disagrees with it, the header is right and this page needs regenerating.