@@ -32,6 +32,7 @@ SOFTWARE.
32
32
#include < array>
33
33
#include < string.h>
34
34
#include " yasio/yasio.hpp"
35
+ #include " yasio/split.hpp"
35
36
36
37
#if defined(_WINDLL)
37
38
# define YASIO_NI_API __declspec (dllexport)
@@ -45,25 +46,6 @@ using namespace yasio;
45
46
46
47
namespace
47
48
{
48
- template <typename _CStr, typename _Fn>
49
- inline void fast_split (_CStr s, size_t slen, typename std::remove_pointer<_CStr>::type delim, _Fn func)
50
- {
51
- auto _Start = s; // the start of every string
52
- auto _Ptr = s; // source string iterator
53
- auto _End = s + slen;
54
- while ((_Ptr = strchr (_Ptr, delim)))
55
- {
56
- if (_Start < _Ptr)
57
- if (func (_Start, _Ptr))
58
- return ;
59
- _Start = _Ptr + 1 ;
60
- ++_Ptr;
61
- }
62
- if (_Start < _End)
63
- {
64
- func (_Start, _End);
65
- }
66
- }
67
49
inline int svtoi (cxx17::string_view& sv) { return !sv.empty () ? atoi (sv.data ()) : 0 ; }
68
50
inline const char * svtoa (cxx17::string_view& sv) { return !sv.empty () ? sv.data () : " " ; }
69
51
} // namespace
@@ -154,7 +136,7 @@ YASIO_NI_API void yasio_set_resolv_fn(void* service_ptr, int(YASIO_INTEROP_DECL*
154
136
YASIO_NI_API void yasio_set_option (void * service_ptr, int opt, const char * pszArgs)
155
137
{
156
138
auto service = reinterpret_cast <io_service*>(service_ptr);
157
- if (!service)
139
+ if (!service || !pszArgs || !*pszArgs )
158
140
return ;
159
141
160
142
// process one arg
@@ -174,10 +156,10 @@ YASIO_NI_API void yasio_set_option(void* service_ptr, int opt, const char* pszAr
174
156
std::string strArgs = pszArgs;
175
157
std::array<cxx17::string_view, YASIO_MAX_OPTION_ARGC> args;
176
158
int argc = 0 ;
177
- fast_split (&strArgs.front (), strArgs. length (), ' ;' , [&](char * s, char * e) {
178
- *e = ' \0 ' ; // to c style string
179
- args[argc] = cxx17::string_view (s, e - s);
180
- return (++ argc == YASIO_MAX_OPTION_ARGC);
159
+ yasio::split_if (&strArgs.front (), ' ;' , [&](char * s, char * e) {
160
+ *e = ' \0 ' ; // to c style string
161
+ args[argc++ ] = cxx17::string_view (s, e - s);
162
+ return (argc < YASIO_MAX_OPTION_ARGC);
181
163
});
182
164
183
165
switch (opt)
0 commit comments