LCOV - code coverage report
Current view: top level - u8stream/include/u8stream - universal_buffer_input_stream.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.57.0_covts Lines: 34 34 100.0 %
Date: 2024-04-07 11:14:42 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* File: universal_buffer_input_stream.inl; Copyright and License: see below */
       2             : 
       3             : #include <assert.h>
       4             : 
       5       34996 : static inline char universal_buffer_input_stream_peek_next( universal_buffer_input_stream_t *this_ )
       6             : {
       7       34996 :     assert( (*this_).mem_buf_start != NULL );
       8       34996 :     assert( (*this_).mem_buf_fill >= (*this_).mem_buf_pos );
       9       34996 :     assert( (*this_).mem_buf_size >= (*this_).mem_buf_fill );
      10       34996 :     char result = '\0';
      11             : 
      12       34996 :     const size_t buf_available1 = (*this_).mem_buf_fill - (*this_).mem_buf_pos;
      13       34996 :     if ( buf_available1 == 0 )
      14             :     {
      15             :         /* try to fill buffer */
      16         134 :         (*this_).stream_pos_of_buf += (*this_).mem_buf_fill;
      17         134 :         (*this_).mem_buf_pos = 0;
      18         134 :         (*this_).mem_buf_fill = 0;
      19             :         const int err
      20         134 :             = universal_input_stream_read( (*this_).source, (*this_).mem_buf_start, (*this_).mem_buf_size, &((*this_).mem_buf_fill) );
      21         134 :         if (( 0 == err )&&( (*this_).mem_buf_fill > 0 ))
      22             :         {
      23         111 :             result = (*(  (char(*)[]) (*this_).mem_buf_start  ))[0];
      24             :         }
      25             :     }
      26             :     else
      27             :     {
      28       34862 :         result = (*(  (char(*)[]) (*this_).mem_buf_start  ))[(*this_).mem_buf_pos];
      29             :     }
      30             : 
      31       34996 :     return result;
      32             : }
      33             : 
      34       26948 : static inline char universal_buffer_input_stream_read_next( universal_buffer_input_stream_t *this_ )
      35             : {
      36       26948 :     assert( (*this_).mem_buf_start != NULL );
      37       26948 :     assert( (*this_).mem_buf_fill >= (*this_).mem_buf_pos );
      38       26948 :     assert( (*this_).mem_buf_size >= (*this_).mem_buf_fill );
      39       26948 :     char result = '\0';
      40             : 
      41       26948 :     const size_t buf_available1 = (*this_).mem_buf_fill - (*this_).mem_buf_pos;
      42       26948 :     if ( buf_available1 == 0 )
      43             :     {
      44             :         /* try to fill buffer */
      45           2 :         (*this_).stream_pos_of_buf += (*this_).mem_buf_fill;
      46           2 :         (*this_).mem_buf_pos = 0;
      47           2 :         (*this_).mem_buf_fill = 0;
      48             :         const int err
      49           2 :             = universal_input_stream_read( (*this_).source, (*this_).mem_buf_start, (*this_).mem_buf_size, &((*this_).mem_buf_fill) );
      50           2 :         if (( 0 == err )&&( (*this_).mem_buf_fill > 0 ))
      51             :         {
      52           1 :             result = (*(  (char(*)[]) (*this_).mem_buf_start  ))[0];
      53           1 :             (*this_).mem_buf_pos = 1;
      54             :         }
      55             :     }
      56             :     else
      57             :     {
      58       26946 :         result = (*(  (char(*)[]) (*this_).mem_buf_start  ))[(*this_).mem_buf_pos];
      59       26946 :         (*this_).mem_buf_pos ++;
      60             :     }
      61             : 
      62       26948 :     return result;
      63             : }
      64             : 
      65          52 : static inline size_t universal_buffer_input_stream_read_pos ( universal_buffer_input_stream_t *this_ )
      66             : {
      67          52 :     return (*this_).stream_pos_of_buf + (*this_).mem_buf_pos;
      68             : }
      69             : 
      70             : 
      71             : /*
      72             : Copyright 2021-2024 Andreas Warnke
      73             : 
      74             : Licensed under the Apache License, Version 2.0 (the "License");
      75             : you may not use this file except in compliance with the License.
      76             : You may obtain a copy of the License at
      77             : 
      78             :     http://www.apache.org/licenses/LICENSE-2.0
      79             : 
      80             : Unless required by applicable law or agreed to in writing, software
      81             : distributed under the License is distributed on an "AS IS" BASIS,
      82             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      83             : See the License for the specific language governing permissions and
      84             : limitations under the License.
      85             : */

Generated by: LCOV version 1.16