Skip to content

Commit fa26d1c

Browse files
committed
refactor
1 parent 31f07fc commit fa26d1c

2 files changed

Lines changed: 96 additions & 32 deletions

File tree

.gitignore

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
1-
# Prerequisites
2-
*.d
3-
4-
# Compiled Object files
5-
*.slo
6-
*.lo
1+
build/
2+
build-*/
73
*.o
84
*.obj
9-
10-
# Precompiled Headers
11-
*.gch
12-
*.pch
13-
14-
# Linker files
15-
*.ilk
16-
17-
# Debugger Files
18-
*.pdb
19-
20-
# Compiled Dynamic libraries
21-
*.so
22-
*.dylib
23-
*.dll
24-
25-
# Fortran module files
26-
*.mod
27-
*.smod
28-
29-
# Compiled Static libraries
5+
*.lo
6+
*.slo
307
*.lai
318
*.la
329
*.a
3310
*.lib
34-
35-
# Executables
11+
*.so
12+
*.dylib
13+
*.dll
3614
*.exe
3715
*.out
3816
*.app
39-
40-
# debug information files
17+
*.gch
18+
*.pch
4119
*.dwo
42-
build/
20+
*.d
4321
.vscode/
22+
.idea/
23+
*.swp
24+
*.swo
25+
*.bak
26+
*.tmp
27+
compile_commands.json
28+
CMakeCache.txt
29+
CMakeFiles/
30+
cmake_install.cmake
31+
*.log
32+
vix.log
33+
text.md
4434
cmd.md
35+
text.txt
36+
cmd.txt
37+
scripts/changelog-release.sh
38+
scripts/update_changelog.sh
39+
build-ref/
40+
build-rel/
41+
hello_server
42+
/hello_world/
43+
*.bak
44+
db.sql
45+
revoir.md
46+
main.cpp
47+
.vix-scripts
48+
49+
50+

include/vix/utils/String.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <vector>
2020
#include <algorithm>
2121
#include <cctype>
22+
#include <cstddef>
2223

2324
/**
2425
* @brief Small string helpers (trim, case transform, prefix/suffix checks, split/join).
@@ -286,6 +287,63 @@ namespace vix::utils
286287
return out;
287288
}
288289

290+
inline bool starts_with_icase(std::string_view s, std::string_view prefix)
291+
{
292+
if (s.size() < prefix.size())
293+
return false;
294+
295+
for (std::size_t i = 0; i < prefix.size(); ++i)
296+
{
297+
unsigned char a = static_cast<unsigned char>(s[i]);
298+
unsigned char b = static_cast<unsigned char>(prefix[i]);
299+
300+
if (a >= 'A' && a <= 'Z')
301+
a = static_cast<unsigned char>(a - 'A' + 'a');
302+
if (b >= 'A' && b <= 'Z')
303+
b = static_cast<unsigned char>(b - 'A' + 'a');
304+
305+
if (a != b)
306+
return false;
307+
}
308+
return true;
309+
}
310+
311+
inline std::string extract_boundary(std::string_view ct)
312+
{
313+
// "multipart/form-data; boundary=----WebKitFormBoundaryabc"
314+
auto pos = ct.find("boundary=");
315+
if (pos == std::string_view::npos)
316+
return {};
317+
318+
pos += std::string_view("boundary=").size();
319+
if (pos >= ct.size())
320+
return {};
321+
322+
std::string_view b = ct.substr(pos);
323+
324+
while (!b.empty() && (b.front() == ' ' || b.front() == '\t'))
325+
b.remove_prefix(1);
326+
327+
if (!b.empty() && b.front() == '"')
328+
{
329+
b.remove_prefix(1);
330+
auto endq = b.find('"');
331+
if (endq != std::string_view::npos)
332+
b = b.substr(0, endq);
333+
}
334+
else
335+
{
336+
auto semi = b.find(';');
337+
if (semi != std::string_view::npos)
338+
b = b.substr(0, semi);
339+
}
340+
341+
while (!b.empty() && (b.back() == ' ' || b.back() == '\t'))
342+
b.remove_suffix(1);
343+
344+
return std::string(b);
345+
}
346+
289347
} // namespace vix::utils
290348

291349
#endif // VIX_STRING_HPP

0 commit comments

Comments
 (0)