LCOV - code coverage report
Current view: top level - u8stream/include/utf8stream - utf8stream_writemem.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.61.0_covts Lines: 28 28 100.0 %
Date: 2024-10-26 21:44:38 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /* File: utf8stream_writemem.c; Copyright and License: see below */
       2             : 
       3             : #include "u8/u8_trace.h"
       4             : #include <string.h>
       5             : #include <inttypes.h>
       6             : #include <assert.h>
       7             : 
       8           4 : static inline void utf8stream_writemem_init( utf8stream_writemem_t *this_, void* mem_buf_start, size_t mem_buf_size )
       9             : {
      10           4 :     assert( mem_buf_start != NULL );
      11           4 :     assert( mem_buf_size != 0 );
      12           4 :     universal_memory_output_stream_init( &((*this_).mem_output),
      13             :                                          mem_buf_start,
      14             :                                          mem_buf_size,
      15             :                                          UNIVERSAL_MEMORY_OUTPUT_STREAM_0TERM_UTF8
      16             :                                        );
      17           4 :     utf8stream_writer_init( &((*this_).writer),
      18             :                             universal_memory_output_stream_get_output_stream( &((*this_).mem_output) )
      19             :                           );
      20           4 :     (*this_).lazy_err = U8_ERROR_NONE;
      21           4 : }
      22             : 
      23           4 : static inline u8_error_t utf8stream_writemem_destroy( utf8stream_writemem_t *this_ )
      24             : {
      25           4 :     u8_error_t err = (*this_).lazy_err;
      26           4 :     err |= utf8stream_writer_destroy( &((*this_).writer) );
      27             :     /* avoid duplicate flush; therefore do not call */
      28             :     /* err |= universal_memory_output_stream_destroy( &((*this_).mem_output) ); */
      29           4 :     return err;
      30             : }
      31             : 
      32         262 : static inline u8_error_t utf8stream_writemem_reset ( utf8stream_writemem_t *this_ )
      33             : {
      34         262 :     u8_error_t err = (*this_).lazy_err;
      35         262 :     (*this_).lazy_err = U8_ERROR_NONE;
      36         262 :     err |= utf8stream_writer_flush( &((*this_).writer) );
      37         262 :     err |= universal_memory_output_stream_reset( &((*this_).mem_output) );
      38         262 :     return err;
      39             : }
      40             : 
      41         263 : static inline utf8stream_writer_t * utf8stream_writemem_get_writer( utf8stream_writemem_t *this_ )
      42             : {
      43         263 :     return &((*this_).writer);
      44             : }
      45             : 
      46         256 : static inline utf8stringview_t utf8stream_writemem_get_view( utf8stream_writemem_t *this_ )
      47             : {
      48         256 :     (*this_).lazy_err |= utf8stream_writer_flush( &((*this_).writer) );
      49             : 
      50         256 :     const void* start = universal_memory_output_stream_get_start( &((*this_).mem_output) );
      51         256 :     const size_t length = universal_memory_output_stream_get_fill( &((*this_).mem_output) );
      52             : 
      53         256 :     return UTF8STRINGVIEW( start, length );
      54             : }
      55             : 
      56           6 : static inline utf8string_t * utf8stream_writemem_get_string( utf8stream_writemem_t *this_ )
      57             : {
      58           6 :     (*this_).lazy_err |= utf8stream_writer_flush( &((*this_).writer) );
      59             : 
      60           6 :     const void* start = universal_memory_output_stream_get_start( &((*this_).mem_output) );
      61             : 
      62           6 :     return start;
      63             : }
      64             : 
      65             : 
      66             : /*
      67             : Copyright 2024-2024 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             : */

Generated by: LCOV version 1.16