Changeset 9ca5e56 for libcfa


Ignore:
Timestamp:
Aug 12, 2023, 3:49:57 PM (16 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
d32679d5
Parents:
43109ce
Message:

formatting, remove superfluous space at end of string when printing, change C for-loops into CFA for-loops

Location:
libcfa/src/containers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/containers/string.cfa

    r43109ce r9ca5e56  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug  7 10:07:26 2023
    13 // Update Count     : 2
     12// Last Modified On : Sat Aug 12 15:24:18 2023
     13// Update Count     : 6
    1414//
    1515
     
    102102// Output
    103103
    104 ofstream & ?|?( ofstream & fs, const string & this ) {
    105     return fs | (*this.inner);
    106 }
    107 
    108 void ?|?( ofstream & fs, const string & this ) {
    109     fs | (*this.inner);
     104ofstream & ?|?( ofstream & out, const string & this ) {
     105    return out | (*this.inner); // print internal string_res
     106}
     107
     108void ?|?( ofstream & out, const string & this ) {
     109    (ofstream &)(out | (*this.inner)); ends( out );
    110110}
    111111
  • libcfa/src/containers/string_res.cfa

    r43109ce r9ca5e56  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 29 09:29:06 2023
    13 // Update Count     : 2
     12// Last Modified On : Sat Aug 12 15:37:47 2023
     13// Update Count     : 10
    1414//
    1515
     
    134134        serr | nlOff;
    135135        serr | " lnth:" | lnth | " s:" | (void *)s | ",\"";
    136         for ( int i = 0; i < lnth; i += 1 ) {
     136        for ( i; lnth ) {
    137137            serr | s[i];
    138138        } // for
     
    198198// Output operator
    199199ofstream & ?|?(ofstream &out, const string_res &s) {
    200     // Store auto-newline state so it can be restored
    201     bool anl = getANL$(out);
    202     nlOff(out);
    203     for (size_t i = 0; i < s.Handle.lnth; i++) {
    204         out | s[i];
    205     }
    206     out | sepVal;
    207     // Re-apply newlines after done, for chaining version
    208     if (anl) nlOn(out);
     200        // CFA string is NOT null terminated, so print exactly lnth characters in a minimum width of 0.
     201        out | wd( 0, s.Handle.lnth, s.Handle.s ) | nonl;
    209202    return out;
    210203}
    211204
    212205void ?|?(ofstream &out, const string_res &s) {
    213     // Store auto-newline state so it can be restored
    214     bool anl = getANL$(out);
    215     if( s.Handle.lnth == 0 ) {
    216         sout | "";
    217     } else {
    218         nlOff(out);
    219         for (size_t i = 0; i < s.Handle.lnth; i++) {
    220             // Need to re-apply on the last output operator, for whole-statement version
    221             if (anl && i == s.Handle.lnth-1) nlOn(out);
    222             out | s[i];
    223         }
    224     }
     206        (ofstream &)(out | s); ends( out );
    225207}
    226208
     
    338320    // adjust all substring string and handle locations, and check if any substring strings are outside the new base string
    339321    char *limit = resultSesStart + resultSesLnth;
    340     for (string_res * p = this.shareEditSet_next; p != &this; p = p->shareEditSet_next) {
     322    for ( string_res * p = this.shareEditSet_next; p != &this; p = p->shareEditSet_next ) {
    341323        verify (p->Handle.s >= beforeBegin);
    342324        if ( p->Handle.s >= afterBegin ) {
     
    396378    string_res * shareEditSetStartPeer = & this;
    397379    string_res * shareEditSetEndPeer = & this;
    398     for (string_res * editPeer = this.shareEditSet_next; editPeer != &this; editPeer = editPeer->shareEditSet_next) {
     380    for ( string_res * editPeer = this.shareEditSet_next; editPeer != &this; editPeer = editPeer->shareEditSet_next ) {
    399381        if ( editPeer->Handle.s < shareEditSetStartPeer->Handle.s ) {
    400382            shareEditSetStartPeer = editPeer;
     
    589571
    590572bool contains(const string_res &s, char ch) {
    591     for (i; size(s)) {
     573    for ( i; size(s) ) {
    592574        if (s[i] == ch) return true;
    593575    }
     
    643625    }
    644626
    645     for (size_t i = fromPos; i < s.Handle.lnth; i++) {
     627    for ( i; fromPos ~ s.Handle.lnth ) {
    646628        size_t remaining = s.Handle.lnth - i;
    647629        // Never going to find the search string if the remaining string is
     
    652634
    653635        bool matched = true;
    654         for (size_t j = 0; j < searchsize; j++) {
     636        for ( j; searchsize ) {
    655637            if (search[j] != s.Handle.s[i + j]) {
    656638                matched = false;
     
    740722
    741723int exclude(const string_res &s, const charclass_res &mask) {
    742     for (int i = 0; i < size(s); i++) {
     724    for ( i; size(s) ) {
    743725        if ( test(mask, s[i]) ) return i;
    744726    }
     
    747729
    748730int include(const string_res &s, const charclass_res &mask) {
    749     for (int i = 0; i < size(s); i++) {
     731    for ( i; size(s) ) {
    750732        if ( ! test(mask, s[i]) ) return i;
    751733    }
     
    775757                for ( HandleNode *ni = HeaderPtr->flink; ni != HeaderPtr; ni = ni->flink ) {
    776758                        serr | "\tnode:" | ni | " lnth:" | ni->lnth | " s:" | (void *)ni->s | ",\"";
    777                         for ( int i = 0; i < ni->lnth; i += 1 ) {
     759                        for ( i; ni->lnth ) {
    778760                                serr | ni->s[i];
    779761                        } // for
     
    881863        for ( HandleNode *n = HeaderPtr->flink; n != HeaderPtr; n = n->flink ) {
    882864            serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\"";
    883             for ( int i = 0; i < n->lnth; i += 1 ) {
    884                 serr | n->s[i];
     865            for ( i; n->lnth ) {
     866                        serr | n->s[i];
    885867            } // for
    886868            serr | "\" flink:" | n->flink | " blink:" | n->blink | nl;
     
    960942    EndVbyte = StartVbyte;
    961943    h = Header.flink;                                   // ignore header node
    962     for (;;) {
     944    for () {
    963945                memmove( EndVbyte, h->s, h->lnth );
    964946                obase = h->s;
     
    971953                // check if any substrings are allocated within a string
    972954               
    973                 for (;;) {
     955                for () {
    974956                        if ( h == &Header ) break;                      // end of header list ?
    975957                        if ( h->s >= limit ) break;                     // outside of current string ?
     
    1001983                        serr | nlOff;
    1002984                        serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\"";
    1003                         for ( int i = 0; i < n->lnth; i += 1 ) {
     985                        for ( i; n->lnth ) {
    1004986                                serr | n->s[i];
    1005987                        } // for
     
    10361018                        serr | nlOff;
    10371019                        serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\"";
    1038                         for ( int i = 0; i < n->lnth; i += 1 ) {
     1020                        for ( i; n->lnth ) {
    10391021                                serr | n->s[i];
    10401022                        } // for
  • libcfa/src/containers/string_res.hfa

    r43109ce r9ca5e56  
    99// Author           : Michael L. Brooks
    1010// Created On       : Fri Sep 03 11:00:00 2021
    11 // Last Modified By : Michael L. Brooks
    12 // Last Modified On : Fri Sep 03 11:00:00 2021
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Aug 12 15:45:47 2023
     13// Update Count     : 2
    1414//
    1515
     
    3030    VbyteHeap *ulink;                   // upward link
    3131
    32     char *s;                                            // pointer to byte string
     32    char *s;                                                    // pointer to byte string
    3333    unsigned int lnth;                                  // length of byte string
    3434}; // HandleNode
Note: See TracChangeset for help on using the changeset viewer.