Changeset fc97128 in mainline


Ignore:
Timestamp:
2011-07-07T19:56:00Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
411e9ca
Parents:
042a725
Message:

Update to str.h: new function str_to_utf16

Location:
uspace/lib/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/str.c

    r042a725 rfc97128  
    633633        return rc;
    634634}
     635
     636int str_to_utf16(uint16_t *dest, size_t size, const char *src)
     637{
     638        int rc=EOK;
     639        size_t offset=0;
     640        size_t idx=0;
     641        wchar_t c;
     642
     643        assert(size > 0);
     644       
     645        while ((c = str_decode(src, &offset, STR_NO_LIMIT)) != 0) {
     646                if (c > 0x10000) {
     647                        if (idx+2 >= size-1) {
     648                                rc=EOVERFLOW;
     649                                break;
     650                        }
     651                        c = (c - 0x10000);
     652                        dest[idx] = 0xD800 | (c >> 10);
     653                        dest[idx+1] = 0xDC00 | (c & 0x3FF);
     654                        idx++;
     655                } else {
     656                         dest[idx] = c;
     657                }
     658
     659                idx++;
     660                if (idx >= size-1) {
     661                        rc=EOVERFLOW;
     662                        break;
     663                }
     664        }
     665
     666        dest[idx] = '\0';
     667        return rc;
     668}
     669
    635670
    636671/** Convert wide string to new string.
  • uspace/lib/c/include/str.h

    r042a725 rfc97128  
    7979extern int str_to_wstr(wchar_t *dest, size_t dlen, const char *src);
    8080extern int utf16_to_str(char *dest, size_t size, const uint16_t *src);
     81extern int str_to_utf16(uint16_t *dest, size_t size, const char *src);
    8182
    8283extern char *str_chr(const char *str, wchar_t ch);
Note: See TracChangeset for help on using the changeset viewer.