MCPcopy Create free account
hub / github.com/N64Recomp/N64Recomp / validate_dependency_string

Function validate_dependency_string

RecompModTool/main.cpp:122–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122static bool validate_dependency_string(const std::string& val, size_t& name_length, bool& has_label) {
123 std::string ret;
124 size_t name_length_temp;
125
126 // Don't allow an empty dependency name.
127 if (val.size() == 0) {
128 return false;
129 }
130 bool validated_name;
131 bool validated_version;
132
133 // Check if there's a version number specified.
134 size_t colon_pos = val.find(':');
135 if (colon_pos == std::string::npos) {
136 // No version present, so just validate the dependency's id.
137
138 validated_name = N64Recomp::validate_mod_id(std::string_view{val});
139 name_length_temp = val.size();
140 validated_version = true;
141 has_label = false;
142 }
143 else {
144 // Version present, validate it.
145
146 // Don't allow an empty dependency name after accounting for the colon.
147 if (colon_pos == 0) {
148 return false;
149 }
150
151 name_length_temp = colon_pos;
152
153 // Validate the dependency's id and version.
154 validated_name = N64Recomp::validate_mod_id(std::string_view{val.begin(), val.begin() + colon_pos});
155 validated_version = validate_version_string(std::string_view{val.begin() + colon_pos + 1, val.end()}, has_label);
156 }
157
158 if (validated_name && validated_version) {
159 name_length = name_length_temp;
160 return true;
161 }
162
163 return false;
164}
165
166template <typename T>
167static T read_toml_value(const toml::table& data, std::string_view key, bool required) {

Callers 1

Calls 2

validate_mod_idFunction · 0.85
validate_version_stringFunction · 0.85

Tested by

no test coverage detected