| 50 | }; |
| 51 | |
| 52 | void ModuleResourcePrivate::InitFilePath(const std::string& file) |
| 53 | { |
| 54 | std::string normalizedFile = file; |
| 55 | if (normalizedFile.empty() || normalizedFile[0] != '/') |
| 56 | { |
| 57 | normalizedFile = '/' + normalizedFile; |
| 58 | } |
| 59 | |
| 60 | std::string rawPath; |
| 61 | std::size_t index = normalizedFile.find_last_of('/'); |
| 62 | if (index == std::string::npos) |
| 63 | { |
| 64 | fileName = normalizedFile; |
| 65 | } |
| 66 | else if (index < normalizedFile.size()-1) |
| 67 | { |
| 68 | fileName = normalizedFile.substr(index+1); |
| 69 | rawPath = normalizedFile.substr(0,index+1); |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | rawPath = normalizedFile; |
| 74 | } |
| 75 | |
| 76 | // remove duplicate / |
| 77 | std::string::value_type lastChar = 0; |
| 78 | for (std::size_t i = 0; i < rawPath.size(); ++i) |
| 79 | { |
| 80 | if (rawPath[i] == '/' && lastChar == '/') |
| 81 | { |
| 82 | continue; |
| 83 | } |
| 84 | lastChar = rawPath[i]; |
| 85 | path.push_back(lastChar); |
| 86 | } |
| 87 | if (path.empty()) |
| 88 | { |
| 89 | path.push_back('/'); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | ModuleResource::ModuleResource() |
| 94 | : d(new ModuleResourcePrivate(nullptr)) |
no test coverage detected