| 1731 | } |
| 1732 | |
| 1733 | CheckedError Parser::ParseEnumFromString(const Type &type, |
| 1734 | std::string *result) { |
| 1735 | const auto base_type = |
| 1736 | type.enum_def ? type.enum_def->underlying_type.base_type : type.base_type; |
| 1737 | if (!IsInteger(base_type)) return Error("not a valid value for this field"); |
| 1738 | uint64_t u64 = 0; |
| 1739 | for (size_t pos = 0; pos != std::string::npos;) { |
| 1740 | const auto delim = attribute_.find_first_of(' ', pos); |
| 1741 | const auto last = (std::string::npos == delim); |
| 1742 | auto word = attribute_.substr(pos, !last ? delim - pos : std::string::npos); |
| 1743 | pos = !last ? delim + 1 : std::string::npos; |
| 1744 | const EnumVal *ev = nullptr; |
| 1745 | if (type.enum_def) { |
| 1746 | ev = type.enum_def->Lookup(word); |
| 1747 | } else { |
| 1748 | auto dot = word.find_first_of('.'); |
| 1749 | if (std::string::npos == dot) |
| 1750 | return Error("enum values need to be qualified by an enum type"); |
| 1751 | auto enum_def_str = word.substr(0, dot); |
| 1752 | const auto enum_def = LookupEnum(enum_def_str); |
| 1753 | if (!enum_def) return Error("unknown enum: " + enum_def_str); |
| 1754 | auto enum_val_str = word.substr(dot + 1); |
| 1755 | ev = enum_def->Lookup(enum_val_str); |
| 1756 | } |
| 1757 | if (!ev) return Error("unknown enum value: " + word); |
| 1758 | u64 |= ev->GetAsUInt64(); |
| 1759 | } |
| 1760 | *result = IsUnsigned(base_type) ? NumToString(u64) |
| 1761 | : NumToString(static_cast<int64_t>(u64)); |
| 1762 | return NoError(); |
| 1763 | } |
| 1764 | |
| 1765 | CheckedError Parser::ParseHash(Value &e, FieldDef *field) { |
| 1766 | FLATBUFFERS_ASSERT(field); |
nothing calls this directly
no test coverage detected