Replaced VALID_HEX, ISODIGIT & NBSP macros in string.h

- Moved them into modsecurity::utils::string to avoid polluting the
  global namespace.
This commit is contained in:
Eduardo Arias 2024-08-17 00:53:54 +00:00
parent 2f5dac5c4c
commit a6d64bf615
8 changed files with 26 additions and 16 deletions

View File

@ -17,6 +17,7 @@
#include "src/utils/string.h"
using namespace modsecurity::utils::string;
namespace modsecurity::actions::transformations {

View File

@ -17,6 +17,8 @@
#include "src/utils/string.h"
using namespace modsecurity::utils::string;
namespace modsecurity::actions::transformations {

View File

@ -23,6 +23,7 @@
#include "src/compat/msvc.h"
#endif
using namespace modsecurity::utils::string;
namespace modsecurity::actions::transformations {

View File

@ -17,6 +17,7 @@
#include "src/utils/string.h"
using namespace modsecurity::utils::string;
namespace modsecurity::actions::transformations {

View File

@ -19,6 +19,7 @@
#include "src/utils/string.h"
using namespace modsecurity::utils::string;
namespace modsecurity::actions::transformations {

View File

@ -18,6 +18,7 @@
#include "modsecurity/rules_set.h"
#include "src/utils/string.h"
using namespace modsecurity::utils::string;
namespace modsecurity::actions::transformations {

View File

@ -17,9 +17,9 @@
#include "modsecurity/modsecurity.h"
#include "src/utils/string.h"
using namespace modsecurity::utils::string;
namespace modsecurity {
namespace utils {
namespace modsecurity::utils {
bool urldecode_nonstrict_inplace(std::string &val,
@ -112,5 +112,4 @@ std::string uri_decode(const std::string & sSrc) {
}
} // namespace utils
} // namespace modsecurity
} // namespace modsecurity::utils

View File

@ -13,6 +13,9 @@
*
*/
#ifndef SRC_UTILS_STRING_H_
#define SRC_UTILS_STRING_H_
#include <ctime>
#include <string>
#include <cstring>
@ -27,18 +30,21 @@
#include "src/compat/msvc.h"
#endif
#ifndef SRC_UTILS_STRING_H_
#define SRC_UTILS_STRING_H_
namespace modsecurity::utils::string {
#define VALID_HEX(X) (((X >= '0') && (X <= '9')) || \
((X >= 'a') && (X <= 'f')) || ((X >= 'A') && (X <= 'F')))
#define ISODIGIT(X) ((X >= '0') && (X <= '7'))
#define NBSP 160
template<typename CharT>
constexpr bool VALID_HEX(CharT X) {
return ((X >= '0') && (X <= '9'))
|| ((X >= 'a') && (X <= 'f'))
|| ((X >= 'A') && (X <= 'F'));
}
template<typename CharT>
constexpr bool ISODIGIT(CharT X) {
return (X >= '0') && (X <= '7');
}
namespace modsecurity {
namespace utils {
namespace string {
constexpr unsigned char NBSP = 160;
const char HEX2DEC[256] = {
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
@ -271,8 +277,6 @@ inline std::string toupper(std::string str) { // cppcheck-suppress passedByValue
}
} // namespace string
} // namespace utils
} // namespace modsecurity
} // namespace modsecurity::utils::string
#endif // SRC_UTILS_STRING_H_