| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 62515e1 commit f1d79b3
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -417,12 +417,21 @@ void BindingData::RegisterExternalReferences( | |||
| 417 | 417 | } | |
| 418 | 418 | } | |
| 419 | 419 | ||
| 420 | - std::string FromFilePath(const std::string_view file_path) { | ||
| 421 | - std::string escaped_file_path; | ||
| 422 | - for (size_t i = 0; i < file_path.length(); ++i) { | ||
| 423 | - escaped_file_path += file_path[i]; | ||
| 424 | - if (file_path[i] == '%') escaped_file_path += "25"; | ||
| 420 | + std::string FromFilePath(std::string_view file_path) { | ||
| 421 | + // Avoid unnecessary allocations. | ||
| 422 | + size_t pos = file_path.empty() ? std::string_view::npos : file_path.find('%'); | ||
| 423 | + if (pos == std::string_view::npos) { | ||
| 424 | + return ada::href_from_file(file_path); | ||
| 425 | 425 | } | |
| 426 | + // Escape '%' characters to a temporary string. | ||
| 427 | + std::string escaped_file_path; | ||
| 428 | + do { | ||
| 429 | + escaped_file_path += file_path.substr(0, pos + 1); | ||
| 430 | + escaped_file_path += "25"; | ||
| 431 | + file_path = file_path.substr(pos + 1); | ||
| 432 | + pos = file_path.empty() ? std::string_view::npos : file_path.find('%'); | ||
| 433 | + } while (pos != std::string_view::npos); | ||
| 434 | + escaped_file_path += file_path; | ||
| 426 | 435 | return ada::href_from_file(escaped_file_path); | |
| 427 | 436 | } | |
| 428 | 437 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,7 +81,7 @@ class BindingData : public SnapshotableObject { | |||
| 81 | 81 | std::optional<std::string> base); | |
| 82 | 82 | }; | |
| 83 | 83 | ||
| 84 | - std::string FromFilePath(const std::string_view file_path); | ||
| 84 | + std::string FromFilePath(std::string_view file_path); | ||
| 85 | 85 | ||
| 86 | 86 | } // namespace url | |
| 87 | 87 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments