Skip to content

Commit 5168a28

Browse files
committed
Improve documentation of safe_string*(), null_safe_string*() functions
[why] It is a jungle. The safe_string*() functions respect C-string style null termination, the null_safe_string*() functions only do that if they do not have a length parameter. Proposed-by: Fini Jastrow <ulf.fini.jastrow@desy.de> Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
1 parent f7fd629 commit 5168a28

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

include/gul17/string_util.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,43 +230,44 @@ hex_string(const Container& container, std::string_view separator = "")
230230
* to find a zero-terminated C string and constructs a std::string from it.
231231
*
232232
* \code
233-
* auto a = safe_string(nullptr); // a == ""s
234-
* auto b = safe_string("ABC"); // b == "ABC"s
235-
* auto c = safe_string("AB\0CD"); // c == "AB"s
233+
* auto a = null_safe_string(nullptr); // a == ""s
234+
* auto b = null_safe_string("ABC"); // b == "ABC"s
235+
* auto c = null_safe_string("AB\0CD"); // c == "AB"s
236236
* \endcode
237237
*
238238
* \param char_ptr Pointer to a null-terminated string or a null pointer
239239
*
240-
* \see safe_string(), null_safe_string_view()
240+
* \see null_safe_string_view(), safe_string(), safe_string_view()
241241
*
242242
* \since version 25.7.0
243243
*/
244244
GUL_EXPORT
245245
std::string null_safe_string(const char* char_ptr);
246246

247247
/**
248-
* Safely construct a string_view from a char pointer.
248+
* Safely construct a string_view from a C string or a null pointer.
249249
*
250250
* If the pointer is null, an empty string_view is constructed. Otherwise, the function
251251
* assumes to find a zero-terminated C string and constructs a std::string_view from it.
252252
*
253253
* \code
254-
* auto a = safe_string_view(nullptr); // a == ""sv
255-
* auto b = safe_string_view("ABC"); // b == "ABC"sv
256-
* auto c = safe_string_view("AB\0CD"); // c == "AB"sv
254+
* auto a = null_safe_string_view(nullptr); // a == ""sv
255+
* auto b = null_safe_string_view("ABC"); // b == "ABC"sv
256+
* auto c = null_safe_string_view("AB\0CD"); // c == "AB"sv
257257
* \endcode
258258
*
259259
* \param char_ptr Pointer to a null-terminated string or a null pointer
260260
*
261-
* \see safe_string_view(), null_safe_string()
261+
* \see null_safe_string(), safe_string(), safe_string_view()
262262
*
263263
* \since version 25.7.0
264264
*/
265265
GUL_EXPORT
266266
std::string_view null_safe_string_view(const char* char_ptr);
267267

268268
/**
269-
* Safely construct a string_view from a char pointer and a length.
269+
* Safely construct a string_view from a char pointer and a length; intermediate null
270+
* bytes do not terminate the string.
270271
*
271272
* If the pointer is null, an empty string_view is constructed. Otherwise, the function
272273
* constructs a std::string_view with the specified length from it. Zero bytes in the
@@ -282,7 +283,7 @@ std::string_view null_safe_string_view(const char* char_ptr);
282283
* null pointer
283284
* \param length Length of the generated string_view (unless the pointer is null)
284285
*
285-
* \see safe_string_view(), null_safe_string()
286+
* \see null_safe_string(), safe_string(), safe_string_view()
286287
*
287288
* \since version UNRELEASED
288289
*/
@@ -306,7 +307,8 @@ GUL_EXPORT
306307
std::string repeat(std::string_view str, std::size_t n);
307308

308309
/**
309-
* Safely construct a std::string from a char pointer and a length.
310+
* Safely construct a std::string from a char pointer and a length, respecting null
311+
* termination in the style of a C string.
310312
*
311313
* If the pointer is null, an empty string is constructed. If there are no zero bytes in
312314
* the input range, a string of length \c length is constructed. Otherwise, the input
@@ -324,15 +326,16 @@ std::string repeat(std::string_view str, std::size_t n);
324326
* \c length accessible bytes, or a null pointer
325327
* \param length Maximum length of the generated string
326328
*
327-
* \see null_safe_string(), safe_string_view()
329+
* \see null_safe_string(), null_safe_string_view(), safe_string_view()
328330
*
329331
* \since GUL version 2.6
330332
*/
331333
GUL_EXPORT
332334
std::string safe_string(const char* char_ptr, std::size_t length);
333335

334336
/**
335-
* Safely construct a string_view from a char pointer and a length.
337+
* Safely construct a string_view from a char pointer and a length, respecting null
338+
* termination in the style of a C string.
336339
*
337340
* If the pointer is null, an empty string_view is constructed. If there are no zero bytes
338341
* in the input range, a string_view of length \c length is constructed. Otherwise, the
@@ -350,7 +353,7 @@ std::string safe_string(const char* char_ptr, std::size_t length);
350353
* \c length accessible bytes, or a null pointer
351354
* \param length Maximum length of the generated string_view
352355
*
353-
* \see null_safe_string_view(), safe_string()
356+
* \see null_safe_string(), null_safe_string_view(), safe_string()
354357
*
355358
* \since GUL version 25.4.0
356359
*/

0 commit comments

Comments
 (0)