Changeset 479fbe3 for libcfa/src


Ignore:
Timestamp:
Jan 14, 2024, 5:48:00 PM (5 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
739495a
Parents:
5ecaeca
Message:

formatting, add string constructor for char, add string *= operator, simplify ?+? and ?*? operations

Location:
libcfa/src/collections
Files:
2 edited

Legend:

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

    r5ecaeca r479fbe3  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan  4 11:27:37 2024
    13 // Update Count     : 233
     12// Last Modified On : Sun Jan 14 12:03:47 2024
     13// Update Count     : 240
    1414//
    1515
     
    2929// string RAII
    3030
    31 
    32 void ?{}( string & s ) {
    33     (s.inner) { malloc() };
    34     ?{}( *s.inner );
    35 }
    36 
    3731// private (not in header)
    3832static void ?{}( string & s, string_res & src, size_t start, size_t end ) {
     
    4135}
    4236
     37void ?{}( string & s ) {
     38    (s.inner) { malloc() };
     39    ?{}( *s.inner );
     40}
     41
    4342void ?{}( string & s, const string & c ) {
    4443    (s.inner) { malloc() };
     
    5049}
    5150
    52 void ?{}( string & s, const char * val ) {
    53     (s.inner) { malloc() };
    54     ?{}( *s.inner, val );
    55 }
    56 
    57 void ?{}( string & s, const char * buffer, size_t bsize) {
    58     (s.inner) { malloc() };
    59     ?{}( *s.inner, buffer, bsize );
     51void ?{}( string & s, const char c ) {
     52    (s.inner) { malloc() };
     53        char cs[2] = { c, '\0' };
     54    ?{}( *s.inner, cs );
     55}
     56
     57void ?{}( string & s, const char * c ) {
     58    (s.inner) { malloc() };
     59    ?{}( *s.inner, c );
     60}
     61
     62void ?{}( string & s, const char * c, size_t size) {
     63    (s.inner) { malloc() };
     64    ?{}( *s.inner, c, size );
    6065}
    6166
     
    237242}
    238243
    239 string ?*?(char c, size_t size) {
    240     string ret = "";
    241     for ((size_t)size) ret += c;
    242     return ret;
    243 }
    244 
    245 string ?*?(const char *s, size_t factor) {
    246     string ss = s;
    247     return ss * factor;
     244void ?*=?(string & s, size_t factor) {
     245    s = s * factor;
     246}
     247
     248string ?*?(char c, size_t factor) {
     249    string ret = c;
     250    return ret * factor;
     251}
     252
     253string ?*?(const char * s, size_t factor) {
     254    string ret = s;
     255    return ret * factor;
    248256}
    249257
  • libcfa/src/collections/string.hfa

    r5ecaeca r479fbe3  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan  4 11:27:35 2024
    13 // Update Count     : 75
     12// Last Modified On : Sun Jan 14 12:03:46 2024
     13// Update Count     : 81
    1414//
    1515
     
    3333// RAII, assignment
    3434void ?{}(string & s); // empty string
    35 void ?{}(string & s, const char * initial); // copy from string literal (NULL-terminated)
    36 void ?{}(string & s, const char * buffer, size_t bsize); // copy specific length from buffer
    37 
    3835void ?{}(string & s, const string & s2);
    3936void ?{}(string & s, string & s2);
    4037
     38void ?{}(string & s, const char);
     39void ?{}(string & s, const char * c); // copy from string literal (NULL-terminated)
     40void ?{}(string & s, const char * c, size_t size); // copy specific length from buffer
     41
    4142void ?=?(string & s, const char * c); // copy assignment from literal
    4243static inline string & strcpy(string & s, const char * c) { s = c; return s; }
     44static inline string & strncpy(string & s, const char * c, size_t n) { s = c; return s; }
    4345void ?=?(string & s, const string & c);
    4446static inline string & strcpy(string & s, const string c) { s = c; return s; }
     
    112114// Repetition
    113115string ?*?(const string & s, size_t factor);
    114 string ?*?(char c, size_t size);
    115 string ?*?(const char *s, size_t size);
     116void ?*=?(string & s, size_t factor);
     117string ?*?(char c, size_t factor);
     118string ?*?(const char *s, size_t factor);
    116119
    117120// Character access
Note: See TracChangeset for help on using the changeset viewer.