LCOV - differential code coverage report
Current view: top level - src/backend/parser - scansup.c (source / functions) Coverage Total Hit UNC UBC GNC CBC DUB DCB
Current: 0e5ff9b9b45a657aea12440478dc002e9b01f138 vs 0123ce131fca454009439dfa3b2266d1d40737d7 Lines: 100.0 % 25 25 6 19 1 11
Current Date: 2026-03-14 14:10:32 -0400 Functions: 100.0 % 4 4 1 3
Baseline: lcov-20260315-024220-baseline Branches: 88.5 % 26 23 2 1 6 17 3 13
Baseline Date: 2026-03-14 15:27:56 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 100.0 % 6 6 6
(360..) days: 100.0 % 19 19 19
Function coverage date bins:
(360..) days: 100.0 % 4 4 1 3
Branch coverage date bins:
(30,360] days: 75.0 % 8 6 2 6
(360..) days: 94.4 % 18 17 1 17

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * scansup.c
                                  4                 :                :  *    scanner support routines used by the core lexer
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
                                  7                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :                :  *
                                  9                 :                :  *
                                 10                 :                :  * IDENTIFICATION
                                 11                 :                :  *    src/backend/parser/scansup.c
                                 12                 :                :  *
                                 13                 :                :  *-------------------------------------------------------------------------
                                 14                 :                :  */
                                 15                 :                : #include "postgres.h"
                                 16                 :                : 
                                 17                 :                : #include <ctype.h>
                                 18                 :                : 
                                 19                 :                : #include "mb/pg_wchar.h"
                                 20                 :                : #include "parser/scansup.h"
                                 21                 :                : #include "utils/pg_locale.h"
                                 22                 :                : 
                                 23                 :                : 
                                 24                 :                : /*
                                 25                 :                :  * downcase_truncate_identifier() --- do appropriate downcasing and
                                 26                 :                :  * truncation of an unquoted identifier.  Optionally warn of truncation.
                                 27                 :                :  *
                                 28                 :                :  * Returns a palloc'd string containing the adjusted identifier.
                                 29                 :                :  *
                                 30                 :                :  * Note: in some usages the passed string is not null-terminated.
                                 31                 :                :  *
                                 32                 :                :  * Note: the API of this function is designed to allow for downcasing
                                 33                 :                :  * transformations that increase the string length, but we don't yet
                                 34                 :                :  * support that.  If you want to implement it, you'll need to fix
                                 35                 :                :  * SplitIdentifierString() in utils/adt/varlena.c.
                                 36                 :                :  */
                                 37                 :                : char *
 8058 tgl@sss.pgh.pa.us          38                 :CBC     3471381 : downcase_truncate_identifier(const char *ident, int len, bool warn)
                                 39                 :                : {
 3649 teodor@sigaev.ru           40                 :        3471381 :     return downcase_identifier(ident, len, warn, true);
                                 41                 :                : }
                                 42                 :                : 
                                 43                 :                : /*
                                 44                 :                :  * a workhorse for downcase_truncate_identifier
                                 45                 :                :  */
                                 46                 :                : char *
                                 47                 :        3472107 : downcase_identifier(const char *ident, int len, bool warn, bool truncate)
                                 48                 :                : {
                                 49                 :                :     char       *result;
                                 50                 :                :     size_t      needed pg_attribute_unused();
                                 51                 :                : 
                                 52                 :                :     /*
                                 53                 :                :      * Preserves string length.
                                 54                 :                :      *
                                 55                 :                :      * NB: if we decide to support Unicode-aware identifier case folding, then
                                 56                 :                :      * we need to account for a change in string length.
                                 57                 :                :      */
   89 jdavis@postgresql.or       58                 :GNC     3472107 :     result = palloc(len + 1);
                                 59                 :                : 
                                 60                 :        3472107 :     needed = pg_downcase_ident(result, len + 1, ident, len);
                                 61         [ -  + ]:        3472107 :     Assert(needed == len);
                                 62         [ -  + ]:        3472107 :     Assert(result[len] == '\0');
                                 63                 :                : 
                                 64   [ +  +  +  + ]:        3472107 :     if (len >= NAMEDATALEN && truncate)
                                 65                 :              6 :         truncate_identifier(result, len, warn);
                                 66                 :                : 
 8058 tgl@sss.pgh.pa.us          67                 :CBC     3472107 :     return result;
                                 68                 :                : }
                                 69                 :                : 
                                 70                 :                : 
                                 71                 :                : /*
                                 72                 :                :  * truncate_identifier() --- truncate an identifier to NAMEDATALEN-1 bytes.
                                 73                 :                :  *
                                 74                 :                :  * The given string is modified in-place, if necessary.  A warning is
                                 75                 :                :  * issued if requested.
                                 76                 :                :  *
                                 77                 :                :  * We require the caller to pass in the string length since this saves a
                                 78                 :                :  * strlen() call in some common usages.
                                 79                 :                :  */
                                 80                 :                : void
                                 81                 :         214336 : truncate_identifier(char *ident, int len, bool warn)
                                 82                 :                : {
                                 83         [ +  + ]:         214336 :     if (len >= NAMEDATALEN)
                                 84                 :                :     {
 7868 bruce@momjian.us           85                 :             17 :         len = pg_mbcliplen(ident, len, NAMEDATALEN - 1);
 8058 tgl@sss.pgh.pa.us          86         [ +  + ]:             17 :         if (warn)
                                 87         [ +  - ]:              7 :             ereport(NOTICE,
                                 88                 :                :                     (errcode(ERRCODE_NAME_TOO_LONG),
                                 89                 :                :                      errmsg("identifier \"%s\" will be truncated to \"%.*s\"",
                                 90                 :                :                             ident, len, ident)));
                                 91                 :             17 :         ident[len] = '\0';
                                 92                 :                :     }
                                 93                 :         214336 : }
                                 94                 :                : 
                                 95                 :                : /*
                                 96                 :                :  * scanner_isspace() --- return true if flex scanner considers char whitespace
                                 97                 :                :  *
                                 98                 :                :  * This should be used instead of the potentially locale-dependent isspace()
                                 99                 :                :  * function when it's important to match the lexer's behavior.
                                100                 :                :  *
                                101                 :                :  * In principle we might need similar functions for isalnum etc, but for the
                                102                 :                :  * moment only isspace seems needed.
                                103                 :                :  */
                                104                 :                : bool
 7114                           105                 :       19339564 : scanner_isspace(char ch)
                                106                 :                : {
                                107                 :                :     /* This must match scan.l's list of {space} characters */
                                108   [ +  +  +  + ]:       19339564 :     if (ch == ' ' ||
                                109         [ +  + ]:       19200947 :         ch == '\t' ||
                                110         [ +  + ]:       19200741 :         ch == '\n' ||
                                111         [ +  + ]:       19200732 :         ch == '\r' ||
  983 michael@paquier.xyz       112         [ +  + ]:       19200729 :         ch == '\v' ||
                                113                 :                :         ch == '\f')
 7114 tgl@sss.pgh.pa.us         114                 :         138838 :         return true;
                                115                 :       19200726 :     return false;
                                116                 :                : }
        

Generated by: LCOV version 2.4-beta