| 148 | } |
| 149 | |
| 150 | std::string_view Uri::getFileName() const { |
| 151 | if (!this->isValid()) { |
| 152 | return {}; |
| 153 | } |
| 154 | |
| 155 | uint32_t pathLength = this->_url->get_pathname_length(); |
| 156 | // If the pathname is empty or just "/", there's no filename. |
| 157 | if (pathLength <= 1) { |
| 158 | return {}; |
| 159 | } |
| 160 | |
| 161 | const std::string_view path = this->_url->get_pathname(); |
| 162 | const int32_t end = (int32_t)(pathLength - 1); |
| 163 | for (int32_t i = end; i >= 0; i--) { |
| 164 | if (path[(size_t)i] != '/') { |
| 165 | continue; |
| 166 | } |
| 167 | |
| 168 | // Last char of pathname is '/', so no filename |
| 169 | if (i == end) { |
| 170 | return {}; |
| 171 | } |
| 172 | |
| 173 | return path.substr((size_t)(i + 1), (size_t)(end - i)); |
| 174 | } |
| 175 | |
| 176 | // If we've gotten this far, the whole pathname is the filename |
| 177 | return path; |
| 178 | } |
| 179 | |
| 180 | std::string_view Uri::getStem() const { |
| 181 | const std::string_view filename = this->getFileName(); |
no test coverage detected