23 std::ostream& operator<<(std::ostream& os, const v_array<substring>& ss);
26 template <
typename ContainerT>
33 if (*s.
begin == delim)
35 if (allow_empty || (s.
begin != last))
43 if (allow_empty || (s.
begin != last))
46 ret.push_back(final_substring);
63 while (start != max && *start != v) start++;
76 typedef example& (*example_factory_t)(
void*);
88 inline float parseFloat(
char* p,
char** end,
char* endLine =
nullptr)
91 bool endLine_is_null = endLine ==
nullptr;
99 while ((*p ==
' ') && (endLine_is_null || p < endLine)) p++;
108 while (*p >=
'0' && *p <=
'9' && (endLine_is_null || p < endLine)) acc = acc * 10 + *p++ -
'0';
113 while (*(++p) >=
'0' && *p <=
'9' && (endLine_is_null || p < endLine))
117 acc = acc * 10 + (*p -
'0');
124 if ((*p ==
'e' || *p ==
'E') && (endLine_is_null || p < endLine))
128 if (*p ==
'-' && (endLine_is_null || p < endLine))
133 while (*p >=
'0' && *p <=
'9' && (endLine_is_null || p < endLine)) exp_acc = exp_acc * 10 + *p++ -
'0';
136 if (*p ==
' ' || *p ==
'\n' || *p ==
'\t' || p == endLine)
138 acc *=
powf(10, (
float)(exp_acc - num_dec));
143 return (
float)strtod(start, end);
148 char* endptr = s.
end;
150 if ((endptr == s.
begin && s.
begin != s.
end) || std::isnan(f))
152 std::cout <<
"warning: " << std::string(s.
begin, s.
end - s.
begin).c_str()
153 <<
" is not a good float, replacing with 0" << std::endl;
161 char* endptr = s.
end;
162 int i = strtol(s.
begin, &endptr, 10);
165 std::cout <<
"warning: " << std::string(s.
begin, s.
end - s.
begin).c_str() <<
" is not a good int, replacing with 0" bool substring_equal(const substring &a, const substring &b)
int int_of_substring(substring s)
std::vector< substring > escaped_tokenize(char delim, substring s, bool allow_empty=false)
size_t substring_len(substring &s)
bool operator==(const substring &ss, const char *str)
hash_func_t getHasher(const std::string &s)
bool operator!=(const substring &ss, const char *str)
float float_of_substring(substring s)
char * safe_index(char *start, char v, char *max)
void tokenize(char delim, substring s, ContainerT &ret, bool allow_empty=false)
std::ostream & operator<<(std::ostream &os, const substring &ss)
void print_substring(substring s)
float parseFloat(char *p, char **end, char *endLine=nullptr)
uint64_t(* hash_func_t)(substring, uint64_t)