MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / urlEncode

Function urlEncode

Source/3rdParty/bx/src/url.cpp:125–155  ·  view source on GitHub ↗

https://secure.wikimedia.org/wikipedia/en/wiki/URL_encoding

Source from the content-addressed store, hash-verified

123
124 // https://secure.wikimedia.org/wikipedia/en/wiki/URL_encoding
125 void urlEncode(char* _out, uint32_t _max, const StringView& _str)
126 {
127 _max--; // need space for zero terminator
128
129 const char* str = _str.getPtr();
130 const char* term = _str.getTerm();
131
132 uint32_t ii = 0;
133 for (char ch = *str++
134 ; str <= term && ii < _max
135 ; ch = *str++
136 )
137 {
138 if (isAlphaNum(ch)
139 || ch == '-'
140 || ch == '_'
141 || ch == '.'
142 || ch == '~')
143 {
144 _out[ii++] = ch;
145 }
146 else if (ii+3 < _max)
147 {
148 _out[ii++] = '%';
149 _out[ii++] = toHex(ch>>4);
150 _out[ii++] = toHex(ch);
151 }
152 }
153
154 _out[ii] = '\0';
155 }
156
157} // namespace bx

Callers

nothing calls this directly

Calls 2

isAlphaNumFunction · 0.85
toHexFunction · 0.85

Tested by

no test coverage detected