LCOV - differential code coverage report
Current view: top level - src/port - pgstrcasecmp.c (source / functions) Coverage Total Hit UBC CBC DCB
Current: 0e5ff9b9b45a657aea12440478dc002e9b01f138 vs 0123ce131fca454009439dfa3b2266d1d40737d7 Lines: 85.4 % 48 41 7 41 8
Current Date: 2026-03-14 14:10:32 -0400 Functions: 100.0 % 4 4 4 2
Baseline: lcov-20260315-024220-baseline Branches: 71.0 % 62 44 18 44 8
Baseline Date: 2026-03-14 15:27:56 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 85.4 % 48 41 7 41
Function coverage date bins:
(360..) days: 100.0 % 4 4 4
Branch coverage date bins:
(360..) days: 71.0 % 62 44 18 44

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * pgstrcasecmp.c
                                  4                 :                :  *     Portable SQL-like case-independent comparisons and conversions.
                                  5                 :                :  *
                                  6                 :                :  * SQL99 specifies Unicode-aware case normalization, which we don't yet
                                  7                 :                :  * have the infrastructure for.  Instead we use tolower() to provide a
                                  8                 :                :  * locale-aware translation.  However, there are some locales where this
                                  9                 :                :  * is not right either (eg, Turkish may do strange things with 'i' and
                                 10                 :                :  * 'I').  Our current compromise is to use tolower() for characters with
                                 11                 :                :  * the high bit set, and use an ASCII-only downcasing for 7-bit
                                 12                 :                :  * characters.
                                 13                 :                :  *
                                 14                 :                :  * NB: this code should match downcase_truncate_identifier() in scansup.c.
                                 15                 :                :  *
                                 16                 :                :  *
                                 17                 :                :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
                                 18                 :                :  *
                                 19                 :                :  * src/port/pgstrcasecmp.c
                                 20                 :                :  *
                                 21                 :                :  *-------------------------------------------------------------------------
                                 22                 :                :  */
                                 23                 :                : #include "c.h"
                                 24                 :                : 
                                 25                 :                : #include <ctype.h>
                                 26                 :                : 
                                 27                 :                : 
                                 28                 :                : /*
                                 29                 :                :  * Case-independent comparison of two null-terminated strings.
                                 30                 :                :  */
                                 31                 :                : int
 7982 tgl@sss.pgh.pa.us          32                 :CBC    12036890 : pg_strcasecmp(const char *s1, const char *s2)
                                 33                 :                : {
                                 34                 :                :     for (;;)
                                 35                 :        5396280 :     {
 7868 bruce@momjian.us           36                 :       17433170 :         unsigned char ch1 = (unsigned char) *s1++;
                                 37                 :       17433170 :         unsigned char ch2 = (unsigned char) *s2++;
                                 38                 :                : 
 7982 tgl@sss.pgh.pa.us          39         [ +  + ]:       17433170 :         if (ch1 != ch2)
                                 40                 :                :         {
                                 41   [ +  +  +  + ]:       11988636 :             if (ch1 >= 'A' && ch1 <= 'Z')
                                 42                 :        4818228 :                 ch1 += 'a' - 'A';
 7385 bruce@momjian.us           43   [ +  +  -  + ]:        7170408 :             else if (IS_HIGHBIT_SET(ch1) && isupper(ch1))
 7982 tgl@sss.pgh.pa.us          44                 :UBC           0 :                 ch1 = tolower(ch1);
                                 45                 :                : 
 7982 tgl@sss.pgh.pa.us          46   [ +  +  +  + ]:CBC    11988636 :             if (ch2 >= 'A' && ch2 <= 'Z')
                                 47                 :        3119254 :                 ch2 += 'a' - 'A';
 7385 bruce@momjian.us           48   [ -  +  -  - ]:        8869382 :             else if (IS_HIGHBIT_SET(ch2) && isupper(ch2))
 7982 tgl@sss.pgh.pa.us          49                 :UBC           0 :                 ch2 = tolower(ch2);
                                 50                 :                : 
 7982 tgl@sss.pgh.pa.us          51         [ +  + ]:CBC    11988636 :             if (ch1 != ch2)
                                 52                 :       10960232 :                 return (int) ch1 - (int) ch2;
                                 53                 :                :         }
                                 54         [ +  + ]:        6472938 :         if (ch1 == 0)
                                 55                 :        1076658 :             break;
                                 56                 :                :     }
                                 57                 :        1076658 :     return 0;
                                 58                 :                : }
                                 59                 :                : 
                                 60                 :                : /*
                                 61                 :                :  * Case-independent comparison of two not-necessarily-null-terminated strings.
                                 62                 :                :  * At most n bytes will be examined from each string.
                                 63                 :                :  */
                                 64                 :                : int
                                 65                 :        5928723 : pg_strncasecmp(const char *s1, const char *s2, size_t n)
                                 66                 :                : {
                                 67         [ +  + ]:        8535652 :     while (n-- > 0)
                                 68                 :                :     {
 7868 bruce@momjian.us           69                 :        6648912 :         unsigned char ch1 = (unsigned char) *s1++;
                                 70                 :        6648912 :         unsigned char ch2 = (unsigned char) *s2++;
                                 71                 :                : 
 7982 tgl@sss.pgh.pa.us          72         [ +  + ]:        6648912 :         if (ch1 != ch2)
                                 73                 :                :         {
                                 74   [ +  +  +  + ]:        4136115 :             if (ch1 >= 'A' && ch1 <= 'Z')
                                 75                 :        2867894 :                 ch1 += 'a' - 'A';
 7385 bruce@momjian.us           76   [ -  +  -  - ]:        1268221 :             else if (IS_HIGHBIT_SET(ch1) && isupper(ch1))
 7982 tgl@sss.pgh.pa.us          77                 :UBC           0 :                 ch1 = tolower(ch1);
                                 78                 :                : 
 7982 tgl@sss.pgh.pa.us          79   [ +  +  +  + ]:CBC     4136115 :             if (ch2 >= 'A' && ch2 <= 'Z')
                                 80                 :         140652 :                 ch2 += 'a' - 'A';
 7385 bruce@momjian.us           81   [ -  +  -  - ]:        3995463 :             else if (IS_HIGHBIT_SET(ch2) && isupper(ch2))
 7982 tgl@sss.pgh.pa.us          82                 :UBC           0 :                 ch2 = tolower(ch2);
                                 83                 :                : 
 7982 tgl@sss.pgh.pa.us          84         [ +  + ]:CBC     4136115 :             if (ch1 != ch2)
                                 85                 :        4041983 :                 return (int) ch1 - (int) ch2;
                                 86                 :                :         }
                                 87         [ -  + ]:        2606929 :         if (ch1 == 0)
 7982 tgl@sss.pgh.pa.us          88                 :UBC           0 :             break;
                                 89                 :                :     }
 7982 tgl@sss.pgh.pa.us          90                 :CBC     1886740 :     return 0;
                                 91                 :                : }
                                 92                 :                : 
                                 93                 :                : /*
                                 94                 :                :  * Fold a character to upper case.
                                 95                 :                :  *
                                 96                 :                :  * Unlike some versions of toupper(), this is safe to apply to characters
                                 97                 :                :  * that aren't lower case letters.  Note however that the whole thing is
                                 98                 :                :  * a bit bogus for multibyte character sets.
                                 99                 :                :  */
                                100                 :                : unsigned char
                                101                 :         172321 : pg_toupper(unsigned char ch)
                                102                 :                : {
                                103   [ +  +  +  - ]:         172321 :     if (ch >= 'a' && ch <= 'z')
                                104                 :         100408 :         ch += 'A' - 'a';
 7385 bruce@momjian.us          105   [ -  +  -  - ]:          71913 :     else if (IS_HIGHBIT_SET(ch) && islower(ch))
 7982 tgl@sss.pgh.pa.us         106                 :UBC           0 :         ch = toupper(ch);
 7982 tgl@sss.pgh.pa.us         107                 :CBC      172321 :     return ch;
                                108                 :                : }
                                109                 :                : 
                                110                 :                : /*
                                111                 :                :  * Fold a character to lower case.
                                112                 :                :  *
                                113                 :                :  * Unlike some versions of tolower(), this is safe to apply to characters
                                114                 :                :  * that aren't upper case letters.  Note however that the whole thing is
                                115                 :                :  * a bit bogus for multibyte character sets.
                                116                 :                :  */
                                117                 :                : unsigned char
                                118                 :        7937442 : pg_tolower(unsigned char ch)
                                119                 :                : {
                                120   [ +  +  +  + ]:        7937442 :     if (ch >= 'A' && ch <= 'Z')
                                121                 :        5063763 :         ch += 'a' - 'A';
 7385 bruce@momjian.us          122   [ -  +  -  - ]:        2873679 :     else if (IS_HIGHBIT_SET(ch) && isupper(ch))
 7982 tgl@sss.pgh.pa.us         123                 :UBC           0 :         ch = tolower(ch);
 7982 tgl@sss.pgh.pa.us         124                 :CBC     7937442 :     return ch;
                                125                 :                : }
        

Generated by: LCOV version 2.4-beta