Ignore:
Timestamp:
Oct 5, 2023, 2:30:54 PM (12 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
b67b632
Parents:
bf1cbde
Message:

Support match-failure reporting for string input.

On failed match, assign the empty-string value to the target.
Prior handling did not modify the target,
which in context like char s[10]; sin | exclude("\n", s);,
left s uninitialized, and invalid for strlen, when the input's next character is a newline.
In this case, scanf offers the return value, the count of output arguments written,
to say, "I did not write to your buffer," a feature lost in the pipe abstraction.

Add tests to exercise such cases.

(Prior "leave uninitialized" treatment was discovered by surprise, while debugging a test program for an upcoming commit.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/collections/string-istream-manip.cfa

    rbf1cbde r8cffa4f  
    2323        sin | ignore( incl( "abc", wdi( 8, s ) ) );     sout | "12" | s;
    2424        sin | ignore( excl( "abc", wdi( 8, s ) ) );     sout | "13" | s;
    25     }
     25
     26                s = "q";
     27                sin | incl( "abc", s );                         sout | "14" | s;
     28                s = "q";
     29                sin | excl( "u", s );                           sout | "15" | s;
     30                sin | skip( "u" );
     31                sin | "\n";
     32        }
    2633    {
    2734        string_res s = "yyyyyyyyyyyyyyyyyyyy";
     
    4148        sin | ignore( incl( "abc", wdi( 8, s ) ) );     sout | "12" | s;
    4249        sin | ignore( excl( "abc", wdi( 8, s ) ) );     sout | "13" | s;
     50
     51                s = "q";
     52                sin | incl( "abc", s );                         sout | "14" | s;
     53                s = "q";
     54                sin | excl( "u", s );                           sout | "15" | s;
     55                sin | skip( "u" );
     56                sin | "\n";
    4357    }
    4458}
Note: See TracChangeset for help on using the changeset viewer.