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

Method FindConfigFile

src/Config.cpp:654–687  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652 }
653
654 std::string FindConfigFile(std::string fileName) {
655 // Working directory
656 if (CanOpenFileUtf8(fileName)) {
657 return fileName;
658 }
659 // Package data directory
660 if (PACKAGE_DATA_DIRECTORY != "") {
661 std::string prefixedFileName = PACKAGE_DATA_DIRECTORY + fileName;
662 if (CanOpenFileUtf8(prefixedFileName)) {
663 return prefixedFileName;
664 }
665 prefixedFileName += ".json";
666 if (CanOpenFileUtf8(prefixedFileName)) {
667 return prefixedFileName;
668 }
669 }
670
671 for (const std::string& dirPath : paths) {
672 std::string path = dirPath + '/' + fileName;
673 if (CanOpenFileUtf8(path)) {
674 return path;
675 }
676 }
677
678 const char* envPath = std::getenv("OPENCC_DATA_DIR");
679 if (envPath != nullptr) {
680 auto path = std::string(envPath) + '/' + fileName;
681 if (CanOpenFileUtf8(path)) {
682 return path;
683 }
684 }
685
686 throw FileNotFound(fileName);
687 }
688};
689
690std::string GetParentDirectory(const std::string& path) {

Callers 1

NewFromFileMethod · 0.80

Calls 1

CanOpenFileUtf8Function · 0.85

Tested by

no test coverage detected