| 245 | } |
| 246 | |
| 247 | std::string ResolveAuxPath(const std::string& dictPath, |
| 248 | const std::string& modelPath, |
| 249 | const std::string& configDir, |
| 250 | const std::string& fileName) { |
| 251 | const std::string::size_type pos = dictPath.find_last_of("/\\"); |
| 252 | if (pos != std::string::npos) { |
| 253 | const std::string candidate = dictPath.substr(0, pos + 1) + fileName; |
| 254 | if (IsReadableFile(candidate)) { |
| 255 | return candidate; |
| 256 | } |
| 257 | } |
| 258 | const std::string::size_type modelPos = modelPath.find_last_of("/\\"); |
| 259 | if (modelPos != std::string::npos) { |
| 260 | const std::string modelCandidate = |
| 261 | modelPath.substr(0, modelPos + 1) + fileName; |
| 262 | if (IsReadableFile(modelCandidate)) { |
| 263 | return modelCandidate; |
| 264 | } |
| 265 | } |
| 266 | // Development fallback: try deps/cppjieba/dict/ relative to the source tree |
| 267 | const std::string needle = "share/opencc/jieba_dict/"; |
| 268 | const std::string::size_type needlePos = dictPath.find(needle); |
| 269 | if (needlePos != std::string::npos) { |
| 270 | std::string alt = dictPath; |
| 271 | alt.replace(needlePos, needle.size(), "plugins/jieba/deps/cppjieba/dict/"); |
| 272 | const std::string::size_type altPos = alt.find_last_of("/\\"); |
| 273 | if (altPos != std::string::npos) { |
| 274 | const std::string altCandidate = alt.substr(0, altPos + 1) + fileName; |
| 275 | if (IsReadableFile(altCandidate)) { |
| 276 | return altCandidate; |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | return ResolveResourcePath("jieba_dict/" + fileName, configDir); |
| 281 | } |
| 282 | |
| 283 | void FallbackToTextJiebaDictionaries(const std::string& requestedDictPath, |
| 284 | const std::string& configDir, |
no test coverage detected