View Issue Details

IDProjectCategoryView StatusLast Update
0000433LDMud 3.5Efunspublic2019-09-24 10:26
Reporteriago3Assigned ToGnomi  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Summary0000433: New efun: wcslen()
Description==Edits to func_spec=========================================================
int wcslen(string|int*);

==Edits to efuns.c===========================================================

#include <wchar.h>
#include <wctype.h>

/*-------------------------------------------------------------------------*/
svalue_t *
f_wcslen (svalue_t * sp)

/* EFUN wcslen()
 *
 * int wcslen(string str|int *wchars)
 *
 * Returns the number of wide characters in a string or array of wide characters
 */

{
    size_t wcdest_len;
    wcdest_len=0;
    if (sp->type == T_STRING) {
        size_t orig_len, len;
        wchar_t *wcdest;
        char *orig_txt, *tmp_txt, **orig_txt_ptr;
        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));
        len=0;
        tmp_txt=orig_txt;
        *orig_txt_ptr=orig_txt;
        while(len<orig_len) {
            wcdest_len+=mbsrtowcs(wcdest+wcdest_len, (const char **)orig_txt_ptr, orig_len-len, (mbstate_t *)NULL);
            len+=strlen(tmp_txt);
            if(len<orig_len) {
                len++;
                wcdest_len++;
                tmp_txt=orig_txt+len;
                *orig_txt_ptr=tmp_txt;
            }
        }
        xfree(wcdest);
        xfree(orig_txt_ptr);
        free_string_svalue(sp);
        put_number(sp, (p_int)wcdest_len);
    } else if(sp->type == T_POINTER) {
        wcdest_len=VEC_SIZE(sp->u.vec);
        free_svalue(sp);
        put_number(sp,wcdest_len);
    }
    return sp;
} /* f_wcslen() */
TagsNo tags attached.

Relationships

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

Activities

iago3

2006-01-06 20:47

reporter   ~0000464

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

Gnomi

2019-09-24 10:26

manager   ~0002481

Implemented as efun sizeof().

Issue History

Date Modified Username Field Change
2006-01-06 20:36 iago3 New Issue
2006-01-06 20:47 iago3 Note Added: 0000464
2008-07-02 03:15 Gnomi Project LDMud => LDMud 3.5
2008-07-02 03:18 Gnomi Relationship added child of 0000432
2019-09-24 10:26 Gnomi Assigned To => Gnomi
2019-09-24 10:26 Gnomi Status new => closed
2019-09-24 10:26 Gnomi Resolution open => fixed
2019-09-24 10:26 Gnomi Note Added: 0002481