| 179 | } |
| 180 | |
| 181 | std::string ResolveResourcePath(const std::string& rawPath, |
| 182 | const std::string& configDir) { |
| 183 | if (rawPath.empty()) { |
| 184 | return rawPath; |
| 185 | } |
| 186 | if (IsAbsolutePath(rawPath) && IsReadableFile(rawPath)) { |
| 187 | return rawPath; |
| 188 | } |
| 189 | if (IsReadableFile(rawPath)) { |
| 190 | return rawPath; |
| 191 | } |
| 192 | if (!configDir.empty()) { |
| 193 | const std::string candidate = JoinPath(configDir, rawPath); |
| 194 | if (IsReadableFile(candidate)) { |
| 195 | return candidate; |
| 196 | } |
| 197 | const std::string parent = ParentDir(configDir); |
| 198 | if (!parent.empty()) { |
| 199 | const std::string parentCandidate = JoinPath(parent, rawPath); |
| 200 | if (IsReadableFile(parentCandidate)) { |
| 201 | return parentCandidate; |
| 202 | } |
| 203 | const std::string parentParent = ParentDir(parent); |
| 204 | if (!parentParent.empty()) { |
| 205 | const std::string basename = rawPath.substr(rawPath.find_last_of("/\\") == std::string::npos |
| 206 | ? 0 |
| 207 | : rawPath.find_last_of("/\\") + 1); |
| 208 | const std::string devCandidate = JoinPath(parentParent, "deps/cppjieba/dict/" + basename); |
| 209 | if (IsReadableFile(devCandidate)) { |
| 210 | return devCandidate; |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | for (const std::string& pluginDir : |
| 216 | SplitSearchPath(std::getenv("OPENCC_SEGMENTATION_PLUGIN_PATH"))) { |
| 217 | const std::string candidate = JoinPath(pluginDir, rawPath); |
| 218 | if (IsReadableFile(candidate)) { |
| 219 | return candidate; |
| 220 | } |
| 221 | const std::string pluginParent = ParentDir(pluginDir); |
| 222 | if (!pluginParent.empty()) { |
| 223 | const std::string parentCandidate = JoinPath(pluginParent, rawPath); |
| 224 | if (IsReadableFile(parentCandidate)) { |
| 225 | return parentCandidate; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | const char* dataDir = std::getenv("OPENCC_DATA_DIR"); |
| 230 | if (dataDir != nullptr && *dataDir != '\0') { |
| 231 | const std::string candidate = JoinPath(dataDir, rawPath); |
| 232 | if (IsReadableFile(candidate)) { |
| 233 | return candidate; |
| 234 | } |
| 235 | } |
| 236 | if (!PACKAGE_DATA_DIRECTORY.empty()) { |
| 237 | const std::string candidate = JoinPath(PACKAGE_DATA_DIRECTORY, rawPath); |
| 238 | if (IsReadableFile(candidate)) { |
no test coverage detected