Changeset c6588ce in mainline for uspace/lib/c/generic/str.c


Ignore:
Timestamp:
2012-05-05T08:12:17Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ee04c28
Parents:
2cc7f16 (diff), d21e935c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r2cc7f16 rc6588ce  
    4646#include <mem.h>
    4747#include <str.h>
     48
     49/** Check the condition if wchar_t is signed */
     50#ifdef WCHAR_IS_UNSIGNED
     51        #define WCHAR_SIGNED_CHECK(cond)  (true)
     52#else
     53        #define WCHAR_SIGNED_CHECK(cond)  (cond)
     54#endif
    4855
    4956/** Byte mask consisting of lowest @n bits (out of 8) */
     
    261268}
    262269
     270/** Get size of string with size limit.
     271 *
     272 * Get the number of bytes which are used by the string @a str
     273 * (excluding the NULL-terminator), but no more than @max_size bytes.
     274 *
     275 * @param str      String to consider.
     276 * @param max_size Maximum number of bytes to measure.
     277 *
     278 * @return Number of bytes used by the string
     279 *
     280 */
     281size_t str_nsize(const char *str, size_t max_size)
     282{
     283        size_t size = 0;
     284       
     285        while ((*str++ != 0) && (size < max_size))
     286                size++;
     287       
     288        return size;
     289}
     290
     291/** Get size of wide string with size limit.
     292 *
     293 * Get the number of bytes which are used by the wide string @a str
     294 * (excluding the NULL-terminator), but no more than @max_size bytes.
     295 *
     296 * @param str      Wide string to consider.
     297 * @param max_size Maximum number of bytes to measure.
     298 *
     299 * @return Number of bytes used by the wide string
     300 *
     301 */
     302size_t wstr_nsize(const wchar_t *str, size_t max_size)
     303{
     304        return (wstr_nlength(str, max_size) * sizeof(wchar_t));
     305}
     306
    263307/** Get size of wide string with length limit.
    264308 *
     
    362406bool ascii_check(wchar_t ch)
    363407{
    364         if ((ch >= 0) && (ch <= 127))
     408        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
    365409                return true;
    366410       
     
    375419bool chr_check(wchar_t ch)
    376420{
    377         if ((ch >= 0) && (ch <= 1114111))
     421        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
    378422                return true;
    379423       
     
    476520 * @param count Size of the destination buffer (must be > 0).
    477521 * @param src   Source string.
     522 *
    478523 */
    479524void str_cpy(char *dest, size_t size, const char *src)
     
    508553 * @param src   Source string.
    509554 * @param n     Maximum number of bytes to read from @a src.
     555 *
    510556 */
    511557void str_ncpy(char *dest, size_t size, const char *src, size_t n)
     
    14981544 *
    14991545 */
    1500 int str_uint64(const char *nptr, char **endptr, unsigned int base,
     1546int str_uint64_t(const char *nptr, char **endptr, unsigned int base,
    15011547    bool strict, uint64_t *result)
    15021548{
Note: See TracChangeset for help on using the changeset viewer.