Line data Source code
1 : /* File: utf8stringviewiterator.inl; Copyright and License: see below */
2 :
3 : #ifdef __cplusplus
4 : extern "C" {
5 : #endif
6 :
7 5 : static inline void utf8stringviewiterator_init ( utf8stringviewiterator_t *this_, const utf8stringview_t *element_list, utf8string_t *separator )
8 : {
9 5 : assert( element_list != NULL );
10 5 : assert( separator != NULL );
11 5 : (*this_).remaining = *element_list;
12 5 : (*this_).separator = separator;
13 5 : (*this_).next_is_end = false;
14 5 : (*this_).has_next = true;
15 5 : utf8stringviewiterator_private_step_to_next( this_ );
16 5 : }
17 :
18 5 : static inline void utf8stringviewiterator_destroy ( utf8stringviewiterator_t *this_ )
19 : {
20 5 : }
21 :
22 15 : static inline bool utf8stringviewiterator_has_next ( const utf8stringviewiterator_t *this_ )
23 : {
24 15 : return (*this_).has_next;
25 : }
26 :
27 15 : static inline utf8stringview_t utf8stringviewiterator_next ( utf8stringviewiterator_t *this_ )
28 : {
29 15 : utf8stringview_t result = (*this_).next;
30 15 : utf8stringviewiterator_private_step_to_next( this_ );
31 15 : return result;
32 : }
33 :
34 20 : static inline void utf8stringviewiterator_private_step_to_next ( utf8stringviewiterator_t *this_ )
35 : {
36 20 : if ( (*this_).next_is_end )
37 : {
38 10 : (*this_).has_next = false;
39 10 : (*this_).next = UTF8STRINGVIEW_EMPTY;
40 : }
41 : else
42 : {
43 10 : utf8stringview_t before = UTF8STRINGVIEW_EMPTY;
44 10 : utf8stringview_t after = UTF8STRINGVIEW_EMPTY;
45 : const utf8error_t has_next
46 10 : = utf8stringview_split_at_first_str( &((*this_).remaining), (*this_).separator, &before, &after );
47 10 : if (( has_next != UTF8ERROR_SUCCESS )||( utf8string_get_length( (*this_).separator ) == 0 ))
48 5 : {
49 5 : (*this_).next_is_end = true;
50 5 : (*this_).next = (*this_).remaining;
51 5 : (*this_).remaining = UTF8STRINGVIEW_EMPTY;
52 : }
53 : else
54 : {
55 5 : (*this_).next = before;
56 5 : (*this_).remaining = after;
57 : }
58 : }
59 20 : }
60 :
61 : #ifdef __cplusplus
62 : }
63 : #endif
64 :
65 :
66 : /*
67 : Copyright 2021-2025 Andreas Warnke
68 :
69 : Licensed under the Apache License, Version 2.0 (the "License");
70 : you may not use this file except in compliance with the License.
71 : You may obtain a copy of the License at
72 :
73 : http://www.apache.org/licenses/LICENSE-2.0
74 :
75 : Unless required by applicable law or agreed to in writing, software
76 : distributed under the License is distributed on an "AS IS" BASIS,
77 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78 : See the License for the specific language governing permissions and
79 : limitations under the License.
80 : */
|