Changeset 61e29a4d in mainline
- Timestamp:
- 2011-06-25T05:23:41Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2e839dda
- Parents:
- 2d0d637
- Location:
- uspace/lib/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
r2d0d637 r61e29a4d 366 366 } 367 367 368 /** Check whether wide string is plain ASCII. 369 * 370 * @return True if wide string is plain ASCII. 371 * 372 */ 373 bool wstr_is_ascii(const wchar_t *wstr) 374 { 375 while (*wstr && ascii_check(*wstr)) 376 wstr++; 377 return *wstr == 0; 378 } 379 368 380 /** Check whether character is valid 369 381 * … … 552 564 * @param size Size of the destination buffer. 553 565 * @param src Source wide string. 554 */ 555 void wstr_to_str(char *dest, size_t size, const wchar_t *src) 556 { 566 * 567 * @return EOK, if success, negative otherwise. 568 */ 569 int wstr_to_str(char *dest, size_t size, const wchar_t *src) 570 { 571 int rc; 557 572 wchar_t ch; 558 573 size_t src_idx; … … 566 581 567 582 while ((ch = src[src_idx++]) != 0) { 568 if (chr_encode(ch, dest, &dest_off, size - 1) != EOK) 583 rc = chr_encode(ch, dest, &dest_off, size - 1); 584 if (rc != EOK) 569 585 break; 570 586 } 571 587 572 588 dest[dest_off] = '\0'; 589 return rc; 573 590 } 574 591 … … 631 648 * @param dlen Length of destination buffer (number of wchars). 632 649 * @param src Source string. 633 */ 634 void str_to_wstr(wchar_t *dest, size_t dlen, const char *src) 635 { 650 * 651 * @return EOK, if success, negative otherwise. 652 */ 653 int str_to_wstr(wchar_t *dest, size_t dlen, const char *src) 654 { 655 int rc=EOK; 636 656 size_t offset; 637 657 size_t di; … … 644 664 645 665 do { 646 if (di >= dlen - 1) 666 if (di >= dlen - 1) { 667 rc = EOVERFLOW; 647 668 break; 669 } 648 670 649 671 c = str_decode(src, &offset, STR_NO_LIMIT); … … 652 674 653 675 dest[dlen - 1] = '\0'; 676 return rc; 654 677 } 655 678 -
uspace/lib/c/include/str.h
r2d0d637 r61e29a4d 65 65 extern bool ascii_check(wchar_t ch); 66 66 extern bool chr_check(wchar_t ch); 67 extern bool wstr_is_ascii(const wchar_t *wstr); 67 68 68 69 extern int str_cmp(const char *s1, const char *s2); … … 73 74 extern void str_append(char *dest, size_t size, const char *src); 74 75 75 extern voidwstr_to_str(char *dest, size_t size, const wchar_t *src);76 extern int wstr_to_str(char *dest, size_t size, const wchar_t *src); 76 77 extern char *wstr_to_astr(const wchar_t *src); 77 extern voidstr_to_wstr(wchar_t *dest, size_t dlen, const char *src);78 extern int str_to_wstr(wchar_t *dest, size_t dlen, const char *src); 78 79 79 80 extern char *str_chr(const char *str, wchar_t ch);
Note:
See TracChangeset
for help on using the changeset viewer.