void Write(StringView data) { NEPTOOLS_CHECK(SinkOverflow, offset+buf_put+data.length() <= size, "Sink overflow during write"); auto cp = std::min(data.length(), size_t(buf_size - buf_put)); memcpy(buf+buf_put, data.data(), cp); data.remove_prefix(cp); buf_put += cp; if (!data.empty()) Write_(data); }
inline bool uint_from_string(StringView & i_source, OutBufferTextStream & i_error_buffer, INT_TYPE & o_value) { static_assert(!std::numeric_limits<INT_TYPE>::is_signed, "uint_from_string is for unsigned ints"); i_source.remove_prefix_writespaces(); const bool hex = i_source.remove_prefix_literal("0x") || i_source.remove_prefix_literal("0X"); const char * curr_digit = i_source.data(); const char * const end_of_buffer = curr_digit + i_source.length(); INT_TYPE result = 0; if (hex) { while (curr_digit < end_of_buffer) { if (*curr_digit >= '0' && *curr_digit <= '9') { result *= 16; result += *curr_digit - '0'; } else if (*curr_digit >= 'A' && *curr_digit <= 'F') { result *= 16; result += *curr_digit - 'A'; } else if (*curr_digit >= 'a' && *curr_digit <= 'f') { result *= 16; result += *curr_digit - 'a'; } else { break; } curr_digit++; } } else { while (curr_digit < end_of_buffer) { if (*curr_digit >= '0' && *curr_digit <= '9') { result *= 10; result += *curr_digit - '0'; } else { break; } curr_digit++; } } const size_t accepted_digits = curr_digit - i_source.data(); if (accepted_digits == 0) { i_error_buffer << "missing digits"; } i_source.remove_prefix(accepted_digits); o_value = result; return accepted_digits > 0; }