Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc
| Context not available. | |||||
| return c <= ' ' || c == '\\'; | return c <= ' ' || c == '\\'; | ||||
| } | } | ||||
| StringRef drop_whitespace(StringRef str) | const char *drop_whitespace(const char *p, const char *end) | ||||
| { | { | ||||
| while (!str.is_empty() && is_whitespace(str[0])) { | while (p < end && is_whitespace(*p)) { | ||||
| str = str.drop_prefix(1); | ++p; | ||||
| } | } | ||||
| return str; | return p; | ||||
| } | } | ||||
| StringRef drop_non_whitespace(StringRef str) | const char *drop_non_whitespace(const char *p, const char *end) | ||||
| { | { | ||||
| while (!str.is_empty() && !is_whitespace(str[0])) { | while (p < end && !is_whitespace(*p)) { | ||||
| str = str.drop_prefix(1); | ++p; | ||||
| } | } | ||||
| return str; | return p; | ||||
| } | } | ||||
| static StringRef drop_plus(StringRef str) | static const char *drop_plus(const char *p, const char *end) | ||||
| { | { | ||||
| if (!str.is_empty() && str[0] == '+') { | if (p < end && *p == '+') { | ||||
| str = str.drop_prefix(1); | ++p; | ||||
| } | } | ||||
| return str; | return p; | ||||
| } | } | ||||
| StringRef parse_float(StringRef str, float fallback, float &dst, bool skip_space) | const char *parse_float( | ||||
| const char *p, const char *end, float fallback, float &dst, bool skip_space) | |||||
| { | { | ||||
| if (skip_space) { | if (skip_space) { | ||||
| str = drop_whitespace(str); | p = drop_whitespace(p, end); | ||||
| } | } | ||||
| str = drop_plus(str); | p = drop_plus(p, end); | ||||
| fast_float::from_chars_result res = fast_float::from_chars(str.begin(), str.end(), dst); | fast_float::from_chars_result res = fast_float::from_chars(p, end, dst); | ||||
| if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) { | if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) { | ||||
| dst = fallback; | dst = fallback; | ||||
| } | } | ||||
| return StringRef(res.ptr, str.end()); | return res.ptr; | ||||
| } | } | ||||
| StringRef parse_floats(StringRef str, float fallback, float *dst, int count) | const char *parse_floats(const char *p, const char *end, float fallback, float *dst, int count) | ||||
| { | { | ||||
| for (int i = 0; i < count; ++i) { | for (int i = 0; i < count; ++i) { | ||||
| str = parse_float(str, fallback, dst[i]); | p = parse_float(p, end, fallback, dst[i]); | ||||
| } | } | ||||
| return str; | return p; | ||||
| } | } | ||||
| StringRef parse_int(StringRef str, int fallback, int &dst, bool skip_space) | const char *parse_int(const char *p, const char *end, int fallback, int &dst, bool skip_space) | ||||
| { | { | ||||
| if (skip_space) { | if (skip_space) { | ||||
| str = drop_whitespace(str); | p = drop_whitespace(p, end); | ||||
| } | } | ||||
| str = drop_plus(str); | p = drop_plus(p, end); | ||||
| std::from_chars_result res = std::from_chars(str.begin(), str.end(), dst); | std::from_chars_result res = std::from_chars(p, end, dst); | ||||
| if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) { | if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) { | ||||
| dst = fallback; | dst = fallback; | ||||
| } | } | ||||
| return StringRef(res.ptr, str.end()); | return res.ptr; | ||||
| } | } | ||||
| } // namespace blender::io::obj | } // namespace blender::io::obj | ||||
| Context not available. | |||||