Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
| static const char *drop_plus(const char *p, const char *end) | static const char *drop_plus(const char *p, const char *end) | ||||
| { | { | ||||
| if (p < end && *p == '+') { | if (p < end && *p == '+') { | ||||
| ++p; | ++p; | ||||
| } | } | ||||
| return p; | return p; | ||||
| } | } | ||||
| const char *parse_float( | const char *parse_float(const char *p, | ||||
| const char *p, const char *end, float fallback, float &dst, bool skip_space) | const char *end, | ||||
| float fallback, | |||||
| float &dst, | |||||
| bool skip_space, | |||||
| bool require_trailing_space) | |||||
| { | { | ||||
| if (skip_space) { | if (skip_space) { | ||||
| p = drop_whitespace(p, end); | p = drop_whitespace(p, end); | ||||
| } | } | ||||
| p = drop_plus(p, end); | p = drop_plus(p, end); | ||||
| fast_float::from_chars_result res = fast_float::from_chars(p, 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; | ||||
| } | } | ||||
| else if (require_trailing_space && res.ptr < end && !is_whitespace(*res.ptr)) { | |||||
| /* If there are trailing non-space characters, do not eat up the number. */ | |||||
| dst = fallback; | |||||
| return p; | |||||
| } | |||||
| return res.ptr; | return res.ptr; | ||||
| } | } | ||||
| const char *parse_floats(const char *p, const char *end, float fallback, float *dst, int count) | const char *parse_floats(const char *p, | ||||
| const char *end, | |||||
| float fallback, | |||||
| float *dst, | |||||
| int count, | |||||
| bool require_trailing_space) | |||||
| { | { | ||||
| for (int i = 0; i < count; ++i) { | for (int i = 0; i < count; ++i) { | ||||
| p = parse_float(p, end, fallback, dst[i]); | p = parse_float(p, end, fallback, dst[i], true, require_trailing_space); | ||||
| } | } | ||||
| return p; | return p; | ||||
| } | } | ||||
| const char *parse_int(const char *p, const char *end, 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) { | ||||
| p = drop_whitespace(p, end); | p = drop_whitespace(p, end); | ||||
| Show All 10 Lines | |||||