| 118 | } |
| 119 | |
| 120 | std::string MetadataTagProcessorImpl::ValidateAndFormat_url(std::string const & v) |
| 121 | { |
| 122 | // Remove the last slash if it's after the hostname to beautify URLs in the UI and save a byte of space: |
| 123 | // https://www.test.com/ => https://www.test.com |
| 124 | // www.test.com/ => www.test.com |
| 125 | // www.test.com/path => www.test.com/path |
| 126 | // www.test.com/path/ => www.test.com/path/ |
| 127 | constexpr std::string_view kHttps = "https://"; |
| 128 | constexpr std::string_view kHttp = "http://"; |
| 129 | size_t start = 0; |
| 130 | if (v.starts_with(kHttps)) |
| 131 | start = kHttps.size(); |
| 132 | else if (v.starts_with(kHttp)) |
| 133 | start = kHttp.size(); |
| 134 | auto const first = v.find('/', start); |
| 135 | if (first == std::string::npos) |
| 136 | return v; |
| 137 | if (first + 1 == v.size()) |
| 138 | return std::string{v.begin(), --v.end()}; |
| 139 | return v; |
| 140 | } |
| 141 | |
| 142 | std::string MetadataTagProcessorImpl::ValidateAndFormat_text(std::string const & v) |
| 143 | { |