LCOV - differential code coverage report
Current view: top level - src/port - pgstrcasecmp.c (source / functions) Coverage Total Hit UBC CBC
Current: a2387c32f2f8a1643c7d71b951587e6bcb2d4744 vs 371a302eecdc82274b0ae2967d18fd726a0aa6a1 Lines: 87.5 % 56 49 7 49
Current Date: 2025-10-26 12:31:50 -0700 Functions: 100.0 % 6 6 6
Baseline: lcov-20251027-010456-baseline Branches: 74.3 % 70 52 18 52
Baseline Date: 2025-10-26 11:01:32 +1300 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 87.5 % 56 49 7 49
Function coverage date bins:
(360..) days: 100.0 % 6 6 6
Branch coverage date bins:
(360..) days: 74.3 % 70 52 18 52

 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                 :                :  * We also provide strict ASCII-only case conversion functions, which can
                                 17                 :                :  * be used to implement C/POSIX case folding semantics no matter what the
                                 18                 :                :  * C library thinks the locale is.
                                 19                 :                :  *
                                 20                 :                :  *
                                 21                 :                :  * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
                                 22                 :                :  *
                                 23                 :                :  * src/port/pgstrcasecmp.c
                                 24                 :                :  *
                                 25                 :                :  *-------------------------------------------------------------------------
                                 26                 :                :  */
                                 27                 :                : #include "c.h"
                                 28                 :                : 
                                 29                 :                : #include <ctype.h>
                                 30                 :                : 
                                 31                 :                : 
                                 32                 :                : /*
                                 33                 :                :  * Case-independent comparison of two null-terminated strings.
                                 34                 :                :  */
                                 35                 :                : int
 7843 tgl@sss.pgh.pa.us          36                 :CBC    11007735 : pg_strcasecmp(const char *s1, const char *s2)
                                 37                 :                : {
                                 38                 :                :     for (;;)
                                 39                 :        5076028 :     {
 7729 bruce@momjian.us           40                 :       16083763 :         unsigned char ch1 = (unsigned char) *s1++;
                                 41                 :       16083763 :         unsigned char ch2 = (unsigned char) *s2++;
                                 42                 :                : 
 7843 tgl@sss.pgh.pa.us          43         [ +  + ]:       16083763 :         if (ch1 != ch2)
                                 44                 :                :         {
                                 45   [ +  +  +  + ]:       10967363 :             if (ch1 >= 'A' && ch1 <= 'Z')
                                 46                 :        4422312 :                 ch1 += 'a' - 'A';
 7246 bruce@momjian.us           47   [ +  +  -  + ]:        6545051 :             else if (IS_HIGHBIT_SET(ch1) && isupper(ch1))
 7843 tgl@sss.pgh.pa.us          48                 :UBC           0 :                 ch1 = tolower(ch1);
                                 49                 :                : 
 7843 tgl@sss.pgh.pa.us          50   [ +  +  +  + ]:CBC    10967363 :             if (ch2 >= 'A' && ch2 <= 'Z')
                                 51                 :        2792176 :                 ch2 += 'a' - 'A';
 7246 bruce@momjian.us           52   [ -  +  -  - ]:        8175187 :             else if (IS_HIGHBIT_SET(ch2) && isupper(ch2))
 7843 tgl@sss.pgh.pa.us          53                 :UBC           0 :                 ch2 = tolower(ch2);
                                 54                 :                : 
 7843 tgl@sss.pgh.pa.us          55         [ +  + ]:CBC    10967363 :             if (ch1 != ch2)
                                 56                 :        9991869 :                 return (int) ch1 - (int) ch2;
                                 57                 :                :         }
                                 58         [ +  + ]:        6091894 :         if (ch1 == 0)
                                 59                 :        1015866 :             break;
                                 60                 :                :     }
                                 61                 :        1015866 :     return 0;
                                 62                 :                : }
                                 63                 :                : 
                                 64                 :                : /*
                                 65                 :                :  * Case-independent comparison of two not-necessarily-null-terminated strings.
                                 66                 :                :  * At most n bytes will be examined from each string.
                                 67                 :                :  */
                                 68                 :                : int
                                 69                 :        5443640 : pg_strncasecmp(const char *s1, const char *s2, size_t n)
                                 70                 :                : {
                                 71         [ +  + ]:        7860208 :     while (n-- > 0)
                                 72                 :                :     {
 7729 bruce@momjian.us           73                 :        6074216 :         unsigned char ch1 = (unsigned char) *s1++;
                                 74                 :        6074216 :         unsigned char ch2 = (unsigned char) *s2++;
                                 75                 :                : 
 7843 tgl@sss.pgh.pa.us          76         [ +  + ]:        6074216 :         if (ch1 != ch2)
                                 77                 :                :         {
                                 78   [ +  +  +  + ]:        3746280 :             if (ch1 >= 'A' && ch1 <= 'Z')
                                 79                 :        2631136 :                 ch1 += 'a' - 'A';
 7246 bruce@momjian.us           80   [ -  +  -  - ]:        1115144 :             else if (IS_HIGHBIT_SET(ch1) && isupper(ch1))
 7843 tgl@sss.pgh.pa.us          81                 :UBC           0 :                 ch1 = tolower(ch1);
                                 82                 :                : 
 7843 tgl@sss.pgh.pa.us          83   [ +  +  +  + ]:CBC     3746280 :             if (ch2 >= 'A' && ch2 <= 'Z')
                                 84                 :         149446 :                 ch2 += 'a' - 'A';
 7246 bruce@momjian.us           85   [ -  +  -  - ]:        3596834 :             else if (IS_HIGHBIT_SET(ch2) && isupper(ch2))
 7843 tgl@sss.pgh.pa.us          86                 :UBC           0 :                 ch2 = tolower(ch2);
                                 87                 :                : 
 7843 tgl@sss.pgh.pa.us          88         [ +  + ]:CBC     3746280 :             if (ch1 != ch2)
                                 89                 :        3657648 :                 return (int) ch1 - (int) ch2;
                                 90                 :                :         }
                                 91         [ -  + ]:        2416568 :         if (ch1 == 0)
 7843 tgl@sss.pgh.pa.us          92                 :UBC           0 :             break;
                                 93                 :                :     }
 7843 tgl@sss.pgh.pa.us          94                 :CBC     1785992 :     return 0;
                                 95                 :                : }
                                 96                 :                : 
                                 97                 :                : /*
                                 98                 :                :  * Fold a character to upper case.
                                 99                 :                :  *
                                100                 :                :  * Unlike some versions of toupper(), this is safe to apply to characters
                                101                 :                :  * that aren't lower case letters.  Note however that the whole thing is
                                102                 :                :  * a bit bogus for multibyte character sets.
                                103                 :                :  */
                                104                 :                : unsigned char
                                105                 :         161823 : pg_toupper(unsigned char ch)
                                106                 :                : {
                                107   [ +  +  +  - ]:         161823 :     if (ch >= 'a' && ch <= 'z')
                                108                 :          95822 :         ch += 'A' - 'a';
 7246 bruce@momjian.us          109   [ -  +  -  - ]:          66001 :     else if (IS_HIGHBIT_SET(ch) && islower(ch))
 7843 tgl@sss.pgh.pa.us         110                 :UBC           0 :         ch = toupper(ch);
 7843 tgl@sss.pgh.pa.us         111                 :CBC      161823 :     return ch;
                                112                 :                : }
                                113                 :                : 
                                114                 :                : /*
                                115                 :                :  * Fold a character to lower case.
                                116                 :                :  *
                                117                 :                :  * Unlike some versions of tolower(), this is safe to apply to characters
                                118                 :                :  * that aren't upper case letters.  Note however that the whole thing is
                                119                 :                :  * a bit bogus for multibyte character sets.
                                120                 :                :  */
                                121                 :                : unsigned char
                                122                 :        7209162 : pg_tolower(unsigned char ch)
                                123                 :                : {
                                124   [ +  +  +  + ]:        7209162 :     if (ch >= 'A' && ch <= 'Z')
                                125                 :        4612505 :         ch += 'a' - 'A';
 7246 bruce@momjian.us          126   [ -  +  -  - ]:        2596657 :     else if (IS_HIGHBIT_SET(ch) && isupper(ch))
 7843 tgl@sss.pgh.pa.us         127                 :UBC           0 :         ch = tolower(ch);
 7843 tgl@sss.pgh.pa.us         128                 :CBC     7209162 :     return ch;
                                129                 :                : }
                                130                 :                : 
                                131                 :                : /*
                                132                 :                :  * Fold a character to upper case, following C/POSIX locale rules.
                                133                 :                :  */
                                134                 :                : unsigned char
 5335                           135                 :         166959 : pg_ascii_toupper(unsigned char ch)
                                136                 :                : {
                                137   [ +  +  +  + ]:         166959 :     if (ch >= 'a' && ch <= 'z')
                                138                 :          57334 :         ch += 'A' - 'a';
                                139                 :         166959 :     return ch;
                                140                 :                : }
                                141                 :                : 
                                142                 :                : /*
                                143                 :                :  * Fold a character to lower case, following C/POSIX locale rules.
                                144                 :                :  */
                                145                 :                : unsigned char
                                146                 :          32647 : pg_ascii_tolower(unsigned char ch)
                                147                 :                : {
                                148   [ +  +  +  + ]:          32647 :     if (ch >= 'A' && ch <= 'Z')
                                149                 :           3458 :         ch += 'a' - 'A';
                                150                 :          32647 :     return ch;
                                151                 :                : }
        

Generated by: LCOV version 2.4-beta