View Issue Details

IDProjectCategoryView StatusLast Update
0000436LDMud 3.5Efunspublic2019-09-24 08:24
Reporteriago3Assigned ToGnomi  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Summary0000436: New efun: mbstowcs()
Description/*-------------------------------------------------------------------------*/
svalue_t *
f_mbstowcs (svalue_t * sp)

/* EFUN mbstowcs()
 *
 * int *mbstowcs(string str)
 *
 * Takes a multibyte string and returns an array of wide characters
 */

{
    vector_t *vec;
    svalue_t *svp;
    wchar_t *wcdest;
    char *orig_txt, **orig_txt_ptr, *tmp_txt;
    size_t tmp_len, len, wcdest_len, orig_len, i;
    orig_len=mstrsize(sp->u.str);
    orig_txt=get_txt(sp->u.str);
    orig_txt_ptr=xalloc(sizeof(char *));
    wcdest=xalloc((orig_len+1)*sizeof(wchar_t));
    memset(wcdest,0,(orig_len+1)*sizeof(wchar_t));
    wcdest_len=0;
    *orig_txt_ptr=orig_txt;
    len=0;
    tmp_txt=orig_txt;
    while(len<orig_len) {
        tmp_len=mbsrtowcs(wcdest+wcdest_len, (const char **)orig_txt_ptr, orig_len-len, (mbstate_t *)NULL);
        if(tmp_len==(size_t)-1) {
            xfree(orig_txt_ptr);
            xfree(wcdest);
                errorf("Bad argument 1 to mbstowcs(): String contains invalid multibyte encoding\n");
        }
        wcdest_len+=tmp_len;
        len+=strlen(tmp_txt);
        if(len<orig_len) {
            len++;
            wcdest_len++;
            tmp_txt=orig_txt+len;
            *orig_txt_ptr=tmp_txt;
        }
    }
    vec=allocate_array(wcdest_len);
    svp=vec->item;
    for(i=0;i<wcdest_len;i++) {
        vec->item[i].type=T_NUMBER;
        vec->item[i].u.number=(unsigned long int)*(wcdest+i);
    }
    xfree(orig_txt_ptr);
    xfree(wcdest);
    free_string_svalue(sp);
    put_array(sp, vec);
    return sp;
} /* f_mbstowcs() */
TagsNo tags attached.

Relationships

child of 0000432 resolvedGnomi LDMud 3.6 Add string efuns with multibyte character support 

Activities

iago3

2006-01-06 19:48

reporter   ~0000467

Explainer: This bug is desinged to add support for multibyte character sets to string efuns, as designed in bug#432

Gnomi

2019-09-24 08:24

manager   ~0002479

Implemented as efun to_array().

Issue History

Date Modified Username Field Change
2006-01-06 19:40 iago3 New Issue
2006-01-06 19:48 iago3 Note Added: 0000467
2008-07-02 01:15 Gnomi Project LDMud => LDMud 3.5
2008-07-02 01:17 Gnomi Relationship added child of 0000432
2019-09-24 08:24 Gnomi Assigned To => Gnomi
2019-09-24 08:24 Gnomi Status new => closed
2019-09-24 08:24 Gnomi Resolution open => fixed
2019-09-24 08:24 Gnomi Note Added: 0002479