Skip to content

Commit 02dec8d

Browse files
committed
Update ProcessStringPattern function
1 parent d3eb808 commit 02dec8d

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

include/dynlibutils/module.hpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,20 @@ inline DYNLIB_COMPILE_TIME_EXPR void ProcessStringPattern(const char (&szInput)[
9191

9292
constexpr auto funcIsHexDigit = [](char c) -> bool
9393
{
94-
return ('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f');
94+
return ('0' <= c && c <= '9') ||
95+
('A' <= c && c <= 'F') ||
96+
('a' <= c && c <= 'f');
9597
};
9698

9799
constexpr auto funcHexCharToByte = [](char c) -> std::uint8_t
98100
{
99-
return ('0' <= c && c <= '9') ? c - '0' : ('A' <= c && c <= 'F') ? c - 'A' + 10 : c - 'a' + 10;
101+
if ('0' <= c && c <= '9')
102+
return c - '0';
103+
104+
if ('A' <= c && c <= 'F')
105+
return c - 'A' + 10;
106+
107+
return c - 'a' + 10;
100108
};
101109

102110
constexpr std::size_t nLength = N - 1; // Exclude null-terminated character.
@@ -112,7 +120,7 @@ inline DYNLIB_COMPILE_TIME_EXPR void ProcessStringPattern(const char (&szInput)[
112120
}
113121
else if (c == '?')
114122
{
115-
aBytes[nIndex] = 0;
123+
aBytes[nIndex] = 0x00;
116124
aMask[nIndex] = '?';
117125

118126
n++;
@@ -127,9 +135,11 @@ inline DYNLIB_COMPILE_TIME_EXPR void ProcessStringPattern(const char (&szInput)[
127135
{
128136
if (n + 1 < nLength)
129137
{
130-
if (funcIsHexDigit(szInput[n + 1]))
138+
const char c2 = szInput[n + 1];
139+
140+
if (funcIsHexDigit(c2))
131141
{
132-
aBytes[nIndex] = (funcHexCharToByte(c) << 4) | funcHexCharToByte(szInput[n + 1]);
142+
aBytes[nIndex] = (funcHexCharToByte(c) << 4) | funcHexCharToByte(c2);
133143
aMask[nIndex] = 'x';
134144

135145
n += 2;
@@ -138,17 +148,20 @@ inline DYNLIB_COMPILE_TIME_EXPR void ProcessStringPattern(const char (&szInput)[
138148
}
139149
else
140150
{
141-
static_assert(R"(Invalid character in pattern. Allowed: <space> or pair: "0-9", "a-f", "A-F" or "?")");
151+
n++;
152+
// Invalid character in pattern. Allowed pair: "0-9", "a-f", "A-F".
142153
}
143154
}
144155
else
145156
{
146-
static_assert("Missing second hexadecimal digit in pattern");
157+
n++;
158+
// Missing second hexadecimal digit in pattern.
147159
}
148160
}
149161
else
150162
{
151-
static_assert("Invalid character in pattern");
163+
n++;
164+
// Invalid character in pattern. Allowed <space> or pair: "0-9", "a-f", "A-F" or "?".
152165
}
153166
}
154167
}

0 commit comments

Comments
 (0)