History

Change nullptr return value in debugger to an exception. Pull out the split() function from the debugger and push it into utils.h.

arr committed 9 years ago

Commit 2e5c41c1 parent 551c5002 files · +40 −40Browse files

Showing the changes to src/include (1 of 2 files). Show all

Unified · Split

src/include/utils.h+37−3
@@ -9,28 +9,62 @@ · 8 unmodified lines
9 9
10#include <cstdint>10#include <cstdint>
11#include <type_traits>11#include <type_traits>
12#include <string>
13#include <cstring>
14#include <vector>
12 15
13namespace disvm16namespace disvm
14{17{
15 namespace util18 namespace util
16 {19 {
17 template<typename Flags>20 template<typename Flags>
18 inline bool has_flag(const Flags flags, const Flags flag)21 bool has_flag(const Flags flags, const Flags flag)
19 {22 {
20 return (static_cast<std::underlying_type_t<Flags>>(flags) & static_cast<std::underlying_type_t<Flags>>(flag)) != 0;23 return (static_cast<std::underlying_type_t<Flags>>(flags) & static_cast<std::underlying_type_t<Flags>>(flag)) != 0;
21 }24 }
22 25
23 template <typename T1, typename T2>26 template <typename T1, typename T2>
24 inline bool are_equal(const T1 &l, const T2 &r)27 bool are_equal(const T1 &l, const T2 &r)
25 {28 {
26 return (l == r);29 return (l == r);
27 }30 }
28 31
29 template <typename T1, typename T2, typename... Others>32 template <typename T1, typename T2, typename... Others>
30 inline bool are_equal(const T1 &l, const T2 &r, const Others &... args)33 bool are_equal(const T1 &l, const T2 &r, const Others &... args)
31 {34 {
32 return (l == r) && are_equal(r, args...);35 return (l == r) && are_equal(r, args...);
33 }36 }
37
38 // split the string using the delimiters contained in the supplied string
39 inline std::vector<std::string> split(const std::string &str, const char *delims)
40 {
41 auto split_string = std::vector<std::string>{};
42
43 auto curr = str.begin();
44 auto end = str.cend();
45 while (curr != end)
46 {
47 auto curr_begin = curr;
48
49 while (curr != end && (nullptr == std::strchr(delims, *curr)))
50 ++curr;
51
52 if (curr_begin != curr)
53 split_string.push_back(std::move(std::string{ curr_begin, curr }));
54
55 if (curr == end)
56 break;
57
58 ++curr;
59 }
60
61 return split_string;
62 }
63
64 inline std::vector<std::string> split(const std::string &str)
65 {
66 return split(str, " ");
67 }
34 }68 }
35}69}
36 70