LCOV - code coverage report
Current view: top level - u8stream/include/utf8stringbuf - utf8string.inl (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.63.2_covts Lines: 100.0 % 42 42
Test Date: 2025-05-01 10:10:14 Functions: 100.0 % 7 7

            Line data    Source code
       1              : /* File: utf8string.inl; Copyright and License: see below */
       2              : 
       3              : #include "utf8stringbuf/utf8codepoint.h"
       4              : #include <string.h>
       5              : #include <stdio.h>
       6              : #include <stdint.h>
       7              : #include <stdlib.h>
       8              : #include <errno.h>
       9              : 
      10              : #ifdef __cplusplus
      11              : extern "C" {
      12              : #endif
      13              : 
      14              : /*!
      15              :  *  \enum utf8string_bool_enum
      16              :  *  \private
      17              :  */
      18              : /*  enumeration for true and false or success and failure */
      19              : enum utf8string_bool_enum {UTF8STRING_FALSE=0, UTF8STRING_TRUE=1,};
      20              : 
      21           28 : static inline size_t utf8string_get_size( utf8string_t *this_ ) {
      22           28 :     size_t sizeResult = 0;
      23           28 :     if ( this_ != NULL ) {
      24           26 :         sizeResult = strlen( this_ ) + 1; /* 1 for size of terminating 0 character */
      25              :     }
      26           28 :     return sizeResult;
      27              : }
      28              : 
      29          256 : static inline unsigned int utf8string_get_length( utf8string_t *this_ ) {
      30          256 :     unsigned int lenResult = 0;
      31          256 :     if ( this_ != NULL ) {
      32          255 :         lenResult = strlen( this_ );
      33              :     }
      34          256 :     return lenResult;
      35              : }
      36              : 
      37           92 : static inline int utf8string_equals_str( utf8string_t *this_, utf8string_t *that ) {
      38           92 :     int cmpResult = -1;
      39           92 :     if (( this_ != NULL ) && ( that != NULL )) {
      40           89 :         cmpResult = strcmp( this_, that );
      41              :     }
      42           92 :     return ( cmpResult == 0 ) ? UTF8STRING_TRUE : UTF8STRING_FALSE;
      43              : }
      44              : 
      45           54 : static inline int utf8string_starts_with_str( utf8string_t *this_, utf8string_t *that ) {
      46           54 :     int cmpResult = -1;
      47           54 :     if (( this_ != NULL )&&( that != NULL )) {
      48           51 :         unsigned int thatLen = strlen( that );
      49           51 :         cmpResult = strncmp( this_, that, thatLen );
      50              :     }
      51           54 :     return ( cmpResult == 0 ) ? UTF8STRING_TRUE : UTF8STRING_FALSE;
      52              : }
      53              : 
      54           12 : static inline int utf8string_ends_with_str( utf8string_t *this_, utf8string_t *that ) {
      55           12 :     int cmpResult = -1;
      56           12 :     if (( this_ != NULL )&&( that != NULL )) {
      57            9 :         unsigned int thatLen = strlen( that );
      58            9 :         unsigned int thisLen = strlen( this_ );
      59            9 :         if ( thatLen <= thisLen ) {
      60            8 :             cmpResult = memcmp( &(this_[thisLen-thatLen]), that, thatLen );
      61              :         }
      62              :     }
      63           12 :     return ( cmpResult == 0 ) ? UTF8STRING_TRUE : UTF8STRING_FALSE;
      64              : }
      65              : 
      66            7 : static inline bool utf8string_contains_str( utf8string_t *this_, utf8string_t *pattern ) {
      67            7 :     bool result = false;
      68            7 :     if (( pattern != NULL )&&( this_ != NULL )) {
      69            4 :         const char *ptrResult = strstr( this_, pattern );
      70            4 :         if ( ptrResult != NULL ) {
      71            2 :             result = true;
      72              :         }
      73              :     }
      74            7 :     return result;
      75              : }
      76              : 
      77           22 : static inline utf8codepoint_t utf8string_get_char_at( utf8string_t *this_, unsigned int byte_index ) {
      78           22 :     utf8codepoint_t result = UTF8CODEPOINT_INVAL_CHAR;
      79           22 :     unsigned int thisSize = utf8string_get_size( this_ );
      80           22 :     if ( byte_index < thisSize ) {
      81           20 :         result = utf8codepoint_new( &(this_[byte_index]), thisSize-byte_index );
      82              :     }
      83           22 :     return result;
      84              : }
      85              : 
      86              : #ifdef __cplusplus
      87              : }
      88              : #endif
      89              : 
      90              : 
      91              : /*
      92              :  * Copyright 2012-2025 Andreas Warnke
      93              :  *
      94              :  * Licensed under the Apache License, Version 2.0 (the "License");
      95              :  * you may not use this file except in compliance with the License.
      96              :  * You may obtain a copy of the License at
      97              :  *
      98              :  *    http://www.apache.org/licenses/LICENSE-2.0
      99              :  *
     100              :  * Unless required by applicable law or agreed to in writing, software
     101              :  * distributed under the License is distributed on an "AS IS" BASIS,
     102              :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     103              :  * See the License for the specific language governing permissions and
     104              :  * limitations under the License.
     105              :  */
        

Generated by: LCOV version 2.0-1