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

Method Create

src/benchmark/Performance.cpp:320–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318 }
319
320 std::string Create(const std::string& source_config_path,
321 const char* target_type,
322 const std::string& suffix) {
323 const std::string content = ReadFile(source_config_path);
324 JSONDocument document;
325 document.Parse(content.c_str());
326 if (document.HasParseError() || !document.IsObject()) {
327 throw InvalidFormat("Error parsing benchmark config JSON");
328 }
329
330 RewriteConfigToText(document, document.GetAllocator(), target_type);
331 RewriteSegmentationResourcesToAbsolute(document, document.GetAllocator(),
332 GetParentDirectory(source_config_path));
333
334 rapidjson::StringBuffer buffer;
335 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
336 document.Accept(writer);
337
338 const std::string temp_path = BuildTempPath(source_config_path, suffix);
339 std::ofstream stream(temp_path.c_str(), std::ios::binary);
340 stream << buffer.GetString();
341 stream.close();
342 if (!stream) {
343 throw FileNotWritable(temp_path);
344 }
345
346 paths_.push_back(temp_path);
347 return temp_path;
348 }
349
350private:
351 std::string BuildTempPath(const std::string& source_config_path,

Callers

nothing calls this directly

Calls 8

RewriteConfigToTextFunction · 0.85
GetStringMethod · 0.80
ReadFileFunction · 0.70
GetParentDirectoryFunction · 0.70
ParseMethod · 0.45
HasParseErrorMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected