libmir / mir-algorithm
Showing 1 of 1 files from the diff.
Newly tracked file
source/mir/format.d changed.

@@ -7,6 +7,7 @@
Loading
7 7
module mir.format;
8 8
9 9
import std.traits;
10 +
import mir.primitives: isOutputRange;
10 11
11 12
/// `mir.conv: to` extension.
12 13
version(mir_test)
@@ -276,6 +277,7 @@
Loading
276 277
277 278
    ///
278 279
    void toString(C = char, W)(scope ref W w) scope const
280 +
    if (isSomeChar!C && isOutputRange!(W, C))
279 281
    {
280 282
        C[512] buf = void;
281 283
        auto n = printFloatingPoint(value, spec, buf);
@@ -302,6 +304,7 @@
Loading
302 304
303 305
    ///
304 306
    void toString(C = char, W)(scope ref W w) scope const
307 +
        if (isSomeChar!C && isOutputRange!(W, C))
305 308
    {
306 309
        enum N = T.sizeof * 2;
307 310
        static if(isFastBuffer!W)
@@ -337,6 +340,7 @@
Loading
337 340
/++
338 341
+/
339 342
ref W printEscaped(C, EscapeFormat escapeFormat = EscapeFormat.ion, W)(scope return ref W w, scope const(C)[] str)
343 +
    if (isOutputRange!(W, C))
340 344
{
341 345
    import mir.utility: _expect;
342 346
    foreach (C c; str)
@@ -406,7 +410,6 @@
Loading
406 410
@safe pure nothrow @nogc
407 411
version (mir_test) unittest
408 412
{
409 -
410 413
    import mir.format: stringBuf;
411 414
    stringBuf w;
412 415
    assert(w.printEscaped("Hi \a\v\0\f\t\b \\\r\n" ~ `"@nogc"`).data == `Hi \a\v\0\f\t\b \\\r\n\"@nogc\"`);
@@ -418,6 +421,7 @@
Loading
418 421
Decodes `char` `c` to the form `u00XX`, where `XX` is 2 hexadecimal characters.
419 422
+/
420 423
ref W put_xXX(C = char, W)(scope return ref W w, char c)
424 +
    if (isSomeChar!C && isOutputRange!(W, C))
421 425
{
422 426
    ubyte[2] spl;
423 427
    spl[0] = c >> 4;
@@ -434,6 +438,7 @@
Loading
434 438
Decodes `char` `c` to the form `u00XX`, where `XX` is 2 hexadecimal characters.
435 439
+/
436 440
ref W put_uXXXX(C = char, W)(scope return ref W w, char c)
441 +
    if (isSomeChar!C && isOutputRange!(W, C))
437 442
{
438 443
    ubyte[2] spl;
439 444
    spl[0] = c >> 4;
@@ -452,6 +457,7 @@
Loading
452 457
Decodes ushort `c` to the form `uXXXX`, where `XXXX` is 2 hexadecimal characters.
453 458
+/
454 459
ref W put_uXXXX(C = char, W)(scope return ref W w, ushort c)
460 +
    if (isSomeChar!C && isOutputRange!(W, C))
455 461
{
456 462
    ubyte[4] spl;
457 463
    spl[0] = (c >> 12) & 0xF;
@@ -470,7 +476,7 @@
Loading
470 476
471 477
///
472 478
ref W printElement(C, EscapeFormat escapeFormat = EscapeFormat.ion, W)(scope return ref W w, scope const(C)[] c)
473 -
    if (isSomeChar!C)
479 +
    if (isSomeChar!C && isOutputRange!(W, C))
474 480
{
475 481
    static immutable C[1] quote = '\"';
476 482
    return w
@@ -481,7 +487,7 @@
Loading
481 487
482 488
///
483 489
ref W printElement(C = char, EscapeFormat escapeFormat = EscapeFormat.ion, W, T)(scope return ref W w, scope auto ref const T c)
484 -
    if (!isSomeString!T)
490 +
    if (!isSomeString!T && isOutputRange!(W, C))
485 491
{
486 492
    return w.print!C(c);
487 493
}
@@ -490,7 +496,7 @@
Loading
490 496
Multiargument overload.
491 497
+/
492 498
ref W print(C = char, W, Args...)(scope return ref W w, scope auto ref const Args args)
493 -
    if (Args.length > 1)
499 +
    if (isSomeChar!C && isOutputRange!(W, C) && Args.length > 1)
494 500
{
495 501
    foreach(i, ref c; args)
496 502
        static if (i < Args.length - 1)
@@ -501,7 +507,7 @@
Loading
501 507
502 508
/// Prints enums
503 509
ref W print(C = char, W, T)(scope return ref W w, const T c)
504 -
    if (is(T == enum))
510 +
    if (isSomeChar!C && isOutputRange!(W, C) && is(T == enum))
505 511
{
506 512
    import mir.enums: getEnumIndex, enumStrings;
507 513
    import mir.utility: _expect;
@@ -538,6 +544,7 @@
Loading
538 544
539 545
/// Prints boolean
540 546
ref W print(C = char, W)(scope return ref W w, bool c)
547 +
    if (isSomeChar!C && isOutputRange!(W, C))
541 548
{
542 549
    enum N = 5;
543 550
    static if(isFastBuffer!W)
@@ -567,6 +574,7 @@
Loading
567 574
/// Prints associative array
568 575
pragma(inline, false)
569 576
ref W print(C = char, W, V, K)(scope return ref W w, scope const V[K] c)
577 +
    if (isSomeChar!C && isOutputRange!(W, C))
570 578
{
571 579
    enum C left = '[';
572 580
    enum C right = ']';
@@ -601,7 +609,7 @@
Loading
601 609
/// Prints array
602 610
pragma(inline, false)
603 611
ref W print(C = char, W, T)(scope return ref W w, scope const(T)[] c)
604 -
    if (!isSomeChar!T)
612 +
    if (isSomeChar!C && isOutputRange!(W, C) && !isSomeChar!T)
605 613
{
606 614
    enum C left = '[';
607 615
    enum C right = ']';
@@ -632,6 +640,7 @@
Loading
632 640
/// Prints escaped character in the form `'c'`.
633 641
pragma(inline, false)
634 642
ref W print(C = char, W)(scope return ref W w, char c)
643 +
    if (isSomeChar!C && isOutputRange!(W, C))
635 644
{
636 645
    w.put('\'');
637 646
    if (c >= 0x20)
@@ -687,7 +696,7 @@
Loading
687 696
688 697
/// Prints some string
689 698
ref W print(C = char, W)(scope return ref W w, scope const(C)[] c)
690 -
    if (isSomeChar!C)
699 +
    if (isSomeChar!C && isOutputRange!(W, C))
691 700
{
692 701
    w.put(c);
693 702
    return w;
@@ -695,7 +704,7 @@
Loading
695 704
696 705
/// Prints integers
697 706
ref W print(C = char, W, I)(scope return ref W w, const I c)
698 -
    if (isIntegral!I && !is(I == enum))
707 +
    if (isSomeChar!C && isOutputRange!(W, C) && isIntegral!I && !is(I == enum))
699 708
{
700 709
    static if (I.sizeof == 16)
701 710
        enum N = 39;
@@ -715,7 +724,7 @@
Loading
715 724
716 725
/// Prints floating point numbers
717 726
ref W print(C = char, W, T)(scope return ref W w, const T c, NumericSpec spec = NumericSpec.init)
718 -
    if(is(T == float) || is(T == double) || is(T == real))
727 +
    if(isSomeChar!C && isOutputRange!(W, C) && is(T == float) || is(T == double) || is(T == real))
719 728
{
720 729
    import mir.bignum.decimal;
721 730
    auto decimal = Decimal!(T.mant_dig < 64 ? 1 : 2)(c);
@@ -808,7 +817,7 @@
Loading
808 817
/// Prints structs and unions
809 818
pragma(inline, false)
810 819
ref W print(C = char, W, T)(scope return ref W w, ref const T c)
811 -
    if (is(T == struct) || is(T == union) && !is(T : NumericSpec))
820 +
    if (isSomeChar!C && isOutputRange!(W, C) && is(T == struct) || is(T == union) && !is(T : NumericSpec))
812 821
{
813 822
    static if (__traits(hasMember, T, "toString"))
814 823
    {
@@ -871,7 +880,7 @@
Loading
871 880
// FUTURE: remove it
872 881
pragma(inline, false)
873 882
ref W print(C = char, W, T)(scope return ref W w, scope const T c)
874 -
    if (is(T == struct) || is(T == union))
883 +
    if (isSomeChar!C && isOutputRange!(W, C) && is(T == struct) || is(T == union))
875 884
{
876 885
    return print!(C, W, T)(w, c);
877 886
}
@@ -894,7 +903,7 @@
Loading
894 903
/// Prints classes and interfaces
895 904
pragma(inline, false)
896 905
ref W print(C = char, W, T)(scope return ref W w, scope const T c)
897 -
    if (is(T == class) || is(T == interface))
906 +
    if (isSomeChar!C && isOutputRange!(W, C) && is(T == class) || is(T == interface))
898 907
{
899 908
    enum C[4] Null = "null";
900 909
    static if (__traits(hasMember, T, "toString") || __traits(compiles, { scope const(C)[] string_of_c = c; }))
@@ -960,7 +969,7 @@
Loading
960 969
961 970
///
962 971
ref W printStaticString(C, size_t N, W)(scope return ref W w, ref scope const C[N] c)
963 -
    if (is(C == char) || is(C == wchar) || is(C == dchar))
972 +
    if (isSomeChar!C && isOutputRange!(W, C) && is(C == char) || is(C == wchar) || is(C == dchar))
964 973
{
965 974
    static if (isFastBuffer!W)
966 975
    {
@@ -1008,7 +1017,7 @@
Loading
1008 1017
1009 1018
///
1010 1019
ref W printZeroPad(C = char, W, I)(scope return ref W w, const I c, size_t minimalLength)
1011 -
    if (isIntegral!I && !is(I == enum))
1020 +
    if (isSomeChar!C && isOutputRange!(W, C) && isIntegral!I && !is(I == enum))
1012 1021
{
1013 1022
    static if (I.sizeof == 16)
1014 1023
        enum N = 39;
Files Coverage
source/mir 92.65%
Project Totals (62 files) 92.65%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading