File tree 3 files changed +12
-3
lines changed
3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -531,6 +531,7 @@ uppercase: native [
531
531
dehex: native [
532
532
{Converts URL-style hex encoded (%xx) strings. If input is UTF-8 encode, you should first convert it to binary!}
533
533
value [any-string! binary! ] {The string to dehex}
534
+ /escape char [char! ] {Can be used to change the default escape char #"%"}
534
535
]
535
536
536
537
enhex: native [
Original file line number Diff line number Diff line change @@ -560,17 +560,21 @@ static struct digest {
560
560
**
561
561
***********************************************************************/
562
562
{
563
- REBVAL * arg = D_ARG (1 );
563
+ REBVAL * arg = D_ARG (1 );
564
+ // REBOOL ref_escape = D_REF(2);
565
+ REBVAL * val_escape = D_ARG (3 );
564
566
REBINT len = (REBINT )VAL_LEN (arg ); // due to len -= 2 below
565
567
REBUNI n ;
566
568
REBSER * ser ;
567
569
570
+ const REBCHR escape_char = (IS_CHAR (val_escape )) ? VAL_CHAR (val_escape ) : '%' ;
571
+
568
572
if (VAL_BYTE_SIZE (arg )) {
569
573
REBYTE * bp = VAL_BIN_DATA (arg );
570
574
REBYTE * dp = Reset_Buffer (BUF_FORM , len );
571
575
572
576
for (; len > 0 ; len -- ) {
573
- if (* bp == '%' && len > 2 && Scan_Hex2 (bp + 1 , & n , FALSE)) {
577
+ if (* bp == escape_char && len > 2 && Scan_Hex2 (bp + 1 , & n , FALSE)) {
574
578
* dp ++ = (REBYTE )n ;
575
579
bp += 3 ;
576
580
len -= 2 ;
@@ -586,7 +590,7 @@ static struct digest {
586
590
REBUNI * dp = (REBUNI * )Reset_Buffer (BUF_MOLD , len );
587
591
588
592
for (; len > 0 ; len -- ) {
589
- if (* up == '%' && len > 2 && Scan_Hex2 ((REBYTE * )(up + 1 ), & n , TRUE)) {
593
+ if (* up == escape_char && len > 2 && Scan_Hex2 ((REBYTE * )(up + 1 ), & n , TRUE)) {
590
594
* dp ++ = (REBUNI )n ;
591
595
up += 3 ;
592
596
len -= 2 ;
Original file line number Diff line number Diff line change @@ -644,6 +644,10 @@ Rebol [
644
644
--assert "%C2%81" = enhex to-string #{ 81 }
645
645
--assert "%E5%85%83" = enhex {元}
646
646
647
+ --test-- "DEHEX/escape"
648
+ --assert "C# #XX" = dehex /escape "C#23#20#XX" #"#"
649
+ --assert "(š)" = dehex /escape "#28š#29" #"#"
650
+
647
651
648
652
===end-group===
649
653
You can’t perform that action at this time.
0 commit comments