LCOV - code coverage report
Current view: top level - lib/dpkg - c-ctype.h (source / functions) Hit Total Coverage
Test: dpkg 1.21.11 C code coverage Lines: 19 19 100.0 %
Date: 2022-12-03 00:40:01 Functions: 9 9 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 2 100.0 %

           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 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                 :        713 : c_isblank(int c)
      52                 :            : {
      53                 :        713 :         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                 :       2994 : c_isspace(int c)
      70                 :            : {
      71                 :       2994 :         return c_isbits(c, C_CTYPE_SPACE);
      72                 :            : }
      73                 :            : 
      74                 :            : /**
      75                 :            :  * Check if the character is [0-9].
      76                 :            :  */
      77                 :            : static inline bool
      78                 :       1227 : c_isdigit(int c)
      79                 :            : {
      80                 :       1227 :         return c_isbits(c, C_CTYPE_DIGIT);
      81                 :            : }
      82                 :            : 
      83                 :            : /**
      84                 :            :  * Check if the character is [A-Z].
      85                 :            :  */
      86                 :            : static inline bool
      87                 :       1351 : c_isupper(int c)
      88                 :            : {
      89                 :       1351 :         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                 :        188 : c_isalpha(int c)
     106                 :            : {
     107                 :        188 :         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                 :        672 : c_isalnum(int c)
     115                 :            : {
     116                 :        672 :         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                 :       1351 : c_tolower(int c)
     124                 :            : {
     125                 :       1351 :         return (c_isupper(c) ?
     126         [ +  + ]:       1351 :                 (DPKG_STATIC_CAST(unsigned char, c) & ~0x20) | 0x20 : c);
     127                 :            : }
     128                 :            : 
     129                 :            : DPKG_END_DECLS
     130                 :            : 
     131                 :            : #endif

Generated by: LCOV version 1.16