| 23 | } |
| 24 | |
| 25 | std::pair<int64_t, int64_t> streamfx::util::size_from_string(std::string_view text, bool allowSquare) |
| 26 | { |
| 27 | int64_t width, height; |
| 28 | |
| 29 | const auto* begin = text.data(); |
| 30 | const auto* end = text.data() + text.size() + 1; |
| 31 | char* here = const_cast<char*>(end); |
| 32 | |
| 33 | long long res = strtoll(begin, &here, 0); |
| 34 | if (errno == ERANGE) { |
| 35 | return {0, 0}; |
| 36 | } |
| 37 | width = res; |
| 38 | |
| 39 | while (here != end) { |
| 40 | if (isdigit(*here) || (*here == '-') || (*here == '+')) { |
| 41 | break; |
| 42 | } |
| 43 | here++; |
| 44 | } |
| 45 | if (here == end) { |
| 46 | // Are we allowed to return a square? |
| 47 | if (allowSquare) { |
| 48 | // Yes: Return width,width. |
| 49 | return {width, width}; |
| 50 | } else { |
| 51 | // No: Return width,0. |
| 52 | return {width, 0}; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | res = strtoll(here, nullptr, 0); |
| 57 | if (errno == ERANGE) { |
| 58 | return {width, 0}; |
| 59 | } |
| 60 | height = res; |
| 61 | |
| 62 | return {width, height}; |
| 63 | } |
| 64 | |
| 65 | void* streamfx::util::memory::malloc_aligned(std::size_t align, std::size_t size) |
| 66 | { |