Skip to content

TStringFunctions

Jay edited this page Oct 3, 2026 · 2 revisions

TStringFunctions<...>

#include <certpp/string.hpp> --- certpp

Template: template <typename T>

Methods

static inline void fillZero(T* data, size_t size)

Fills the given data array with default-constructed values of type T.

  • data --- The data array to fill with default-constructed values.
  • size --- The number of elements in the data array to fill.

static inline void copy(T* dest, const T* src, size_t size)

Copies the contents from the source array to the destination array.

  • dest --- The destination array where the contents will be copied.
  • src --- The source array from which the contents will be copied.
  • size --- The number of elements to copy.

static inline void move(T* dest, T* src, size_t size)

Moves the contents from the source array to the destination array.

  • dest --- The destination array where the contents will be moved.
  • src --- The source array from which the contents will be moved.
  • size --- The number of elements to move.

static inline int32_t cmp(const T* lhs, const T* rhs, size_t size)

Compares two arrays of type T for equality.

  • lhs --- The left-hand side array.
  • rhs --- The right-hand side array.
  • size --- The number of elements to compare.

Returns: 0 if the arrays are equal, a non-zero value otherwise.

static inline int32_t caseCmp(const T* lhs, const T* rhs, size_t size)

Compares two arrays of type T for equality, ignoring case.

  • lhs --- The left-hand side array.
  • rhs --- The right-hand side array.
  • size --- The number of elements to compare.

Returns: 0 if the arrays are equal (ignoring case), a non-zero value otherwise.

static inline const T* chr(const T* str, size_t size, T ch)

Finds the first occurrence of the specified character in the given string. Returns a pointer to the character if found, or nullptr if not found.

  • str --- The string to search for the character.
  • size --- The size of the string.
  • ch --- The character to find.

Returns: A pointer to the character if found, or nullptr if not found.

static inline const T* rchr(const T* str, size_t size, T ch)

Finds the last occurrence of the specified character in the given string. Returns a pointer to the character if found, or nullptr if not found.

  • str --- The string to search for the character.
  • size --- The size of the string.
  • ch --- The character to find.

Returns: A pointer to the character if found, or nullptr if not found.

static inline offset_t find(const T* str, size_t size, T ch)

Finds the first occurrence of the specified character in the given string. Returns the offset of the character if found, or -1 if not found.

  • str --- The string to search for the character.
  • size --- The size of the string.
  • ch --- The character to find.

Returns: The offset of the character if found, or -1 if not found.

static inline offset_t findLast(const T* str, size_t size, T ch)

Finds the last occurrence of the specified character in the given string. Returns the offset of the character if found, or -1 if not found.

  • str --- The string to search for the character.
  • size --- The size of the string.
  • ch --- The character to find.

Returns: The offset of the character if found, or -1 if not found.

static inline size_t countOf(const T* str, size_t size = size_t(-1))

Counts the number of characters in the given string up to the specified size.

  • str --- The string to count characters in.
  • size --- The maximum number of characters to count.

Returns: The number of characters in the string up to the specified size.

static inline bool isSpace(T ch)

Checks if the given character is a whitespace character.

  • ch --- The character to check.

Returns: True if the character is a whitespace character, false otherwise.

static inline T toLower(T ch)

Converts the given character to lowercase.

  • ch --- The character to convert to lowercase.

Returns: The lowercase version of the character.

static inline T toUpper(T ch)

Converts the given character to uppercase.

  • ch --- The character to convert to uppercase.

Returns: The uppercase version of the character.

Example

The raw-pointer string primitives TString and CName are built on, usable directly when you have a pointer and a length instead of a TString. Everything here takes an explicit size and never looks for a terminator -- countOf() is the one call that does.

// given: const char* header
using Fn = TStringFunctions<char>;

const size_t len = Fn::countOf(header);
if (len == 0) {
    return;   // also what a null pointer reports, rather than crashing
}

const offset_t colon = Fn::find(header, len, ':');
if (colon < 0) {
    return;
}

// caseCmp() compares exactly the count it is given and does not stop at a terminator, so
// the length has to be checked first, not inferred from the result.
const size_t nameLen = static_cast<size_t>(colon);
if (nameLen != 12 || Fn::caseCmp(header, "content-type", nameLen) != 0) {
    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.

Clone this wiki locally