Changeset 7abc3de for libcfa


Ignore:
Timestamp:
Jan 17, 2024, 6:31:03 PM (3 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
906d8fa
Parents:
11f65b3
Message:

Harmonize string constructors with assignments, refactor implementations to include string_res, add missing tests

Location:
libcfa/src/collections
Files:
3 edited

Legend:

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

    r11f65b3 r7abc3de  
    4545}
    4646
     47void ?{}( string & s, const string & s2, size_t maxlen) {
     48    (s.inner) { malloc() };
     49    ?{}( *s.inner, *s2.inner, COPY_VALUE, maxlen );
     50}
     51
     52
    4753void ?{}( string & s, string & c ) {
    4854    ?{}( s, (const string &) c );
     
    5157void ?{}( string & s, const char c ) {
    5258    (s.inner) { malloc() };
    53         char cs[2] = { c, '\0' };
    54     ?{}( *s.inner, cs );
     59    ?{}( *s.inner, c );
    5560}
    5661
  • libcfa/src/collections/string.hfa

    r11f65b3 r7abc3de  
    3434void ?{}(string & s); // empty string
    3535void ?{}(string & s, const string & s2);
     36void ?{}(string & s, const string & s2, size_t maxlen);
    3637void ?{}(string & s, string & s2);
    3738
  • libcfa/src/collections/string_res.hfa

    r11f65b3 r7abc3de  
    7878    (s){ rhs, strlen(rhs) };
    7979}
    80 
     80static inline void ?{}(string_res & s, char c ) {
     81    ?{}( s, &c, 1);
     82}
     83
     84// Deleting the copy constructors makes the compiler reject an attempt to call/return by value
    8185void ?{}(string_res & s, const string_res & s2) = void;
    8286void ?{}(string_res & s, string_res & s2) = void;
     
    8690static inline void ?{}(string_res & s, const string_res & src, StrResInitMode mode ) {
    8791    ?{}( s, src, mode, 0, size(src));
     92}
     93static inline void ?{}(string_res & s, const string_res & src, StrResInitMode mode, size_t maxlen ) {
     94    ?{}( s, src, mode, 0, (size(src) > maxlen)?maxlen:size(src) );
    8895}
    8996
Note: See TracChangeset for help on using the changeset viewer.