LCOV - code coverage report
Current view: top level - source/common/formatter - substitution_formatter.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 4 4 100.0 %
Date: 2024-01-05 06:35:25 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "source/common/formatter/substitution_formatter.h"
       2             : 
       3             : namespace Envoy {
       4             : namespace Formatter {
       5             : 
       6        4017 : const std::regex& SubstitutionFormatParser::commandWithArgsRegex() {
       7             :   // The following regex is used to check validity of the formatter command and to
       8             :   // extract groups.
       9             :   // The formatter command has the following format:
      10             :   //    % COMMAND(SUBCOMMAND):LENGTH%
      11             :   // % signs at the beginning and end are used by parser to find next COMMAND.
      12             :   // COMMAND must always be present and must consist of characters: "A-Z", "0-9" or "_".
      13             :   // SUBCOMMAND presence depends on the COMMAND. Format is flexible but cannot contain ")".:
      14             :   // - for some commands SUBCOMMAND is not allowed (for example %PROTOCOL%)
      15             :   // - for some commands SUBCOMMAND is required (for example %REQ(:AUTHORITY)%, just %REQ% will
      16             :   // cause error)
      17             :   // - for some commands SUBCOMMAND is optional (for example %START_TIME% and
      18             :   // %START_TIME(%f.%1f.%2f.%3f)% are both correct).
      19             :   // LENGTH presence depends on the command. Some
      20             :   // commands allow LENGTH to be specified, so not. Regex is used to validate the syntax and also
      21             :   // to extract values for COMMAND, SUBCOMMAND and LENGTH.
      22             :   //
      23             :   // Below is explanation of capturing and non-capturing groups. Non-capturing groups are used
      24             :   // to specify that certain part of the formatter command is optional and should contain specific
      25             :   // characters. Capturing groups are used to extract the values when regex is matched against
      26             :   // formatter command string.
      27             :   //
      28             :   // clang-format off
      29             :   // Non-capturing group specifying optional :LENGTH ----------------------
      30             :   //                                                                       |
      31             :   // Non-capturing group specifying optional (SUBCOMMAND)---               |
      32             :   //                                                        |              |
      33             :   // Non-capturing group specifying mandatory COMMAND       |              |
      34             :   //  which uses only A-Z, 0-9 and _ characters             |              |
      35             :   //  Group is used only to specify allowed characters.     |              |
      36             :   //                                      |                 |              |
      37             :   //                                      |                 |              |
      38             :   //                              _________________  _______________  _____________
      39             :   //                              |               |  |             |  |           |
      40        4017 :   CONSTRUCT_ON_FIRST_USE(std::regex,
      41        4017 :                          R"EOF(^%((?:[A-Z]|[0-9]|_)+)(?:\(([^\)]*)\))?(?::([0-9]+))?%)EOF");
      42             :   //                             |__________________|     |______|        |______|
      43             :   //                                      |                   |              |
      44             :   // Capturing group specifying COMMAND --                    |              |
      45             :   // The index of this group is 1.                            |              |
      46             :   //                                                          |              |
      47             :   // Capturing group for SUBCOMMAND. If present, it will -----               |
      48             :   // contain SUBCOMMAND without "(" and ")". The index                       |
      49             :   // of SUBCOMMAND group is 2.                                               |
      50             :   //                                                                         |
      51             :   // Capturing group for LENGTH. If present, it will -------------------------
      52             :   // contain just number without ":". The index of
      53             :   // LENGTH group is 3.
      54             :   // clang-format on
      55        4017 : }
      56             : 
      57             : } // namespace Formatter
      58             : } // namespace Envoy

Generated by: LCOV version 1.15