diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2011-01-19 20:22:04 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2011-01-19 20:22:04 +0200 |
commit | b4a1aa90519d34c87b3a6699b77a24f39b1b22c1 (patch) | |
tree | 572747fc4d6f256b7383be2c26cfb57dea15c010 /node.c | |
parent | 32b060d8f0069ad0083ad19d1d095d8ea69f0f45 (diff) | |
download | egawk-b4a1aa90519d34c87b3a6699b77a24f39b1b22c1.tar.gz egawk-b4a1aa90519d34c87b3a6699b77a24f39b1b22c1.tar.bz2 egawk-b4a1aa90519d34c87b3a6699b77a24f39b1b22c1.zip |
Simplify code for do_tolower, do_toupper.
Diffstat (limited to 'node.c')
-rw-r--r-- | node.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -761,6 +761,47 @@ str2wstr(NODE *n, size_t **ptr) return n; } +/* wstr2str --- convert a wide string back into multibyte one */ + +NODE * +wstr2str(NODE *n) +{ + size_t result; + size_t length; + wchar_t *wp; + mbstate_t mbs; + char *newval, *cp; + + assert(n->valref == 1); + assert((n->flags & WSTRCUR) != 0); + + /* + * Convert the wide chars in t1->wstptr back into m.b. chars. + * This is pretty grotty, but it's the most straightforward + * way to do things. + */ + memset(& mbs, 0, sizeof(mbs)); + + length = n->wstlen; + emalloc(newval, char *, (length * gawk_mb_cur_max) + 2, "wstr2str"); + + wp = n->wstptr; + for (cp = newval; length > 0; length--) { + result = wcrtomb(cp, *wp, & mbs); + if (result == (size_t) -1) /* what to do? break seems best */ + break; + cp += result; + wp++; + } + *cp = '\0'; + + efree(n->stptr); + n->stptr = newval; + n->stlen = cp - newval; + + return n; +} + /* free_wstr --- release the wide string part of a node */ void |