ewmscp  ..
Private Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
escapismUrl Class Reference
Inheritance diagram for escapismUrl:
[legend]
Collaboration diagram for escapismUrl:
[legend]

Private Member Functions

virtual bool unencoded (char c) const
 
void escape (const std::string &unEscaped, std::string &escaped) const override
 
void deEscape (const std::string &escaped, std::string &unEscaped) const override
 

Static Private Member Functions

static charCodingBitPatternType initCodeList ()
 

Static Private Attributes

static escapismFactoryClassTemplate< escapismUrlfactory
 

Additional Inherited Members

- Static Public Member Functions inherited from escapism
static const escapismnewEscaper (const std::string &name)
 
static void addAllowedNamesToOption (options::single< std::string > &option)
 
static options::single< std::string > * newEscaperOption (const std::string &name, const std::string &description, const std::string &defaultValue="Url")
 

Detailed Description

Definition at line 47 of file escapism.cpp.

Member Function Documentation

◆ deEscape()

void escapismUrl::deEscape ( const std::string &  escaped,
std::string &  unEscaped 
) const
inlineoverrideprivatevirtual

Implements escapism.

Definition at line 74 of file escapism.cpp.

74  {
75  unEscaped.reserve(escaped.size()); // de-Escaped is always smaller, so this always fits and saves time
76  std::remove_reference<decltype(unEscaped)>::type::value_type code;
77  enum {normal, firstNibble, secondNibble} state = normal;
78  for (auto c : escaped) {
79  if (state == normal) {
80  if (c == '%') {
81  state = firstNibble;
82  continue;
83  }
84  unEscaped.push_back(c);
85  } else {
86  decltype(code) nibble;
87  if (std::isdigit(c)) {
88  nibble = c - '0';
89  } else {
90  c = std::toupper(c);
91  if ('A' <= c && c <= 'F') {
92  nibble = c - 'A' + 10;
93  } else {
94  throw std::invalid_argument("bad encoding");
95  }
96  }
97  if (state == firstNibble) {
98  code = nibble << 4;
99  state = secondNibble;
100  continue;
101  } else {
102  code |= nibble;
103  unEscaped.push_back(code);
104  state = normal;
105  continue;
106  }
107  }
108  }
109 
110  if (state != normal) {
111  throw std::invalid_argument("bad encoding");
112  }
113  }

◆ escape()

void escapismUrl::escape ( const std::string &  unEscaped,
std::string &  escaped 
) const
inlineoverrideprivatevirtual

Implements escapism.

Definition at line 61 of file escapism.cpp.

61  {
62  for (auto c : unEscaped) {
63  if (unencoded(c)) {
64  escaped.push_back(c);
65  } else {
66  static const char hexEncode[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
67  escaped.push_back('%');
68  // array indices are safe due to & 0x0f,
69  escaped.push_back(hexEncode[ (c >> 4) & 0x0F ]); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
70  escaped.push_back(hexEncode[ c & 0x0F ]); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
71  }
72  }
73  }

References unencoded().

Here is the call graph for this function:

◆ initCodeList()

static charCodingBitPatternType escapismUrl::initCodeList ( )
inlinestaticprivate

Definition at line 49 of file escapism.cpp.

49  {
50  charCodingBitPatternType codingPattern = {{0ull, 0ull, 0ull, 0ull}};
51  const char* ueChars = "0123456789.-~_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
52  for (const char *c = ueChars; *c; c++) {
54  }
55  return codingPattern;
56  }

References escapism::charCodingBitPatternType::bits, escapism::charCodingBitPatternType::index(), and escapism::charCodingBitPatternType::mask().

Referenced by unencoded().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unencoded()

virtual bool escapismUrl::unencoded ( char  c) const
inlineprivatevirtual

Reimplemented in escapismUrlsoft.

Definition at line 57 of file escapism.cpp.

57  {
58  static charCodingBitPatternType codingPattern = initCodeList();
59  return (codingPattern.bits[charCodingBitPatternType::index(c)] & charCodingBitPatternType::mask(c)) != 0ull;
60  }

References escapism::charCodingBitPatternType::bits, escapism::charCodingBitPatternType::index(), initCodeList(), and escapism::charCodingBitPatternType::mask().

Referenced by escape().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ factory

escapismFactoryClassTemplate<escapismUrl> escapismUrl::factory
staticprivate

Definition at line 48 of file escapism.cpp.


The documentation for this class was generated from the following file:
escapismUrl::initCodeList
static charCodingBitPatternType initCodeList()
Definition: escapism.cpp:49
escapism::charCodingBitPatternType::mask
static std::uint64_t mask(char c)
Definition: escapism.h:14
escapismUrl::unencoded
virtual bool unencoded(char c) const
Definition: escapism.cpp:57
escapism::charCodingBitPatternType::index
static int index(char c)
Definition: escapism.h:11