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

Function ResolveAuxPath

plugins/jieba/src/JiebaSegmentationPlugin.cpp:247–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245}
246
247std::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
283void FallbackToTextJiebaDictionaries(const std::string& requestedDictPath,
284 const std::string& configDir,

Callers 1

CreateJiebaSegmentationFunction · 0.70

Calls 5

ResolveResourcePathFunction · 0.85
findMethod · 0.80
IsReadableFileFunction · 0.70
substrMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected