@@ -153,9 +153,10 @@ namespace cage
153153 return std::binary_search (data, data + current, what);
154154 }
155155
156- uint32 encodeUrlBase (char *pStart, const char *pSrc, uint32 length)
156+ uint32 encodeUrlBase (uint8 *pStart, const uint8 *pSrc, uint32 length)
157157 {
158- static constexpr bool SAFE[256 ] = { /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
158+ static constexpr bool SAFE[256 ] = { //
159+ /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
159160 /* 0 */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
160161 /* 1 */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
161162 /* 2 */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 1 , 0 , // (, ), +, -, .
@@ -176,26 +177,27 @@ namespace cage
176177 /* E */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
177178 /* F */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
178179 };
179- static constexpr char DEC2HEX[16 + 1 ] = " 0123456789ABCDEF" ;
180- char *pEnd = pStart;
181- const char *const SRC_END = pSrc + length;
180+ static constexpr uint8 DEC2HEX[16 + 1 ] = " 0123456789ABCDEF" ;
181+ uint8 *pEnd = pStart;
182+ const uint8 *const SRC_END = pSrc + length;
182183 for (; pSrc < SRC_END; ++pSrc)
183184 {
184- if (SAFE[( unsigned char ) *pSrc])
185+ if (SAFE[*pSrc])
185186 *pEnd++ = *pSrc;
186187 else
187188 {
188189 *pEnd++ = ' %' ;
189- *pEnd++ = DEC2HEX[(( unsigned char ) *pSrc) >> 4 ];
190- *pEnd++ = DEC2HEX[(( unsigned char ) *pSrc) & 0x0F ];
190+ *pEnd++ = DEC2HEX[(*pSrc) >> 4 ];
191+ *pEnd++ = DEC2HEX[(*pSrc) & 0x0F ];
191192 }
192193 }
193194 return numeric_cast<uint32>(pEnd - pStart);
194195 }
195196
196- uint32 decodeUrlBase (char *pStart, const char *pSrc, uint32 length)
197+ uint32 decodeUrlBase (uint8 *pStart, const uint8 *pSrc, uint32 length)
197198 {
198- static constexpr char HEX2DEC[256 ] = { /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
199+ static constexpr sint8 HEX2DEC[256 ] = { //
200+ /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
199201 /* 0 */ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
200202 /* 1 */ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
201203 /* 2 */ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
@@ -216,15 +218,15 @@ namespace cage
216218 /* E */ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
217219 /* F */ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1
218220 };
219- const char *const SRC_END = pSrc + length;
220- const char *const SRC_LAST_DEC = SRC_END - 2 ;
221- char *pEnd = pStart;
221+ const uint8 *const SRC_END = pSrc + length;
222+ const uint8 *const SRC_LAST_DEC = SRC_END - 2 ;
223+ uint8 *pEnd = pStart;
222224 while (pSrc < SRC_LAST_DEC)
223225 {
224226 if (*pSrc == ' %' )
225227 {
226- char dec1, dec2;
227- if (-1 != (dec1 = HEX2DEC[( unsigned char ) *(pSrc + 1 )]) && -1 != (dec2 = HEX2DEC[( unsigned char ) *(pSrc + 2 )]))
228+ uint8 dec1, dec2;
229+ if (-1 != (dec1 = HEX2DEC[*(pSrc + 1 )]) && -1 != (dec2 = HEX2DEC[*(pSrc + 2 )]))
228230 {
229231 *pEnd++ = (dec1 << 4 ) + dec2;
230232 pSrc += 3 ;
@@ -468,8 +470,8 @@ namespace cage
468470 void stringEncodeUrl (char *data, uint32 ¤t, uint32 maxLength, PointerRange<const char > what)
469471 {
470472 // todo this can buffer overflow
471- char tmp[4096 ];
472- const uint32 len = encodeUrlBase (tmp, what.data (), numeric_cast<uint32>(what.size ()));
473+ uint8 tmp[4096 ];
474+ const uint32 len = encodeUrlBase (tmp, (uint8 *) what.data (), numeric_cast<uint32>(what.size ()));
473475 if (len > maxLength)
474476 CAGE_THROW_ERROR (Exception, " string truncation" );
475477 std::memcpy (data, tmp, len);
@@ -480,7 +482,7 @@ namespace cage
480482 void stringDecodeUrl (char *data, uint32 ¤t, uint32 maxLength, PointerRange<const char > what)
481483 {
482484 CAGE_ASSERT (maxLength >= what.size ());
483- current = decodeUrlBase (data, what.data (), numeric_cast<uint32>(what.size ()));
485+ current = decodeUrlBase ((uint8 *) data, ( const uint8 *) what.data (), numeric_cast<uint32>(what.size ()));
484486 data[current] = 0 ;
485487 }
486488
0 commit comments