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#define pw_assert_stringio(value) pw_assert(pw_is_stringio(value))
18
19
20/****************************************************************
21 * Constructors
22 */
23
24typedef struct {
25 PwCtorArgs* next;
26 uint16_t type_id;
27
28 PwValuePtr string;
29
30} PwStringIOCtorArgs;
31
32#define pw_create_string_io(result, str) _Generic((str), \
33 char*: _pw_create_string_io_ascii, \
34 char8_t*: _pw_create_string_io_utf8, \
35 char32_t*: _pw_create_string_io_utf32, \
36 PwValuePtr: _pw_create_string_io \
37 )((result), (str))
38
39[[nodiscard]] static inline bool _pw_create_string_io(PwValuePtr result, PwValuePtr str)
40{
41 PwStringIOCtorArgs args = {
42 .type_id = PwTypeId_StringIO,
43 .string = str
44 };
45 return pw_create2(PwTypeId_StringIO, &args, result);
46}
47
48[[nodiscard]] static inline bool _pw_create_string_io_ascii(PwValuePtr result, char* str)
49{
50 _PwValue s = PwStaticString(str);
51 PwStringIOCtorArgs args = {
52 .type_id = PwTypeId_StringIO,
53 .string = &s
54 };
55 return pw_create2(PwTypeId_StringIO, &args, result);
56}
57
58[[nodiscard]] static inline bool _pw_create_string_io_utf8 (PwValuePtr result, char8_t* str)
59{
60 PwValue s = PW_NULL;
61 if (!pw_create_string(&s, str)) {
62 return false;
63 }
64 PwStringIOCtorArgs args = {
65 .type_id = PwTypeId_StringIO,
66 .string = &s
67 };
68 return pw_create2(PwTypeId_StringIO, &args, result);
69}
70
71[[nodiscard]] static inline bool _pw_create_string_io_utf32(PwValuePtr result, char32_t* str)
72{
73 _PwValue s = PwStaticStringUtf32(str);
74 PwStringIOCtorArgs args = {
75 .type_id = PwTypeId_StringIO,
76 .string = &s
77 };
78 return pw_create2(PwTypeId_StringIO, &args, result);
79}
80
81
82#ifdef __cplusplus
83}
84#endif