3#ifndef OCPP_COMMON_CISTRING_HPP
4#define OCPP_COMMON_CISTRING_HPP
6#include <nlohmann/json.hpp>
8#include <ocpp/common/string.hpp>
9#include <ocpp/common/utils.hpp>
11using json = nlohmann::json;
20 CiString(
const std::string& data, StringTooLarge to_large = StringTooLarge::Throw) :
String<L>(data, to_large) {
23 CiString(
const char* data, StringTooLarge to_large = StringTooLarge::Throw) :
String<L>(data, to_large) {
39 for (
char character : data) {
41 if ((character < 0x20 || character > 0x7e) && character != 0xa) {
42 throw std::runtime_error(
"CiString can only contain printable ASCII characters");
49 operator std::string()
const {
55template <
size_t L>
bool operator==(
const CiString<L>& lhs,
const char* rhs) {
56 return iequals(lhs.get(), rhs);
60template <
size_t L>
bool operator==(
const CiString<L>& lhs,
const CiString<L>& rhs) {
61 return iequals(lhs.get(), rhs.get());
65template <
size_t L>
bool operator!=(
const CiString<L>& lhs,
const char* rhs) {
66 return !(lhs.get() == rhs);
70template <
size_t L>
bool operator!=(
const CiString<L>& lhs,
const CiString<L>& rhs) {
71 return !(lhs.get() == rhs.get());
75template <
size_t L>
bool operator<(
const CiString<L>& lhs,
const CiString<L>& rhs) {
76 return lhs.get() < rhs.get();
81template <
size_t L> std::ostream& operator<<(std::ostream& os,
const CiString<L>& str) {
86template <
size_t L>
void to_json(json& j,
const CiString<L>& k) {
90template <
size_t L>
void from_json(
const json& j, CiString<L>& k) {
Contains a CaseInsensitive string implementation that only allows printable ASCII characters.
Definition: cistring.hpp:16
bool is_valid(std::string_view data)
CaseInsensitive string implementation only allows printable ASCII characters.
Definition: cistring.hpp:38
CiString(const std::string &data, StringTooLarge to_large=StringTooLarge::Throw)
Creates a string from the given data.
Definition: cistring.hpp:20
CiString()
Creates a string.
Definition: cistring.hpp:30
Contains a String impementation with a maximum length.
Definition: string.hpp:24
String()=default
Creates a string.
std::string get() const
Provides a std::string representation of the string.
Definition: string.hpp:44