MCPcopy Create free account
hub / github.com/bytedance/sonic-cpp / get_all_jsons

Function get_all_jsons

tests/document_test.cpp:345–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343}
344
345static std::vector<std::string> get_all_jsons(const std::string& dirname) {
346 DIR* dir = opendir(dirname.c_str());
347 std::vector<std::string> jsons;
348 EXPECT_TRUE(dir != nullptr) << "Error open directory: " + dirname;
349 if (nullptr == dir) return jsons;
350 struct dirent* ent = nullptr;
351 while (nullptr != (ent = readdir(dir))) {
352 struct stat st;
353 std::string filename = dirname + ent->d_name;
354 int ret = lstat(filename.c_str(), &st);
355 if (ret == -1) {
356 goto return_label;
357 }
358 if (S_ISDIR(st.st_mode)) {
359 if (ent->d_name[0] == '.') {
360 continue;
361 }
362 auto sub_jsons = get_all_jsons(filename + '/');
363 jsons.insert(jsons.end(), sub_jsons.begin(), sub_jsons.end());
364 } else {
365 auto const pos = filename.find_last_of('.');
366 const auto extension = filename.substr(pos + 1);
367 if (extension == "json") {
368 jsons.push_back(get_json(filename));
369 }
370 }
371 }
372
373return_label:
374 closedir(dir);
375 return jsons;
376}
377
378TYPED_TEST(DocumentTest, ParseFile) {
379 using Document = TypeParam;

Callers 1

TYPED_TESTFunction · 0.85

Calls 1

get_jsonFunction · 0.70

Tested by

no test coverage detected