C/C++ API Reference
Loading...
Searching...
No Matches
util.h File Reference

The pw::string::* functions provide safer alternatives to C++ standard library string functions. More...

#include <cctype>
#include <cstddef>
#include <string_view>
#include "pw_assert/assert.h"
#include "pw_polyfill/language_feature_macros.h"
#include "pw_result/result.h"
#include "pw_span/span.h"
#include "pw_status/status.h"
#include "pw_status/status_with_size.h"
#include "pw_string/internal/length.h"
#include "pw_string/string.h"

Go to the source code of this file.

Namespaces

namespace  pw
 The Pigweed namespace.
 

Functions

StatusWithSize pw::string::internal::CopyToSpan (std::string_view source, span< char > dest)
 
constexpr std::string_view pw::string::ClampedCString (span< const char > str)
 Safe alternative to the string_view constructor that avoids the risk of an unbounded implicit or explicit use of strlen.
 
constexpr std::string_view pw::string::ClampedCString (const char *str, size_t max_len)
 
constexpr Result< size_t > pw::string::NullTerminatedLength (span< const char > str)
 pw::string::NullTerminatedLength is a safer alternative to strlen for calculating the null-terminated length of the string within the specified span, excluding the null terminator.
 
constexpr Result< size_t > pw::string::NullTerminatedLength (const char *str, size_t max_len)
 
template<typename Span >
StatusWithSize pw::string::Copy (std::string_view source, Span &&dest)
 pw::string::Copy is a safer alternative to std::strncpy as it always null-terminates whenever the destination buffer has a non-zero size.
 
template<typename Span >
StatusWithSize pw::string::Copy (const char *source, Span &&dest)
 
StatusWithSize pw::string::Copy (const char *source, char *dest, size_t num)
 
Status pw::string::Assign (InlineString<> &string, std::string_view view)
 
Status pw::string::Assign (InlineString<> &string, const char *c_string)
 
Status pw::string::Append (InlineString<> &string, std::string_view view)
 
Status pw::string::Append (InlineString<> &string, const char *c_string)
 
StatusWithSize pw::string::PrintableCopy (std::string_view source, span< char > dest)
 Provides a safe, printable copy of a string.
 

Detailed Description

The pw::string::* functions provide safer alternatives to C++ standard library string functions.