Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset be2a38ad in mainline


Ignore:
Timestamp:
2012-08-16T10:37:59Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
56fd7cf, 7a7b8efa
Parents:
69cf3a4
Message:

Add functions chr_width() and str_width() to determine character and string display width on a character cell display.

Location:
uspace/lib/c
Files:
2 edited

Legend:

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

    r69cf3a4 rbe2a38ad  
    397397       
    398398        return len;
     399}
     400
     401/** Get character display width on a character cell display.
     402 *
     403 * @param ch    Character
     404 * @return      Width of character in cells.
     405 */
     406size_t chr_width(wchar_t ch)
     407{
     408        return 1;
     409}
     410
     411/** Get string display width on a character cell display.
     412 *
     413 * @param str   String
     414 * @return      Width of string in cells.
     415 */
     416size_t str_width(const char *str)
     417{
     418        size_t width = 0;
     419        size_t offset = 0;
     420        wchar_t ch;
     421       
     422        while ((ch = str_decode(str, &offset, STR_NO_LIMIT)) != 0)
     423                width += chr_width(ch);
     424       
     425        return width;
    399426}
    400427
  • uspace/lib/c/include/str.h

    r69cf3a4 rbe2a38ad  
    7373extern size_t wstr_nlength(const wchar_t *str, size_t size);
    7474
     75extern size_t chr_width(wchar_t ch);
     76extern size_t str_width(const char *str);
     77
    7578extern bool ascii_check(wchar_t ch);
    7679extern bool chr_check(wchar_t ch);
Note: See TracChangeset for help on using the changeset viewer.