1#pragma once
2
3/*
4 * StringIO provides LineReader interface.
5 * It's a singleton iterator for self.
6 */
7
8#include <pw.h>
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14extern uint16_t PwTypeId_StringIO;
15
16#define pw_is_stringio(value) pw_is_subtype((value), PwTypeId_StringIO)
17
18
19/****************************************************************
20 * Constructors
21 */
22
23PW_STRUCT(PwStringIOCtorArgs) {
24 PwCtorArgs* next;
25 uint16_t type_id;
26
27 PwValuePtr string;
28};
29
30#define pw_create_string_io(result, str) _Generic((str), \
31 char*: _pw_create_string_io_ascii, \
32 char8_t*: _pw_create_string_io_utf8, \
33 char32_t*: _pw_create_string_io_utf32, \
34 PwValuePtr: _pw_create_string_io \
35 )((result), (str))
36
37[[nodiscard]] static inline bool _pw_create_string_io(PwValuePtr result, PwValuePtr str)
38{
39 PwStringIOCtorArgs args = {
40 .type_id = PwTypeId_StringIO,
41 .string = str
42 };
43 return pw_create2(PwTypeId_StringIO, &args, result);
44}
45
46[[nodiscard]] static inline bool _pw_create_string_io_ascii(PwValuePtr result, char* str)
47{
48 _PwValue s = PwStaticString(str);
49 PwStringIOCtorArgs args = {
50 .type_id = PwTypeId_StringIO,
51 .string = &s
52 };
53 return pw_create2(PwTypeId_StringIO, &args, result);
54}
55
56[[nodiscard]] static inline bool _pw_create_string_io_utf8 (PwValuePtr result, char8_t* str)
57{
58 PwValue s = PW_NULL;
59 if (!pw_create_string(&s, str)) {
60 return false;
61 }
62 PwStringIOCtorArgs args = {
63 .type_id = PwTypeId_StringIO,
64 .string = &s
65 };
66 return pw_create2(PwTypeId_StringIO, &args, result);
67}
68
69[[nodiscard]] static inline bool _pw_create_string_io_utf32(PwValuePtr result, char32_t* str)
70{
71 _PwValue s = PwStaticStringUtf32(str);
72 PwStringIOCtorArgs args = {
73 .type_id = PwTypeId_StringIO,
74 .string = &s
75 };
76 return pw_create2(PwTypeId_StringIO, &args, result);
77}
78
79
80#ifdef __cplusplus
81}
82#endif