13#ifndef NROS_RCLCPP_FIXED_STRING_HPP
14#define NROS_RCLCPP_FIXED_STRING_HPP
23#include "rclcpp/detail/std_detect.hpp"
52 for (; i < N - 1 && s[i] !=
'\0'; ++i) {
65 while (len < N &&
data[len] !=
'\0')
71 static constexpr size_t capacity() {
return N - 1; }
82 if (s ==
nullptr)
return data[0] ==
'\0';
83 return strncmp(
data, s, N) == 0;
86 bool operator!=(
const char* s)
const {
return !(*
this == s); }
88#ifdef NROS_CPP_HAS_STD_STRING
113 operator std::string()
const {
return std::string(
data,
length()); }
117 std::string to_string()
const {
return std::string(
data,
length()); }
119 bool operator==(
const std::string& s)
const {
return *
this == s.c_str(); }
120 bool operator!=(
const std::string& s)
const {
return !(*
this == s.c_str()); }
Definition fixed_string.hpp:39
char data[N]
Definition fixed_string.hpp:40
const char * c_str() const
Get a pointer to the null-terminated string.
Definition fixed_string.hpp:60
static constexpr size_t capacity()
Maximum number of characters (excluding null terminator).
Definition fixed_string.hpp:71
FixedString()
Default constructor — empty string.
Definition fixed_string.hpp:43
bool operator==(const char *s) const
Compare with a C string.
Definition fixed_string.hpp:81
bool empty() const
True when the string holds no characters. phase-417 W1.c; ungated.
Definition fixed_string.hpp:78
bool operator!=(const char *s) const
Definition fixed_string.hpp:86
FixedString & operator=(const char *s)
Assign from a C string. Truncates if longer than capacity.
Definition fixed_string.hpp:46
size_t size() const
Definition fixed_string.hpp:75
size_t length() const
Get the length of the string (up to N-1).
Definition fixed_string.hpp:63