Ignore:
File:
1 edited

Legend:

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

    r8e893ae rd7f6248  
    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
    5548
    5649/** Byte mask consisting of lowest @n bits (out of 8) */
     
    268261}
    269262
    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  */
    281 size_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  */
    302 size_t wstr_nsize(const wchar_t *str, size_t max_size)
    303 {
    304         return (wstr_nlength(str, max_size) * sizeof(wchar_t));
    305 }
    306 
    307263/** Get size of wide string with length limit.
    308264 *
     
    406362bool ascii_check(wchar_t ch)
    407363{
    408         if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
     364        if ((ch >= 0) && (ch <= 127))
    409365                return true;
    410366       
     
    419375bool chr_check(wchar_t ch)
    420376{
    421         if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
     377        if ((ch >= 0) && (ch <= 1114111))
    422378                return true;
    423379       
     
    520476 * @param count Size of the destination buffer (must be > 0).
    521477 * @param src   Source string.
    522  *
    523478 */
    524479void str_cpy(char *dest, size_t size, const char *src)
     
    553508 * @param src   Source string.
    554509 * @param n     Maximum number of bytes to read from @a src.
    555  *
    556510 */
    557511void str_ncpy(char *dest, size_t size, const char *src, size_t n)
     
    885839       
    886840        return NULL;
    887 }
    888 
    889 /** Removes specified trailing characters from a string.
    890  *
    891  * @param str String to remove from.
    892  * @param ch  Character to remove.
    893  */
    894 void str_rtrim(char *str, wchar_t ch)
    895 {
    896         size_t off = 0;
    897         size_t pos = 0;
    898         wchar_t c;
    899         bool update_last_chunk = true;
    900         char *last_chunk = NULL;
    901 
    902         while ((c = str_decode(str, &off, STR_NO_LIMIT))) {
    903                 if (c != ch) {
    904                         update_last_chunk = true;
    905                         last_chunk = NULL;
    906                 } else if (update_last_chunk) {
    907                         update_last_chunk = false;
    908                         last_chunk = (str + pos);
    909                 }
    910                 pos = off;
    911         }
    912 
    913         if (last_chunk)
    914                 *last_chunk = '\0';
    915 }
    916 
    917 /** Removes specified leading characters from a string.
    918  *
    919  * @param str String to remove from.
    920  * @param ch  Character to remove.
    921  */
    922 void str_ltrim(char *str, wchar_t ch)
    923 {
    924         wchar_t acc;
    925         size_t off = 0;
    926         size_t pos = 0;
    927         size_t str_sz = str_size(str);
    928 
    929         while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
    930                 if (acc != ch)
    931                         break;
    932                 else
    933                         pos = off;
    934         }
    935 
    936         if (pos > 0) {
    937                 memmove(str, &str[pos], str_sz - pos);
    938                 pos = str_sz - pos;
    939                 str[str_sz - pos] = '\0';
    940         }
    941841}
    942842
     
    15441444 *
    15451445 */
    1546 int str_uint64_t(const char *nptr, char **endptr, unsigned int base,
     1446int str_uint64(const char *nptr, char **endptr, unsigned int base,
    15471447    bool strict, uint64_t *result)
    15481448{
Note: See TracChangeset for help on using the changeset viewer.