Gamp v0.0.7-67-g7798ac4
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
string_util_unsafe.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021-2026 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef JAU_STRING_UTIL_UNSAFE_HPP_
26#define JAU_STRING_UTIL_UNSAFE_HPP_
27
28#include <cstdarg>
29#include <cstring>
30#include <string>
31
32namespace jau::unsafe {
33 /** \addtogroup StringUtils
34 *
35 * @{
36 */
37
38 /**
39 * Returns a (potentially truncated) string according to `snprintf()` formatting rules
40 * and variable number of arguments following the `format` argument
41 * while utilizing the unsafe `vsnprintf`.
42 *
43 * This variant doesn't validate `format` against given arguments, see jau::format_string_n.
44 *
45 * Resulting string is truncated to `min(maxStrLen, formatLen)`,
46 * with `formatLen` being the given formatted string length of output w/o limitation.
47 *
48 * @param maxStrLen maximum resulting string length
49 * @param format `printf()` compliant format string
50 * @param args optional arguments matching the format string
51 */
52 std::string format_string_n(const std::size_t maxStrLen, const char* format, ...) noexcept;
53 std::string vformat_string_n(const std::size_t maxStrLen, const char* format, va_list args) noexcept;
54
55 /**
56 * Returns a (non-truncated) string according to `snprintf()` formatting rules
57 * and variable number of arguments following the `format` argument
58 * while utilizing the unsafe `vsnprintf`.
59 *
60 * This variant doesn't validate `format` against given arguments, see jau::format_string_h.
61 *
62 * Resulting string size matches formated output w/o limitation.
63 *
64 * @param strLenHint initially used string length w/o EOS
65 * @param format `printf()` compliant format string
66 * @param args optional arguments matching the format string
67 */
68 std::string format_string_h(const std::size_t strLenHint, const char* format, ...) noexcept;
69 std::string vformat_string_h(const std::size_t strLenHint, const char* format, va_list args) noexcept;
70
71 /**
72 * Returns a (non-truncated) string according to `snprintf()` formatting rules
73 * and variable number of arguments following the `format` argument
74 * while utilizing the unsafe `vsnprintf`.
75 *
76 * This variant doesn't validate `format` against given arguments, see jau::format_string.
77 *
78 * Resulting string size matches formated output w/o limitation.
79 *
80 * @param format `printf()` compliant format string
81 * @param args optional arguments matching the format string
82 */
83 std::string format_string(const char* format, ...) noexcept;
84
85 void errPrint(FILE *out, const char *msg, bool addErrno, bool addBacktrace, const char *func, const char *file, const int line,
86 const char* format, ...) noexcept;
87
88 /**@}*/
89
90} // namespace jau::unsafe
91
92#endif // JAU_STRING_UTIL_UNSAFE_HPP_
std::string format_string_h(const std::size_t strLenHint, const char *format,...) noexcept
Returns a (non-truncated) string according to snprintf() formatting rules and variable number of argu...
std::string vformat_string_h(const std::size_t strLenHint, const char *format, va_list args) noexcept
void errPrint(FILE *out, const char *msg, bool addErrno, bool addBacktrace, const char *func, const char *file, const int line, const char *format,...) noexcept
std::string format_string_n(const std::size_t maxStrLen, const char *format,...) noexcept
Returns a (potentially truncated) string according to snprintf() formatting rules and variable number...
std::string vformat_string_n(const std::size_t maxStrLen, const char *format, va_list args) noexcept
std::string format_string(const char *format,...) noexcept
Returns a (non-truncated) string according to snprintf() formatting rules and variable number of argu...