#pragma once #include namespace ss { struct none {}; using string_range = std::pair; using split_data = std::vector; constexpr inline auto default_delimiter = ","; template inline void assert_string_error_defined() { static_assert(StringError, "'string_error' needs to be enabled to use 'error_msg'"); } #if __unix__ inline ssize_t get_line(char** lineptr, size_t* n, FILE* stream) { return getline(lineptr, n, stream); } #else #include using ssize_t = int64_t; inline ssize_t get_line(char** lineptr, size_t* n, FILE* stream) { size_t pos; int c; if (lineptr == nullptr || stream == nullptr || n == nullptr) { errno = EINVAL; return -1; } c = getc(stream); if (c == EOF) { return -1; } if (*lineptr == nullptr) { *lineptr = static_cast(malloc(128)); if (*lineptr == nullptr) { return -1; } *n = 128; } pos = 0; while (c != EOF) { if (pos + 1 >= *n) { size_t new_size = *n + (*n >> 2); if (new_size < 128) { new_size = 128; } char* new_ptr = static_cast( realloc(static_cast(*lineptr), new_size)); if (new_ptr == nullptr) { return -1; } *n = new_size; *lineptr = new_ptr; } (*lineptr)[pos++] = c; if (c == '\n') { break; } c = getc(stream); } (*lineptr)[pos] = '\0'; return pos; } #endif } /* ss */