Cbeam
Loading...
Searching...
No Matches
string.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2025 acrion innovations GmbH
3Authors: Stefan Zipproth, s.zipproth@acrion.ch
4
5This file is part of Cbeam, see https://github.com/acrion/cbeam and https://cbeam.org
6
7Cbeam is offered under a commercial and under the AGPL license.
8For commercial licensing, contact us at https://acrion.ch/sales. For AGPL licensing, see below.
9
10AGPL licensing:
11
12Cbeam is free software: you can redistribute it and/or modify
13it under the terms of the GNU Affero General Public License as published by
14the Free Software Foundation, either version 3 of the License, or
15(at your option) any later version.
16
17Cbeam is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU Affero General Public License for more details.
21
22You should have received a copy of the GNU Affero General Public License
23along with Cbeam. If not, see <https://www.gnu.org/licenses/>.
24*/
25
26#pragma once
27
29#include <cbeam/json/traits.hpp> // for cbeam::serialization::serialized_object, cbeam::serialization::traits
30
31#include <cstddef> // for std::size_t
32
33#include <iosfwd> // for std::stringstream
34#include <string> // for std::string
35
36namespace cbeam::container
37{
38 class buffer;
39}
40
41namespace cbeam::json
42{
49 template <>
50 struct traits<std::string>
51 {
52 static inline void serialize(const std::string& str, container::buffer& stream)
53 {
54 stream.append("\"", 1);
55 const std::string escaped_string = convert::escape_string(str, escape_character, characters_to_escape);
56 stream.append(escaped_string.c_str(), escaped_string.length());
57 stream.append("\"", 1);
58 }
59 };
60}
Manages memory a byte buffer, offering dynamic appending. This class is designed for scenarios where ...
Definition buffer.hpp:50
virtual void append(const void *buffer_to_append, const std::size_t length_of_buffer)
append the given buffer to the end of the current buffer. If there is no current buffer yet,...
Definition buffer.hpp:96
Offers advanced container types with unique approaches to stability and interprocess sharing....
Definition buffer.hpp:44
std::string escape_string(const std::string &input, const char escape_character, const std::string &characters_to_escape)
Definition string.hpp:97
Provides JSON-style and nested-map serialization features. It offers methods to convert a wide range ...
Definition map.hpp:37
static void serialize(const std::string &str, container::buffer &stream)
Definition string.hpp:52
Defines the traits required for serializing and deserializing objects of type T.
Definition traits.hpp:56