libcstl
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1/*!
2 * @file
3 *
4 * This is the public-facing header for string objects. The actual
5 * implementation is in _string.[ch], hidden behind a lot of macros
6 * that function as a poor man's template. This allows the same code
7 * to implement both narrow and wide character string objects.
8 *
9 * This file sets the @p %cstl_STRING, @p %STRCHAR, and @p %STDSTRPFX macros,
10 * and then includes the actual implementation file to import all of its
11 * types, functions, and prototypes.
12 *
13 * To add new variants:
14 * - @p %cstl_STRING should be set to the name of the string
15 * object, e.g. string, wstring
16 * - @p %STRCHAR should be the type of character housed by the string,
17 * e.g. char, wchar_t
18 * - @p %STDSTRPFX should be the prefix of standard library functions
19 * associated with the type of string being implemented. For example,
20 * the implementation relies on the @p strlen() function. For the narrow
21 * string, @p %STDSTRPFX is set to @p str to select @p strlen(). For
22 * the wide string, it would be @p wcs to select @p wcslen().
23 *
24 * @see _string.h for the templatized %string object header
25 */
26
27#ifndef CSTL_STRING_H
28#define CSTL_STRING_H
29
30#include "cstl/vector.h"
31
32#ifndef NO_DOC
33#define cstl_STRING cstl_string
34#define STRCHAR char
35#define STDSTRPFX str
36#include "cstl/_string.h"
37#undef STDSTRPFX
38#undef STRCHAR
39#undef cstl_STRING
40#endif
41
42#include <wchar.h>
43#ifndef NO_DOC
44#define cstl_STRING cstl_wstring
45#define STRCHAR wchar_t
46#define STDSTRPFX wcs
47#include "cstl/_string.h"
48#undef STDSTRPFX
49#undef STRCHAR
50#undef cstl_STRING
51#endif
52
53/*!
54 * @addtogroup string
55 * @{
56 */
57
58/*!
59 * @name Supported string types
60 * @{
61 */
62/*! @brief String of narrow characters */
63typedef struct cstl_string cstl_string_t;
64/*! @brief String of wide characters */
65typedef struct cstl_wstring cstl_wstring_t;
66/*!
67 * @}
68 */
69
70/*!
71 * @brief Constant initialization of a string object
72 *
73 * Unlike the templatized functions, "STRING" is not a placeholder
74 * for a "templatized" name. This macro/function is called literally as
75 * CSTL_STRING_INITIALIZER() and the @p CTYPE parameter is the type of
76 * character held by the string object, e.g. @p cstl_string_char_t,
77 * @p cstl_wstring_char_t
78 *
79 * @param CTYPE The type of character that the string will hold
80 */
81#define CSTL_STRING_INITIALIZER(CTYPE) \
82 { \
83 .v = CSTL_VECTOR_INITIALIZER(CTYPE), \
84 }
85/*!
86 * @brief (Statically) declare and initialize a vector
87 *
88 * Unlike the templatized functions, "STRING" is not a placeholder
89 * for a "templatized" name. This macro/function is called literally as
90 * DECLARE_CSTL_STRING() and the @p TYPE parameter is the type of string
91 * object being declared without the @p cstl_ prefix, e.g.
92 * @code{.c}
93 * DECLARE_CSTL_STRING(string, s);
94 * // or
95 * DECLARE_CSTL_STRING(wstring, ws);
96 * @endcode
97 *
98 * @param TYPE The type of string object being declared
99 * @param NAME The name of the variable being declared
100 */
101#define DECLARE_CSTL_STRING(TYPE, NAME) \
102 struct cstl_##TYPE NAME = \
103 CSTL_STRING_INITIALIZER(cstl_##TYPE##_char_t)
104/*!
105 * @}
106 */
107
108#endif
struct cstl_wstring cstl_wstring_t
String of wide characters.
Definition string.h:65
struct cstl_string cstl_string_t
String of narrow characters.
Definition string.h:63