Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/iostream.c

    r53ba273 re945826  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr  6 16:13:29 2016
    13 // Update Count     : 278
     12// Last Modified On : Sat Apr 30 14:00:53 2016
     13// Update Count     : 302
    1414//
    1515
     
    3434ostype * ?|?( ostype *os, short int si ) {
    3535        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    36         sepReset( os );
    3736        prtfmt( os, "%hd", si );
    3837        return os;
     
    4241ostype * ?|?( ostype *os, unsigned short int usi ) {
    4342        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    44         sepReset( os );
    4543        prtfmt( os, "%hu", usi );
    4644        return os;
     
    5048ostype * ?|?( ostype *os, int i ) {
    5149        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    52         sepReset( os );
    5350        prtfmt( os, "%d", i );
    5451        return os;
     
    5855ostype * ?|?( ostype *os, unsigned int ui ) {
    5956        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    60         sepReset( os );
    6157        prtfmt( os, "%u", ui );
    6258        return os;
     
    6662ostype * ?|?( ostype *os, long int li ) {
    6763        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    68         sepReset( os );
    6964        prtfmt( os, "%ld", li );
    7065        return os;
     
    7469ostype * ?|?( ostype *os, unsigned long int uli ) {
    7570        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    76         sepReset( os );
    7771        prtfmt( os, "%lu", uli );
    7872        return os;
     
    8276ostype * ?|?( ostype *os, long long int lli ) {
    8377        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    84         sepReset( os );
    8578        prtfmt( os, "%lld", lli );
    8679        return os;
     
    9083ostype * ?|?( ostype *os, unsigned long long int ulli ) {
    9184        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    92         sepReset( os );
    9385        prtfmt( os, "%llu", ulli );
    9486        return os;
     
    9890ostype * ?|?( ostype *os, float f ) {
    9991        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    100         sepReset( os );
    10192        prtfmt( os, "%g", f );
    10293        return os;
     
    10697ostype * ?|?( ostype *os, double d ) {
    10798        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    108         sepReset( os );
    10999        prtfmt( os, "%.*lg", DBL_DIG, d );
    110100        return os;
     
    114104ostype * ?|?( ostype *os, long double ld ) {
    115105        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    116         sepReset( os );
    117106        prtfmt( os, "%.*Lg", LDBL_DIG, ld );
    118107        return os;
     
    155144                // opening delimiters
    156145                ['('] : Open, ['['] : Open, ['{'] : Open,
    157                 ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
     146                ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open,
     147                [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
    158148                // closing delimiters
    159149                [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
     
    162152                // opening-closing delimiters
    163153                ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose,
    164                 ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace
     154                [' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace
    165155        }; // mask
    166156
    167         int len = strlen( cp );
    168         // null string => no separator
    169   if ( len == 0 ) { sepOff( os ); return os; }
     157  if ( cp[0] == '\0' ) { sepOff( os ); return os; }             // null string => no separator
     158
    170159        // first character IS NOT spacing or closing punctuation => add left separator
    171160        unsigned char ch = cp[0];                                                       // must make unsigned
     
    173162                prtfmt( os, "%s", sepGet( os ) );
    174163        } // if
     164
     165        // if string starts line, must reset to determine open state because separator is off
     166        sepReset( os );                                                                         // reset separator
     167
    175168        // last character IS spacing or opening punctuation => turn off separator for next item
    176         unsigned int posn = len - 1;
     169        unsigned int len = strlen( cp ), posn = len - 1;
    177170        ch = cp[posn];                                                                          // must make unsigned
    178         if ( mask[ ch ] == Open || mask[ ch ] == OpenClose ) {
     171        if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
     172                sepOn( os );
     173        } else {
    179174                sepOff( os );
    180         } else {
    181                 sepOn( os );
    182175        } // if
    183176        return write( os, cp, len );
     
    187180ostype * ?|?( ostype *os, const void *p ) {
    188181        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    189         sepReset( os );
    190182        prtfmt( os, "%p", p );
    191183        return os;
    192184} // ?|?
    193 
    194185
    195186forall( dtype ostype | ostream( ostype ) )
Note: See TracChangeset for help on using the changeset viewer.