@@ -334,6 +334,13 @@ struct HexAddress(T)
334334 }
335335}
336336
337+ // /ditto
338+ HexAddress! T hexAddress (T)(const T value, SwitchLU switchLU = SwitchLU.upper)
339+ if (isUnsigned! T && ! is (T == enum ))
340+ {
341+ return typeof (return )(value, switchLU);
342+ }
343+
337344/+ +
338345Escaped string formats
339346+/
@@ -640,25 +647,37 @@ version (mir_test) unittest
640647
641648// / Prints array
642649pragma (inline, false )
643- ref W print (C = char , W, T)(scope return ref W w, scope const (T)[] c)
650+ ref W printArray (C = char , W, T)(scope return ref W w,
651+ scope const (T)[] c,
652+ scope const (C)[] lb = " [" ,
653+ scope const (C)[] rb = " ]" ,
654+ scope const (C)[] sep = " , " ,
655+ )
644656 if (isSomeChar! C && ! isSomeChar! T)
645657{
646- enum C left = ' [' ;
647- enum C right = ' ]' ;
648- enum C[2 ] sep = " , " ;
649- w.put(left);
658+ w.put(lb);
650659 bool first = true ;
651660 foreach (ref e; c)
652661 {
653662 if (! first)
654- w.printStaticString ! C (sep);
663+ w.put (sep);
655664 first = false ;
656665 printElement! C(w, e);
657666 }
658- w.put(right );
667+ w.put(rb );
659668 return w;
660669}
661670
671+ // / ditto
672+ pragma (inline, false )
673+ ref W print (C = char , W, T)(scope return ref W w,
674+ scope const (T)[] c,
675+ )
676+ if (isSomeChar! C && ! isSomeChar! T)
677+ {
678+ return printArray (w, c);
679+ }
680+
662681// /
663682@safe pure nothrow @nogc
664683version (mir_test) unittest
@@ -669,6 +688,39 @@ version (mir_test) unittest
669688 assert (w.print(array[]).data == ` ["a\na", "b"]` );
670689}
671690
691+ // / Prints array as hex values
692+ pragma (inline, false )
693+ ref W printHexArray (C = char , W, T)(scope return ref W w,
694+ scope const (T)[] c,
695+ scope const (C)[] lb = " " ,
696+ scope const (C)[] rb = " " ,
697+ scope const (C)[] sep = " " ,
698+ )
699+ if (isSomeChar! C && ! isSomeChar! T && isUnsigned! T)
700+ {
701+ w.put(lb);
702+ bool first = true ;
703+ foreach (ref e; c)
704+ {
705+ if (! first)
706+ w.put(sep);
707+ first = false ;
708+ printElement! C(w, e.hexAddress);
709+ }
710+ w.put(rb);
711+ return w;
712+ }
713+
714+ // /
715+ @safe pure nothrow @nogc
716+ version (mir_test) unittest
717+ {
718+ import mir.appender: scopedBuffer;
719+ auto w = scopedBuffer! char ;
720+ ubyte [2 ] array = [0x34 , 0x32 ];
721+ assert (w.print(array[]).data == ` 34 32` );
722+ }
723+
672724// / Prints escaped character in the form `'c'`.
673725pragma (inline, false )
674726ref W print (C = char , W)(scope return ref W w, char c)
0 commit comments