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

Implement string initialization and assignment from various numeric types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 ) {
Note: See TracChangeset for help on using the changeset viewer.