Changeset bb1eabc


Ignore:
Timestamp:
May 4, 2026, 7:26:38 AM (5 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
244335b
Parents:
8403b32
Message:

harmonize output quote manipulator with input quote manipulator, adding left/right quote parameters

Files:
11 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r8403b32 rbb1eabc  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun May  3 10:13:13 2026
    14 %% Update Count     : 7425
     13%% Last Modified On : Mon May  4 07:19:24 2026
     14%% Update Count     : 7436
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    54695469
    54705470\item
    5471 \Indexc{quote}( character / string) )\index{manipulator!quote@©quote©} bracket text with appropriate quote characters.
     5471\Indexc{quote}( character / string, ©const char qleft©, ©const char qright©) )\index{manipulator!quote@©quote©} bracket text with appropriate quote characters.
    54725472No quotes is the default.
    54735473\begin{cfa}[belowskip=0pt]
    5474 sout | quote( 'A' ) | quote( "abd" ) | quote( (string){ "@#!" } );
    5475 'A'"abd" "@#!"
     5474sout | quote( 'A' ) | quote( 'W', '"' ) | quote( "abd" ) | quote( "abd", '<', '>' )
     5475          | quote( (string){ "@#!" } ) | quote( (string){ "@#!" }, '[', ']' );
     5476'A'"W""abd" §\LstStringStyle{<abd>}§ "@#!" §\LstStringStyle{[@\#!]}§
    54765477\end{cfa}
    54775478
     
    57435744
    57445745\item
    5745 \Indexc{quote}( ©char & ch©, ©const char Ldelimiter = '\''©, ©const char Rdelimiter = '\0'© )\index{manipulator!quote@©quote©}
     5746\Indexc{quote}( ©char & ch©, ©const char qleft = '\''©, ©const char qright = '\0'© )\index{manipulator!quote@©quote©}
    57465747consumes the string ©"LCR"©, where ©L© is the left ©delimiter© character, ©C© is the value in ©ch©, and ©R© is the right delimiter character, which skips whitespace, consumes and ignores the left delimiter, reads a single character into ©ch©, and consumes and ignores the right delimiter (3 characters).
    57475748If the delimit character is omitted, it defaults to ©'\''© (single quote).
     
    57565757\item
    57575758\begin{sloppypar}
    5758 \Indexc{quote}( $wdi\ manipulator$, ©const char Ldelimiter = '\''©, ©const char Rdelimiter = '\0'© )\index{manipulator!quote@©quote©}
     5759\Indexc{quote}( $wdi\ manipulator$, ©const char qleft = '\''©, ©const char qright = '\0'© )\index{manipulator!quote@©quote©}
    57595760consumes the scanset ©"L[^R]R"©, where ©L© is the left ©delimiter© character and ©R© is the right delimiter character, which skips whitespace, consumes and ignores the left delimiter, reads characters until the right-delimiter into the string variable (null terminated), and consumes and ignores the right delimiter.
    57605761If the delimit character is omitted, it defaults to ©'"'© (double quote).
  • libcfa/src/collections/string.cfa

    r8403b32 rbb1eabc  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 15 10:26:35 2025
    13 // Update Count     : 394
     12// Last Modified On : Sun May  3 23:21:25 2026
     13// Update Count     : 395
    1414//
    1515
     
    214214                for ( i; l ) cstr[i] = f.val[i];                                        // copy string
    215215                cstr[l] = '\0';                                                                         // terminate
    216                 _Ostream_Manip(const char *) cf @= { cstr, f.wd, f.pc, f.base, {f.all} };
     216                _Ostream_Manip(const char *) cf @= { cstr, f.wd, f.pc, f.base, {f.all}, f.qleft, f.qright };
    217217                return os | cf | nonl;
    218218        } // ?|?
  • libcfa/src/collections/string.hfa

    r8403b32 rbb1eabc  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May  2 19:09:55 2026
    13 // Update Count     : 322
     12// Last Modified On : Sun May  3 23:24:08 2026
     13// Update Count     : 324
    1414//
    1515
     
    9090        _Ostream_Manip(string) oct( string s ) { return (_Ostream_Manip(string))@{ .val = s, .wd = 1, .pc = 0, .base = 'o', { .all = 0 } }; }
    9191        _Ostream_Manip(string) hex( string s ) { return (_Ostream_Manip(string))@{ .val = s, .wd = 1, .pc = 0, .base = 'x', { .all = 0 } }; }
    92         _Ostream_Manip(string) quote( string s ) { return (_Ostream_Manip(string))@{ .val = s, .wd = 1, .pc = 0, .base = 's', { .flags.quote = true } }; }
     92        _Ostream_Manip(string) quote( string s, const char qleft = '"', const char qright = '\0' ) {
     93                return (_Ostream_Manip(string))@{ .val = s, .wd = 1, .pc = 0, .base = 's', { .flags.quote = true }, .qleft = qleft, .qright = qright }; }
    9394        _Ostream_Manip(string) wd( unsigned int wd, string s ) { return (_Ostream_Manip(string))@{ .val = s, .wd = wd, .pc = 0, .base = 's', { .all = 0 } }; }
    9495        _Ostream_Manip(string) wd( unsigned int wd, unsigned int pc, string s ) { return (_Ostream_Manip(string))@{ .val = s, .wd = wd, .pc = pc, .base = 's', { .flags.pc = true } }; }
     
    9899        _Ostream_Manip(string) & nobase( _Ostream_Manip(string) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
    99100        _Ostream_Manip(string) & upcase( _Ostream_Manip(string) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; }
    100         _Ostream_Manip(string) & quote( _Ostream_Manip(string) & fmt ) { fmt.flags.quote = true; return fmt; } \
     101        _Ostream_Manip(string) & quote( _Ostream_Manip(string) & fmt, const char qleft = '"', const char qright = '\0' ) {
     102                fmt.flags.quote = true; fmt.qleft = qleft, fmt.qright = qright; return fmt; }
    101103} // distribution
    102104
  • libcfa/src/iostream.cfa

    r8403b32 rbb1eabc  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May  3 08:08:29 2026
    13 // Update Count     : 2241
     12// Last Modified On : Sun May  3 22:02:37 2026
     13// Update Count     : 2271
    1414//
    1515
     
    698698                } // if
    699699                if ( f.flags.quote ) {                                                  // print as string
    700                         char qv[] = "' '";
    701                         qv[1] = f.val;
     700                        char qv[] = { f.qleft, f.val, f.qright ? : f.qleft, '\0' };
    702701                        f.flags.quote = false;                                          // already quoted
    703702                        _Ostream_Manip(const char *) fmtuc @= { qv, f.wd, f.pc, 's', {f.all} };
     
    743742                        int len = strlen( f.val );
    744743                        char qv[len + 3];                                                       // space for quotes and '\0'
    745                         qv[0] = '"';                                                            // copy string surrounded with quotes
    746                         strcpy( &qv[1], f.val );
    747                         qv[len + 1] = '"';
    748                         qv[len + 2] = '\0';
     744                        qv[0] = f.qleft; strcpy( &qv[1], f.val );
     745                        qv[len + 1] = f.qright ? : f.qleft; qv[len + 2] = '\0'; // copy string surrounded with quotes
    749746                        f.flags.quote = false;                                          // already quoted
    750747                        _Ostream_Manip(const char *) fmtuc @= { qv, f.wd, f.pc, 's', {f.all} };
  • libcfa/src/iostream.hfa

    r8403b32 rbb1eabc  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May  2 18:48:56 2026
    13 // Update Count     : 780
     12// Last Modified On : Sun May  3 21:55:06 2026
     13// Update Count     : 829
    1414//
    1515
     
    209209        char base;                                                                                      // numeric base / floating-point style
    210210        inline _Ostream_Manip_Mode;
     211        char qleft, qright;                                                                     // quote delimiters (PLACE HERE SO OPTIONAL IN INITIALIZATION)
    211212}; // _Ostream_Manip
    212213
     
    289290        _Ostream_Manip(char) oct( char c ) { return (_Ostream_Manip(char))@{ .val = c, .wd = 1, .pc = 0, .base = 'o', { .all = 0 } }; }
    290291        _Ostream_Manip(char) hex( char c ) { return (_Ostream_Manip(char))@{ .val = c, .wd = 1, .pc = 0, .base = 'x', { .all = 0 } }; }
    291         _Ostream_Manip(char) quote( char c ) { return (_Ostream_Manip(char))@{ .val = c, .wd = 1, .pc = 0, .base = 'c', { .flags.quote = true } }; }
     292        _Ostream_Manip(char) quote( char c, const char qleft = '\'', const char qright = '\0' ) {
     293                return (_Ostream_Manip(char))@{ .val = c, .wd = 1, .pc = 0, .base = 'c', { .flags.quote = true }, .qleft = qleft, .qright = qright }; }
    292294        _Ostream_Manip(char) wd( unsigned int wd, char c ) { return (_Ostream_Manip(char))@{ .val = c, .wd = wd, .pc = 0, .base = 'c', { .all = 0 } }; }
    293295        _Ostream_Manip(char) & wd( unsigned int wd, _Ostream_Manip(char) & fmt ) { fmt.wd = wd; return fmt; }
     
    295297        _Ostream_Manip(char) & upcase( _Ostream_Manip(char) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; }
    296298        _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
    297         _Ostream_Manip(char) & quote( _Ostream_Manip(char) & fmt ) { fmt.flags.quote = true; return fmt; }
     299        _Ostream_Manip(char) & quote( _Ostream_Manip(char) & fmt, const char qleft = '\'', const char qright = '\0' ) {
     300                fmt.flags.quote = true; fmt.qleft = qleft, fmt.qright = qright; return fmt; }
    298301} // distribution
    299302forall( ostype & | basic_ostream( ostype ) ) {
     
    308311        _Ostream_Manip(const char *) oct( const char s[] ) { return (_Ostream_Manip(const char *))@{ .val = s, .wd = 1, .pc = 0, .base = 'o', { .all = 0 } }; }
    309312        _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ .val = s, .wd = 1, .pc = 0, .base = 'x', { .all = 0 } }; }
    310         _Ostream_Manip(const char *) quote( const char s[] ) { return (_Ostream_Manip(const char *))@{ .val = s, .wd = 1, .pc = 0, .base = 's', { .flags.quote = true } }; }
     313        _Ostream_Manip(const char *) quote( const char s[], const char qleft = '"', const char qright = '\0' ) {
     314                return (_Ostream_Manip(const char *))@{ .val = s, .wd = 1, .pc = 0, .base = 's', { .flags.quote = true }, .qleft = qleft, .qright = qright }; }
    311315        _Ostream_Manip(const char *) wd( unsigned int wd, const char s[] ) { return (_Ostream_Manip(const char *))@{ .val = s, .wd = wd, .pc = 0, .base = 's', { .all = 0 } }; }
    312316        _Ostream_Manip(const char *) wd( unsigned int wd, unsigned int pc, const char s[] ) { return (_Ostream_Manip(const char *))@{ .val = s, .wd = wd, .pc = pc, .base = 's', { .flags.pc = true } }; }
     
    316320        _Ostream_Manip(const char *) & upcase( _Ostream_Manip(const char *) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; }
    317321        _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
    318         _Ostream_Manip(const char *) & quote( _Ostream_Manip(const char *) & fmt ) { fmt.flags.quote = true; return fmt; } \
     322        _Ostream_Manip(const char *) & quote( _Ostream_Manip(const char *) & fmt, const char qleft = '"', const char qright = '\0' ) {
     323                fmt.flags.quote = true; fmt.qleft = qleft; fmt.qright = qright; return fmt; }
    319324} // distribution
    320325forall( ostype & | basic_ostream( ostype ) ) {
     
    430435        union {
    431436                const char * scanset;
    432                 char delimiters[3];                                                             // [0] => left, [1] => right
     437                char delimiters[3];                                                             // [0] => qleft or terminator, [1] => qright or getline '\0', [2] => char '\0' or char * '\1'
    433438        };
    434439        int wd;                                                                                         // width
  • tests/collections/.expect/string-ostream.txt

    r8403b32 rbb1eabc  
    11string
    2 abcd "abcd"     abcd   "abcd"   abcd abcd     "abcd" 
    3 abcd "abcd"     abcd   "abcd"   abcd abcd     "abcd" 
     2abcd "abcd"     abcd   "abcd"   'abcd'   <abcd>   abcd abcd     "abcd" 
     3abcd "abcd"     abcd   "abcd"   'abcd'   <abcd>   abcd abcd     "abcd" 
    44141 142 143 144 0141 0142 0143 0144      141      142      143      144 0141     0142     0143     0144   
    55141 142 143 144 0141 0142 0143 0144      141      142      143      144 0141     0142     0143     0144   
  • tests/collections/string-ostream.cfa

    r8403b32 rbb1eabc  
    88// Created On       : Sat May  2 18:02:34 2026
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Sat May  2 19:06:22 2026
    11 // Update Count     : 7
     10// Last Modified On : Sun May  3 23:31:07 2026
     11// Update Count     : 8
    1212//
    1313
     
    1818        sout | "string";
    1919        const char * cs = "abcd";
    20         sout | cs | quote( cs ) | wd(8,cs) | quote(wd(8,cs)) | wd(6,8,cs) | left(wd(8,cs)) | quote(left(wd(8,cs)));
     20        sout | cs | quote(cs) | wd(8,cs) | quote(wd(8,cs)) | quote(wd(8,cs), '\'')| quote(wd(8,cs), '<', '>')
     21                 | wd(6,8,cs) | left(wd(8,cs)) | quote(left(wd(8,cs)));
    2122        string s = "abcd";
    22         sout | s | quote( s ) | wd(8,s) | quote(wd(8,s)) | wd(6,8,s) | left(wd(8,s)) | quote(left(wd(8,s)));
     23        sout | s | quote(s) | wd(8,s) | quote(wd(8,s)) | quote(wd(8,s), '\'')| quote(wd(8,s), '<', '>')
     24                 | wd(6,8,s) | left(wd(8,s)) | quote(left(wd(8,s)));
    2325
    2426        sout | nobase(oct(cs)) | upcase(oct(cs)) | nobase(wd(8,oct(cs))) | left(wd(-8,oct(cs)));
  • tests/io/.expect/manipulatorsOutput1.arm64.txt

    r8403b32 rbb1eabc  
    3838
    3939char
    40 a'a' ' '       a     'a'    aa   
    41 a'a' ' '       a     'a'    aa   
     40a'a' ' '"a"<a>       a     'a'     "a"     {a}    aa   
     41a'a' ' '"a"<a>       a     'a'     "a"     {a}    aa   
    4242141 0141      141 0141     61 0x61       61 0x61   
    4343141 0141      141 0141     61 0X61       61 0x61     1100001 0B1100001      1100001 0b1100001
    4444
    4545char *
    46 abcd "abcd"     abcd   "abcd"   abcd abcd     "abcd" 
    47 abcd "abcd"     abcd   "abcd"   abcd abcd     "abcd" 
     46abcd "abcd"     abcd   "abcd"   'abcd'   <abcd>   abcd abcd     "abcd" 
     47abcd "abcd"     abcd   "abcd"   'abcd'   <abcd>   abcd abcd     "abcd" 
    4848141 142 143 144 0141 0142 0143 0144      141      142      143      144 0141     0142     0143     0144   
    494961 62 63 64 0X61 0X62 0X63 0X64       61       62       63       64 0x61     0x62     0x63     0x64   
  • tests/io/.expect/manipulatorsOutput1.x64.txt

    r8403b32 rbb1eabc  
    3838
    3939char
    40 a'a' ' '       a     'a'    aa   
    41 a'a' ' '       a     'a'    aa   
     40a'a' ' '"a"<a>       a     'a'     "a"     {a}    aa   
     41a'a' ' '"a"<a>       a     'a'     "a"     {a}    aa   
    4242141 0141      141 0141     61 0x61       61 0x61   
    4343141 0141      141 0141     61 0X61       61 0x61     1100001 0B1100001      1100001 0b1100001
    4444
    4545char *
    46 abcd "abcd"     abcd   "abcd"   abcd abcd     "abcd" 
    47 abcd "abcd"     abcd   "abcd"   abcd abcd     "abcd" 
     46abcd "abcd"     abcd   "abcd"   'abcd'   <abcd>   abcd abcd     "abcd" 
     47abcd "abcd"     abcd   "abcd"   'abcd'   <abcd>   abcd abcd     "abcd" 
    4848141 142 143 144 0141 0142 0143 0144      141      142      143      144 0141     0142     0143     0144   
    494961 62 63 64 0X61 0X62 0X63 0X64       61       62       63       64 0x61     0x62     0x63     0x64   
  • tests/io/.expect/manipulatorsOutput1.x86.txt

    r8403b32 rbb1eabc  
    3838
    3939char
    40 a'a' ' '       a     'a'    aa   
    41 a'a' ' '       a     'a'    aa   
     40a'a' ' '"a"<a>       a     'a'     "a"     {a}    aa   
     41a'a' ' '"a"<a>       a     'a'     "a"     {a}    aa   
    4242141 0141      141 0141     61 0x61       61 0x61   
    4343141 0141      141 0141     61 0X61       61 0x61     1100001 0B1100001      1100001 0b1100001
    4444
    4545char *
    46 abcd "abcd"     abcd   "abcd"   abcd abcd     "abcd" 
    47 abcd "abcd"     abcd   "abcd"   abcd abcd     "abcd" 
     46abcd "abcd"     abcd   "abcd"   'abcd'   <abcd>   abcd abcd     "abcd" 
     47abcd "abcd"     abcd   "abcd"   'abcd'   <abcd>   abcd abcd     "abcd" 
    4848141 142 143 144 0141 0142 0143 0144      141      142      143      144 0141     0142     0143     0144   
    494961 62 63 64 0X61 0X62 0X63 0X64       61       62       63       64 0x61     0x62     0x63     0x64   
  • tests/io/manipulatorsOutput1.cfa

    r8403b32 rbb1eabc  
    77// Created On       : Sat Jun  8 18:04:11 2019
    88// Last Modified By : Peter A. Buhr
    9 // Last Modified On : Sat May  2 18:50:48 2026
    10 // Update Count     : 65
     9// Last Modified On : Sun May  3 23:31:09 2026
     10// Update Count     : 76
    1111//
    1212
     
    100100
    101101        sout | nl | "char";
    102         char c = 'a', * qc = "'a'";
    103         printf( "%c%s%c'%c'%8c%8s%5c%-5c\n", c, qc, ' ', ' ', c, qc, c, c );
    104         sout | c | quote(c) | ' ' | quote(' ') | wd(8,c) | quote( wd(8,c) ) | wd(5,c) | left(wd(5,c));
     102        char c = 'a';
     103        printf( "%c'%c'%c'%c'\"%c\"<%c>%8c%8s%8s%8s%5c%-5c\n", c, c, ' ', ' ', c, c, c, "'a'", "\"a\"", "{a}", c, c );
     104        sout | c | quote(c) | ' ' | quote(' ') | quote( c, '"' ) | quote( c, '<', '>' )
     105                 | wd(8,c) | quote( wd(8,c) ) | quote( wd(8,c), '"' ) | quote( wd(8,c), '{', '}' ) | wd(5,c) | left(wd(5,c));
    105106        printf( "%hho %#hho %8hho %#-8hho %hhx %#hhx %8hhx %#-8hhx\n", c, c, c, c, c, c, c, c );
    106107        sout | nobase(oct(c)) | upcase(oct(c)) | nobase(wd(8,oct(c))) | left(wd(-8,oct(c))) | nonl;
     
    109110
    110111        sout | nl | "char *";
    111         const char * s = "abcd", * qs = "\"abcd\"";
    112         printf( "%s %s %8s %8s %6.8s %-8s %-8s\n", s, qs, s, qs, s, s, qs );
    113         sout | s | quote( s ) | wd(8,s) | quote(wd(8,s)) | wd(6,8,s) | left(wd(8,s)) | quote(left(wd(8,s)));
    114         sout | nobase(oct(s)) | upcase(oct(s)) | nobase(wd(8,oct(s))) | left(wd(-8,oct(s)));
    115         sout | nobase(hex(s)) | upcase(hex(s)) | nobase(wd(8,hex(s))) | left(wd(-8,hex(s)));
    116         sout | nobase(bin(s)) | upcase(bin(s)) | nobase(wd(12,bin(s))) | left(wd(-12,bin(s)));
     112        const char * cs = "abcd";
     113        printf( "%s %s %8s %8s %8s %8s %6.8s %-8s %-8s\n", cs, "\"abcd\"", cs, "\"abcd\"", "'abcd'", "<abcd>", cs, cs, "\"abcd\"" );
     114        sout | cs | quote(cs) | wd(8,cs) | quote(wd(8,cs)) | quote(wd(8,cs), '\'')| quote(wd(8,cs), '<', '>')
     115                 | wd(6,8,cs) | left(wd(8,cs)) | quote(left(wd(8,cs)));
     116        sout | nobase(oct(cs)) | upcase(oct(cs)) | nobase(wd(8,oct(cs))) | left(wd(-8,oct(cs)));
     117        sout | nobase(hex(cs)) | upcase(hex(cs)) | nobase(wd(8,hex(cs))) | left(wd(-8,hex(cs)));
     118        sout | nobase(bin(cs)) | upcase(bin(cs)) | nobase(wd(12,bin(cs))) | left(wd(-12,bin(cs)));
    117119}
    118120
Note: See TracChangeset for help on using the changeset viewer.