LCOV - code coverage report
Current view: top level - lib/dpkg - c-ctype.h (source / functions) Coverage Total Hit
Test: dpkg 1.22.7-3-g89f48 C code coverage Lines: 100.0 % 19 19
Test Date: 2024-07-17 02:53:43 Functions: 100.0 % 9 9
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 100.0 % 2 2

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * libdpkg - Debian packaging suite library routines
       3                 :             :  * c-ctype.h - ASCII C locale-only functions
       4                 :             :  *
       5                 :             :  * Copyright © 2009-2014 Guillem Jover <guillem@debian.org>
       6                 :             :  *
       7                 :             :  * This is free software; you can redistribute it and/or modify
       8                 :             :  * it under the terms of the GNU General Public License as published by
       9                 :             :  * the Free Software Foundation; either version 2 of the License, or
      10                 :             :  * (at your option) any later version.
      11                 :             :  *
      12                 :             :  * This is distributed in the hope that it will be useful,
      13                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :             :  * GNU General Public License for more details.
      16                 :             :  *
      17                 :             :  * You should have received a copy of the GNU General Public License
      18                 :             :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      19                 :             :  */
      20                 :             : 
      21                 :             : #ifndef LIBDPKG_C_CTYPE_H
      22                 :             : #define LIBDPKG_C_CTYPE_H
      23                 :             : 
      24                 :             : #include <stdbool.h>
      25                 :             : 
      26                 :             : #include <dpkg/macros.h>
      27                 :             : 
      28                 :             : DPKG_BEGIN_DECLS
      29                 :             : 
      30                 :             : #define C_CTYPE_BIT(bit)        (1 << (bit))
      31                 :             : 
      32                 :             : enum DPKG_ATTR_ENUM_FLAGS c_ctype_bit {
      33                 :             :         C_CTYPE_BLANK = C_CTYPE_BIT(0),
      34                 :             :         C_CTYPE_WHITE = C_CTYPE_BIT(1),
      35                 :             :         C_CTYPE_SPACE = C_CTYPE_BIT(2),
      36                 :             :         C_CTYPE_UPPER = C_CTYPE_BIT(3),
      37                 :             :         C_CTYPE_LOWER = C_CTYPE_BIT(4),
      38                 :             :         C_CTYPE_DIGIT = C_CTYPE_BIT(5),
      39                 :             : 
      40                 :             :         C_CTYPE_ALPHA = C_CTYPE_UPPER | C_CTYPE_LOWER,
      41                 :             :         C_CTYPE_ALNUM = C_CTYPE_ALPHA | C_CTYPE_DIGIT,
      42                 :             : };
      43                 :             : 
      44                 :             : bool
      45                 :             : c_isbits(int c, enum c_ctype_bit bits);
      46                 :             : 
      47                 :             : /**
      48                 :             :  * Check if the character is [ \t].
      49                 :             :  */
      50                 :             : static inline bool
      51                 :         761 : c_isblank(int c)
      52                 :             : {
      53                 :         761 :         return c_isbits(c, C_CTYPE_BLANK);
      54                 :             : }
      55                 :             : 
      56                 :             : /**
      57                 :             :  * Check if the character is [ \t\n].
      58                 :             :  */
      59                 :             : static inline bool
      60                 :          66 : c_iswhite(int c)
      61                 :             : {
      62                 :          66 :         return c_isbits(c, C_CTYPE_WHITE);
      63                 :             : }
      64                 :             : 
      65                 :             : /**
      66                 :             :  * Check if the character is [ \v\t\f\r\n].
      67                 :             :  */
      68                 :             : static inline bool
      69                 :        3874 : c_isspace(int c)
      70                 :             : {
      71                 :        3874 :         return c_isbits(c, C_CTYPE_SPACE);
      72                 :             : }
      73                 :             : 
      74                 :             : /**
      75                 :             :  * Check if the character is [0-9].
      76                 :             :  */
      77                 :             : static inline bool
      78                 :        1308 : c_isdigit(int c)
      79                 :             : {
      80                 :        1308 :         return c_isbits(c, C_CTYPE_DIGIT);
      81                 :             : }
      82                 :             : 
      83                 :             : /**
      84                 :             :  * Check if the character is [A-Z].
      85                 :             :  */
      86                 :             : static inline bool
      87                 :        1575 : c_isupper(int c)
      88                 :             : {
      89                 :        1575 :         return c_isbits(c, C_CTYPE_UPPER);
      90                 :             : }
      91                 :             : 
      92                 :             : /**
      93                 :             :  * Check if the character is [a-z].
      94                 :             :  */
      95                 :             : static inline bool
      96                 :          60 : c_islower(int c)
      97                 :             : {
      98                 :          60 :         return c_isbits(c, C_CTYPE_LOWER);
      99                 :             : }
     100                 :             : 
     101                 :             : /**
     102                 :             :  * Check if the character is [a-zA-Z].
     103                 :             :  */
     104                 :             : static inline bool
     105                 :         196 : c_isalpha(int c)
     106                 :             : {
     107                 :         196 :         return c_isbits(c, C_CTYPE_ALPHA);
     108                 :             : }
     109                 :             : 
     110                 :             : /**
     111                 :             :  * Check if the character is [a-zA-Z0-9].
     112                 :             :  */
     113                 :             : static inline bool
     114                 :         792 : c_isalnum(int c)
     115                 :             : {
     116                 :         792 :         return c_isbits(c, C_CTYPE_ALNUM);
     117                 :             : }
     118                 :             : 
     119                 :             : /**
     120                 :             :  * Maps the character to its lower-case form.
     121                 :             :  */
     122                 :             : static inline int
     123                 :        1575 : c_tolower(int c)
     124                 :             : {
     125                 :        1575 :         return (c_isupper(c) ?
     126         [ +  + ]:        1575 :                 (DPKG_STATIC_CAST(unsigned char, c) & ~0x20) | 0x20 : c);
     127                 :             : }
     128                 :             : 
     129                 :             : DPKG_END_DECLS
     130                 :             : 
     131                 :             : #endif
        

Generated by: LCOV version 2.0-1