Line data Source code
1 : /* File: io_txt_writer.inl; Copyright and License: see below */
2 :
3 : #include <assert.h>
4 : #include "utf8stringbuf/utf8error.h"
5 :
6 0 : static inline u8_error_t io_txt_writer_write_plain ( io_txt_writer_t *this_, const char *text )
7 : {
8 0 : assert ( NULL != text );
9 0 : assert ( NULL != (*this_).output );
10 : u8_error_t write_err;
11 :
12 0 : const size_t text_len = strlen(text);
13 0 : write_err = universal_output_stream_write ( (*this_).output, text, text_len );
14 :
15 0 : return ( write_err );
16 : }
17 :
18 0 : static inline u8_error_t io_txt_writer_fill ( io_txt_writer_t *this_, char pattern, unsigned int count )
19 : {
20 0 : assert ( NULL != (*this_).output );
21 0 : u8_error_t write_err = U8_ERROR_NONE;
22 :
23 : /* prepare a buffer for optimized output */
24 : char buf[16];
25 0 : for ( unsigned int index = 0; index < 16; index++ )
26 : {
27 0 : buf[index] = pattern;
28 : }
29 :
30 : /* do write the buffer */
31 0 : unsigned int buf_count = count / 16;
32 0 : for ( unsigned int loop_count = 0; loop_count < buf_count; loop_count++ )
33 : {
34 0 : write_err |= universal_output_stream_write ( (*this_).output, &buf, sizeof(buf) );
35 : }
36 0 : unsigned int buf_remain = count % 16;
37 0 : write_err |= universal_output_stream_write ( (*this_).output, &buf, buf_remain );
38 :
39 0 : return ( write_err );
40 : }
41 :
42 :
43 : /*
44 : Copyright 2019-2025 Andreas Warnke
45 :
46 : Licensed under the Apache License, Version 2.0 (the "License");
47 : you may not use this file except in compliance with the License.
48 : You may obtain a copy of the License at
49 :
50 : http://www.apache.org/licenses/LICENSE-2.0
51 :
52 : Unless required by applicable law or agreed to in writing, software
53 : distributed under the License is distributed on an "AS IS" BASIS,
54 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
55 : See the License for the specific language governing permissions and
56 : limitations under the License.
57 : */
|