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