| 58 | |
| 59 | protected: |
| 60 | std::string get_include_url ( |
| 61 | const std::string& filename |
| 62 | ) const override |
| 63 | { |
| 64 | // Match quoted-include search order. A header that is found but is |
| 65 | // not being rendered must not link to a different, later match. |
| 66 | std::vector<fs::path> candidates = {source.parent_path() / filename}; |
| 67 | for (const auto& dir : include_dirs) |
| 68 | candidates.push_back(dir / filename); |
| 69 | for (const auto& candidate : candidates) |
| 70 | { |
| 71 | if (!fs::is_regular_file(candidate)) |
| 72 | continue; |
| 73 | const auto found = outputs.find(fs::weakly_canonical(candidate)); |
| 74 | if (found == outputs.end()) |
| 75 | return {}; |
| 76 | const auto relative = found->second.lexically_relative(output.parent_path()).generic_string(); |
| 77 | std::string url; |
| 78 | const char hex[] = "0123456789ABCDEF"; |
| 79 | for (const unsigned char ch : relative) |
| 80 | { |
| 81 | if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || |
| 82 | (ch >= '0' && ch <= '9') || std::string("/.-_~").find(ch) != std::string::npos) |
| 83 | url += ch; |
| 84 | else |
| 85 | { |
| 86 | url += '%'; |
| 87 | url += hex[ch >> 4]; |
| 88 | url += hex[ch & 15]; |
| 89 | } |
| 90 | } |
| 91 | return url; |
| 92 | } |
| 93 | return {}; |
| 94 | } |
| 95 | |
| 96 | private: |
| 97 | fs::path source; |