Changeset b2906c0 in mainline


Ignore:
Timestamp:
2017-07-11T18:44:04Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f3504c1
Parents:
9bf4488
Message:

One function to compute the number of code units in a UTF-16 null-terminated string.

Location:
uspace
Files:
9 edited

Legend:

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

    r9bf4488 rb2906c0  
    995995        dest[idx] = '\0';
    996996        return rc;
     997}
     998
     999/** Get size of UTF-16 string.
     1000 *
     1001 * Get the number of words which are used by the UTF-16 string @a ustr
     1002 * (excluding the NULL-terminator).
     1003 *
     1004 * @param ustr UTF-16 string to consider.
     1005 *
     1006 * @return Number of words used by the UTF-16 string
     1007 *
     1008 */
     1009size_t utf16_wsize(const uint16_t *ustr)
     1010{
     1011        size_t wsize = 0;
     1012
     1013        while (*ustr++ != 0)
     1014                wsize++;
     1015
     1016        return wsize;
    9971017}
    9981018
  • uspace/lib/c/include/str.h

    r9bf4488 rb2906c0  
    9999extern int utf16_to_str(char *dest, size_t size, const uint16_t *src);
    100100extern int str_to_utf16(uint16_t *dest, size_t dlen, const char *src);
     101extern size_t utf16_wsize(const uint16_t *ustr);
    101102
    102103extern char *str_chr(const char *str, wchar_t ch);
  • uspace/srv/fs/exfat/exfat_dentry.c

    r9bf4488 rb2906c0  
    130130}
    131131
    132 size_t exfat_utf16_length(const uint16_t *wstr)
    133 {
    134         size_t len = 0;
    135        
    136         while (*wstr++ != 0)
    137                 len++;
    138        
    139         return len;
    140 }
    141 
    142132/**
    143133 * @}
  • uspace/srv/fs/exfat/exfat_dentry.h

    r9bf4488 rb2906c0  
    161161extern bool exfat_valid_name(const char *);
    162162
    163 extern size_t exfat_utf16_length(const uint16_t *);
    164 
    165 
    166163#endif
    167164
  • uspace/srv/fs/exfat/exfat_directory.c

    r9bf4488 rb2906c0  
    371371        ds.stream.valid_data_size = 0;
    372372        ds.stream.data_size = 0;
    373         ds.stream.name_size = exfat_utf16_length(wname);
     373        ds.stream.name_size = utf16_wsize(wname);
    374374        ds.stream.hash = host2uint16_t_le(exfat_name_hash(wname, uctable,
    375375            uctable_chars));
  • uspace/srv/fs/fat/fat_dentry.c

    r9bf4488 rb2906c0  
    427427}
    428428
    429 size_t utf16_length(const uint16_t *wstr)
    430 {
    431         size_t len = 0;
    432        
    433         while (*wstr++ != 0)
    434                 len++;
    435        
    436         return len;
    437 }
    438 
    439429/**
    440430 * @}
  • uspace/srv/fs/fat/fat_dentry.h

    r9bf4488 rb2906c0  
    152152
    153153extern void str_to_ascii(char *, const char *, size_t, uint8_t);
    154 extern size_t utf16_length(const uint16_t *);
    155154
    156155extern bool fat_valid_name(const char *);
  • uspace/srv/fs/fat/fat_directory.c

    r9bf4488 rb2906c0  
    301301                        return rc;
    302302               
    303                 lfn_size = utf16_length(wname);
     303                lfn_size = utf16_wsize(wname);
    304304                long_entry_count = lfn_size / FAT_LFN_ENTRY_SIZE;
    305305                if (lfn_size % FAT_LFN_ENTRY_SIZE)
  • uspace/srv/fs/udf/udf_osta.c

    r9bf4488 rb2906c0  
    5151#include "udf_osta.h"
    5252#include "udf_cksum.h"
    53 
    54 /** Calculate length of UTF-16 string
    55  *
    56  * FIXME: This is wrong! UTF-16 is not a fixed-width encoding,
    57  *        it is a variable-width encoding (mind the surrogate
    58  *        pairs).
    59  *
    60  */
    61 static size_t utf16_length(uint16_t *string) {
    62         size_t len = 0;
    63        
    64         while (*string++ != 0)
    65                 len++;
    66        
    67         return len;
    68 }
    6953
    7054/** Illegal UNIX characters are NULL and slash.
     
    296280                ucode_chars =
    297281                    udf_uncompress_unicode(len, (uint8_t *) id, raw_name, MAX_BUF);
    298                 ucode_chars = min(ucode_chars, utf16_length(raw_name));
     282                ucode_chars = min(ucode_chars, utf16_wsize(raw_name));
    299283                nice_uchars =
    300284                    udf_translate_name(unix_name, raw_name, ucode_chars);
Note: See TracChangeset for help on using the changeset viewer.