Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/source/common/formatter/substitution_formatter.cc
Line
Count
Source
1
#include "source/common/formatter/substitution_formatter.h"
2
3
namespace Envoy {
4
namespace Formatter {
5
6
360k
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
360k
  CONSTRUCT_ON_FIRST_USE(std::regex,
41
360k
                         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
360k
}
56
57
} // namespace Formatter
58
} // namespace Envoy