File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 1919
2020#include " iceberg/util/url_encoder.h"
2121
22+ #include < locale>
23+
2224namespace iceberg {
2325
2426namespace {
27+
28+ bool IsUnreserved (unsigned char c) {
29+ return (c >= ' 0' && c <= ' 9' ) || (c >= ' a' && c <= ' z' ) || (c >= ' A' && c <= ' Z' ) ||
30+ c == ' -' || c == ' .' || c == ' _' || c == ' ~' ;
31+ }
32+
2533// Helper: convert hex char to int (0–15), returns -1 if invalid
2634constexpr int8_t FromHex (char c) {
2735 if (c >= ' 0' && c <= ' 9' ) return c - ' 0' ;
2836 if (c >= ' A' && c <= ' F' ) return c - ' A' + 10 ;
2937 if (c >= ' a' && c <= ' f' ) return c - ' a' + 10 ;
3038 return -1 ;
3139}
40+
3241} // namespace
3342
3443std::string UrlEncoder::Encode (std::string_view str_to_encode) {
3544 static const char * hex_chars = " 0123456789ABCDEF" ;
3645 std::string result;
37- result.reserve (str_to_encode.size () * 3 /* Worst case: every char becomes %XX */ );
46+ result.reserve (str_to_encode.size () * 3 / 2 /* Heuristic reservation */ );
3847
39- for (unsigned char c : str_to_encode) {
40- if (std::isalnum (c) || c == ' - ' || c == ' _ ' || c == ' . ' || c == ' ~ ' ) {
41- result += static_cast < char >(c) ;
48+ for (char c : str_to_encode) {
49+ if (IsUnreserved (c)) {
50+ result += c ;
4251 } else {
4352 result += ' %' ;
4453 result += hex_chars[c >> 4 ];
Original file line number Diff line number Diff line change 2323#include < string_view>
2424
2525#include " iceberg/iceberg_export.h"
26- #include " iceberg/result.h"
2726
2827// / \file iceberg/util/url_encoder.h
2928// / \brief URL encoding and decoding.
You can’t perform that action at this time.
0 commit comments