MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / RewriteDictNode

Function RewriteDictNode

src/benchmark/Performance.cpp:207–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207void RewriteDictNode(JSONValue& node, JSONDocument::AllocatorType& allocator,
208 const char* target_type) {
209 if (!node.IsObject()) {
210 return;
211 }
212
213 if (node.HasMember("type") && node["type"].IsString() &&
214 std::string(node["type"].GetString()) == "group" && node.HasMember("dicts") &&
215 node["dicts"].IsArray()) {
216 for (auto& child : node["dicts"].GetArray()) {
217 RewriteDictNode(child, allocator, target_type);
218 }
219 return;
220 }
221
222 if (!node.HasMember("type") || !node["type"].IsString() ||
223 !node.HasMember("file") || !node["file"].IsString()) {
224 return;
225 }
226
227 const std::string type = node["type"].GetString();
228 const std::string file_name = node["file"].GetString();
229 if (type != "ocd2" || !EndsWith(file_name, ".ocd2")) {
230 return;
231 }
232
233 const std::string text_path = ResolveTextDictionaryPath(file_name);
234 node["type"].SetString(target_type, allocator);
235 node["file"].SetString(text_path.c_str(),
236 static_cast<rapidjson::SizeType>(text_path.size()),
237 allocator);
238}
239
240void RewriteConfigToText(JSONValue& node, JSONDocument::AllocatorType& allocator,
241 const char* target_type) {

Callers 1

RewriteConfigToTextFunction · 0.85

Calls 5

HasMemberMethod · 0.80
GetStringMethod · 0.80
EndsWithFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected