Changeset f2898df for libcfa


Ignore:
Timestamp:
Jan 19, 2024, 5:25:28 PM (3 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
8abe4090, a4ed165
Parents:
dd10bf4
Message:

Implement string initialization and assignment from various numeric types

Location:
libcfa/src/collections
Files:
4 edited

Legend:

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

    rdd10bf4 rf2898df  
    7070}
    7171
     72void ?{}( string & s, ssize_t rhs ) {
     73    (s.inner) { malloc() };
     74    ?{}( *s.inner, rhs );
     75}
     76
     77void ?{}( string & s, size_t rhs ) {
     78    (s.inner) { malloc() };
     79    ?{}( *s.inner, rhs );
     80}
     81
     82void ?{}( string & s, double rhs ) {
     83    (s.inner) { malloc() };
     84    ?{}( *s.inner, rhs );
     85}
     86
     87void ?{}( string & s, long double rhs ) {
     88    (s.inner) { malloc() };
     89    ?{}( *s.inner, rhs );
     90}
     91
     92void ?{}( string & s, double _Complex rhs ) {
     93    (s.inner) { malloc() };
     94    ?{}( *s.inner, rhs );
     95}
     96
     97void ?{}( string & s, long double _Complex rhs ) {
     98    (s.inner) { malloc() };
     99    ?{}( *s.inner, rhs );
     100}
     101
    72102void ^?{}( string & s ) {
    73103    ^(*s.inner){};
     
    121151}
    122152
     153string & ?=?( string & s, ssize_t rhs ) {
     154    (*s.inner) = rhs;
     155    return s;
     156}
     157
     158string & ?=?( string & s, size_t rhs ) {
     159    (*s.inner) = rhs;
     160    return s;
     161}
     162
     163string & ?=?( string & s, double rhs ) {
     164    (*s.inner) = rhs;
     165    return s;
     166}
     167
     168string & ?=?( string & s, long double rhs ) {
     169    (*s.inner) = rhs;
     170    return s;
     171}
     172
     173string & ?=?( string & s, double _Complex rhs ) {
     174    (*s.inner) = rhs;
     175    return s;
     176}
     177
     178string & ?=?( string & s, long double _Complex rhs ) {
     179    (*s.inner) = rhs;
     180    return s;
     181}
    123182
    124183////////////////////////////////////////////////////////
  • libcfa/src/collections/string.hfa

    rdd10bf4 rf2898df  
    4040void ?{}(string & s, const char * c); // copy from string literal (NULL-terminated)
    4141void ?{}(string & s, const char * c, size_t size); // copy specific length from buffer
     42
     43void ?{}( string & s, ssize_t rhs );
     44void ?{}( string & s, size_t rhs );
     45void ?{}( string & s, double rhs );
     46void ?{}( string & s, long double rhs );
     47void ?{}( string & s, double _Complex rhs );
     48void ?{}( string & s, long double _Complex rhs );
    4249
    4350string & ?=?(string & s, const string & c);
     
    5259static inline string & strcpy(string & s, const string & c) { s = c; return s; }
    5360static inline string & strncpy(string & s, const string & c, size_t n) { assign(s, c, n); return s; }
     61
     62string & ?=?( string & s, ssize_t rhs );
     63string & ?=?( string & s, size_t rhs );
     64string & ?=?( string & s, double rhs );
     65string & ?=?( string & s, long double rhs );
     66string & ?=?( string & s, double _Complex rhs );
     67string & ?=?( string & s, long double _Complex rhs );
    5468
    5569void ^?{}(string & s);
  • libcfa/src/collections/string_res.cfa

    rdd10bf4 rf2898df  
    2525
    2626#include <assert.h>
     27#include <complex.h>                           // creal, cimag
    2728
    2829//######################### VbyteHeap "header" #########################
     
    333334void ?{}(string_res & s, const char * rhs, size_t rhslnth) with(s) {
    334335    eagerCopyCtorHelper(s, rhs, rhslnth);
     336}
     337
     338void ?{}( string_res & s, ssize_t rhs ) {
     339    char buf[64];
     340    int len;
     341    snprintf( buf, sizeof(buf)-1, "%zd%n", rhs, &len );
     342    ( s ){ buf, len };
     343}
     344void ?{}( string_res & s, size_t rhs ) {
     345    char buf[64];
     346    int len;
     347    snprintf( buf, sizeof(buf)-1, "%zu%n", rhs, &len );
     348    ( s ){ buf, len };
     349}
     350void ?{}( string_res & s, double rhs ) {
     351    char buf[64];
     352    int len;
     353    snprintf( buf, sizeof(buf)-1, "%g%n", rhs, &len );
     354    ( s ){ buf, len };
     355}
     356void ?{}( string_res & s, long double rhs ) {
     357    char buf[64];
     358    int len;
     359    snprintf( buf, sizeof(buf)-1, "%Lg%n", rhs, &len );
     360    ( s ){ buf, len };
     361}
     362void ?{}( string_res & s, double _Complex rhs ) {
     363    char buf[64];
     364    int len;
     365    snprintf( buf, sizeof(buf)-1, "%g+%gi%n", creal( rhs ), cimag( rhs ), &len );
     366    ( s ){ buf, len };
     367}
     368void ?{}( string_res & s, long double _Complex rhs ) {
     369    char buf[64];
     370    int len;
     371    snprintf( buf, sizeof(buf)-1, "%Lg+%Lgi%n", creall( rhs ), cimagl( rhs ), &len );
     372    ( s ){ buf, len };
    335373}
    336374
     
    577615}
    578616
     617string_res & ?=?( string_res & s, ssize_t rhs ) {
     618    string_res rhs2 = rhs;
     619    s = rhs2;
     620    return s;
     621}
     622string_res & ?=?( string_res & s, size_t rhs ) {
     623    string_res rhs2 = rhs;
     624    s = rhs2;
     625    return s;
     626}
     627string_res & ?=?( string_res & s, double rhs ) {
     628    string_res rhs2 = rhs;
     629    s = rhs2;
     630    return s;
     631}
     632string_res & ?=?( string_res & s, long double rhs ) {
     633    string_res rhs2 = rhs;
     634    s = rhs2;
     635    return s;
     636}
     637string_res & ?=?( string_res & s, double _Complex rhs ) {
     638    string_res rhs2 = rhs;
     639    s = rhs2;
     640    return s;
     641}
     642string_res & ?=?( string_res & s, long double _Complex rhs ) {
     643    string_res rhs2 = rhs;
     644    s = rhs2;
     645    return s;
     646}
     647
    579648// Copy assignment operator
    580649string_res & ?=?(string_res & s, const string_res & rhs) with( s ) {
  • libcfa/src/collections/string_res.hfa

    rdd10bf4 rf2898df  
    9494    ?{}( s, src, mode, 0, (size(src) > maxlen)?maxlen:size(src) );
    9595}
     96void ?{}( string_res & s, ssize_t rhs );
     97void ?{}( string_res & s, size_t rhs );
     98void ?{}( string_res & s, double rhs );
     99void ?{}( string_res & s, long double rhs );
     100void ?{}( string_res & s, double _Complex rhs );
     101void ?{}( string_res & s, long double _Complex rhs );
    96102
    97103string_res & assign(string_res & s, const string_res & src, size_t maxlen); // copy specific length from other string
     
    103109string_res & ?=?(string_res & s, string_res & c);
    104110string_res & ?=?(string_res & s, char c);
     111
     112string_res & ?=?( string_res & s, ssize_t rhs );
     113string_res & ?=?( string_res & s, size_t rhs );
     114string_res & ?=?( string_res & s, double rhs );
     115string_res & ?=?( string_res & s, long double rhs );
     116string_res & ?=?( string_res & s, double _Complex rhs );
     117string_res & ?=?( string_res & s, long double _Complex rhs );
    105118
    106119void ^?{}(string_res & s);
Note: See TracChangeset for help on using the changeset viewer.