Changeset 0f06dbc in mainline


Ignore:
Timestamp:
2009-11-30T19:16:35Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b67c7d64
Parents:
ba26129
Message:

Rename wstr_nstr() to wstr_to_str() and align it better with the rest of string functions.

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/string.h

    rba26129 r0f06dbc  
    8787extern void str_cpy(char *dest, size_t size, const char *src);
    8888extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
    89 extern void wstr_nstr(char *dst, const wchar_t *src, size_t size);
     89extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
    9090
    9191extern char *str_chr(const char *str, wchar_t ch);
  • kernel/generic/src/console/kconsole.c

    rba26129 r0f06dbc  
    289289                       
    290290                        char tmp[STR_BOUNDS(MAX_CMDLINE)];
    291                         wstr_nstr(tmp, current + beg, position - beg + 1);
     291                        wstr_to_str(tmp, position - beg + 1, current + beg);
    292292                       
    293293                        int found;
     
    665665               
    666666                char cmdline[STR_BOUNDS(MAX_CMDLINE)];
    667                 wstr_nstr(cmdline, tmp, STR_BOUNDS(MAX_CMDLINE));
     667                wstr_to_str(cmdline, STR_BOUNDS(MAX_CMDLINE), tmp);
    668668               
    669669                if ((!kcon) && (len == 4) && (str_lcmp(cmdline, "exit", 4) == 0))
  • kernel/generic/src/lib/string.c

    rba26129 r0f06dbc  
    537537 * null-terminated and containing only complete characters.
    538538 *
    539  * @param dst   Destination buffer.
     539 * @param dest   Destination buffer.
    540540 * @param count Size of the destination buffer (must be > 0).
    541541 * @param src   Source string.
     
    571571 * have to be null-terminated.
    572572 *
    573  * @param dst   Destination buffer.
     573 * @param dest   Destination buffer.
    574574 * @param count Size of the destination buffer (must be > 0).
    575575 * @param src   Source string.
     
    596596}
    597597
    598 /** Copy NULL-terminated wide string to string
    599  *
    600  * Copy source wide string @a src to destination buffer @a dst.
    601  * No more than @a size bytes are written. NULL-terminator is always
    602  * written after the last succesfully copied character (i.e. if the
    603  * destination buffer is has at least 1 byte, it will be always
    604  * NULL-terminated).
    605  *
    606  * @param src   Source wide string.
    607  * @param dst   Destination buffer.
    608  * @param count Size of the destination buffer.
    609  *
    610  */
    611 void wstr_nstr(char *dst, const wchar_t *src, size_t size)
    612 {
    613         /* No space for the NULL-terminator in the buffer */
    614         if (size == 0)
    615                 return;
    616        
     598/** Convert wide string to string.
     599 *
     600 * Convert wide string @a src to string. The output is written to the buffer
     601 * specified by @a dest and @a size. @a size must be non-zero and the string
     602 * written will always be well-formed.
     603 *
     604 * @param dest  Destination buffer.
     605 * @param size  Size of the destination buffer.
     606 * @param src   Source wide string.
     607 */
     608void wstr_to_str(char *dest, size_t size, const wchar_t *src)
     609{
    617610        wchar_t ch;
    618         size_t src_idx = 0;
    619         size_t dst_off = 0;
     611        size_t src_idx;
     612        size_t dest_off;
     613
     614        /* There must be space for a null terminator in the buffer. */
     615        ASSERT(size > 0);
     616
     617        src_idx = 0;
     618        dest_off = 0;
    620619       
    621620        while ((ch = src[src_idx++]) != 0) {
    622                 if (chr_encode(ch, dst, &dst_off, size) != EOK)
     621                if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
    623622                        break;
    624623        }
    625        
    626         if (dst_off >= size)
    627                 dst[size - 1] = 0;
    628         else
    629                 dst[dst_off] = 0;
     624
     625        dest[dest_off] = '\0';
    630626}
    631627
  • uspace/app/bdsh/input.c

    rba26129 r0f06dbc  
    140140                return NULL;
    141141
    142         wstr_nstr(str, ti->buffer, STR_BOUNDS(ti->nc) + 1);
     142        wstr_to_str(str, STR_BOUNDS(ti->nc) + 1, ti->buffer);
    143143
    144144        return str;
  • uspace/app/edit/edit.c

    rba26129 r0f06dbc  
    396396                return NULL;
    397397
    398         wstr_nstr(str, buffer, STR_BOUNDS(wstr_length(buffer)) + 1);
     398        wstr_to_str(str, STR_BOUNDS(wstr_length(buffer)) + 1, buffer);
    399399
    400400        console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
  • uspace/lib/libc/generic/string.c

    rba26129 r0f06dbc  
    471471 * null-terminated and containing only complete characters.
    472472 *
    473  * @param dst   Destination buffer.
     473 * @param dest   Destination buffer.
    474474 * @param count Size of the destination buffer (must be > 0).
    475475 * @param src   Source string.
     
    505505 * have to be null-terminated.
    506506 *
    507  * @param dst   Destination buffer.
     507 * @param dest   Destination buffer.
    508508 * @param count Size of the destination buffer (must be > 0).
    509509 * @param src   Source string.
     
    537537 * null-terminated and containing only complete characters.
    538538 *
    539  * @param dst   Destination buffer.
     539 * @param dest   Destination buffer.
    540540 * @param count Size of the destination buffer.
    541541 * @param src   Source string.
     
    549549}
    550550
    551 /** Copy NULL-terminated wide string to string
    552  *
    553  * Copy source wide string @a src to destination buffer @a dst.
    554  * No more than @a size bytes are written. NULL-terminator is always
    555  * written after the last succesfully copied character (i.e. if the
    556  * destination buffer is has at least 1 byte, it will be always
    557  * NULL-terminated).
    558  *
    559  * @param src   Source wide string.
    560  * @param dst   Destination buffer.
    561  * @param count Size of the destination buffer.
    562  *
    563  */
    564 void wstr_nstr(char *dst, const wchar_t *src, size_t size)
    565 {
    566         /* No space for the NULL-terminator in the buffer */
    567         if (size == 0)
    568                 return;
    569        
     551/** Convert wide string to string.
     552 *
     553 * Convert wide string @a src to string. The output is written to the buffer
     554 * specified by @a dest and @a size. @a size must be non-zero and the string
     555 * written will always be well-formed.
     556 *
     557 * @param dest  Destination buffer.
     558 * @param size  Size of the destination buffer.
     559 * @param src   Source wide string.
     560 */
     561void wstr_to_str(char *dest, size_t size, const wchar_t *src)
     562{
    570563        wchar_t ch;
    571         size_t src_idx = 0;
    572         size_t dst_off = 0;
    573        
     564        size_t src_idx;
     565        size_t dest_off;
     566
     567        /* There must be space for a null terminator in the buffer. */
     568        assert(size > 0);
     569       
     570        src_idx = 0;
     571        dest_off = 0;
     572
    574573        while ((ch = src[src_idx++]) != 0) {
    575                 if (chr_encode(ch, dst, &dst_off, size) != EOK)
     574                if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
    576575                        break;
    577576        }
    578        
    579         if (dst_off >= size)
    580                 dst[size - 1] = 0;
    581         else
    582                 dst[dst_off] = 0;
     577
     578        dest[dest_off] = '\0';
    583579}
    584580
     
    586582 *
    587583 * Convert string @a src to wide string. The output is written to the
    588  * buffer specified by @a dest and @a size, which must have non-zero
    589  * size. The output will always be null-terminated.
     584 * buffer specified by @a dest and @a dlen. @a dlen must be non-zero
     585 * and the wide string written will always be null-terminated.
    590586 *
    591587 * @param dest  Destination buffer.
  • uspace/lib/libc/include/string.h

    rba26129 r0f06dbc  
    7373extern void str_append(char *dest, size_t size, const char *src);
    7474
    75 extern void wstr_nstr(char *dst, const wchar_t *src, size_t size);
     75extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
    7676extern void str_to_wstr(wchar_t *dest, size_t dlen, const char *src);
    7777
Note: See TracChangeset for help on using the changeset viewer.