Changeset 2e839dda in mainline
- Timestamp:
- 2011-06-27T16:35:11Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7194a60
- Parents:
- 61e29a4d
- Location:
- uspace/lib/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
r61e29a4d r2e839dda 722 722 } 723 723 724 /** Find first occurence of character in wide string. 725 * 726 * @param wstr String to search. 727 * @param ch Character to look for. 728 * 729 * @return Pointer to character in @a wstr or NULL if not found. 730 */ 731 wchar_t *wstr_chr(const wchar_t *wstr, wchar_t ch) 732 { 733 while (*wstr && *wstr != ch) 734 wstr++; 735 if (*wstr) 736 return (wchar_t *) wstr; 737 else 738 return NULL; 739 } 740 741 /** Find last occurence of character in wide string. 742 * 743 * @param wstr String to search. 744 * @param ch Character to look for. 745 * 746 * @return Pointer to character in @a wstr or NULL if not found. 747 */ 748 wchar_t *wstr_rchr(const wchar_t *wstr, wchar_t ch) 749 { 750 const wchar_t *res = NULL; 751 while (*wstr) { 752 if (*wstr == ch) 753 res = wstr; 754 wstr++; 755 } 756 return (wchar_t *) res; 757 } 758 724 759 /** Insert a wide character into a wide string. 725 760 * … … 974 1009 } 975 1010 1011 void str_reverse(char* begin, char* end) 1012 { 1013 char aux; 1014 while(end>begin) 1015 aux=*end, *end--=*begin, *begin++=aux; 1016 } 1017 1018 int size_t_str(size_t value, int base, char* str, size_t size) 1019 { 1020 static char num[] = "0123456789abcdefghijklmnopqrstuvwxyz"; 1021 char* wstr=str; 1022 1023 if (size == 0) 1024 return EINVAL; 1025 if (base<2 || base>35) { 1026 *str='\0'; 1027 return EINVAL; 1028 } 1029 1030 do { 1031 *wstr++ = num[value % base]; 1032 if (--size == 0) 1033 return EOVERFLOW; 1034 } while(value /= base); 1035 *wstr='\0'; 1036 1037 // Reverse string 1038 str_reverse(str,wstr-1); 1039 return EOK; 1040 } 976 1041 977 1042 /** Convert initial part of string to unsigned long according to given base. -
uspace/lib/c/include/str.h
r61e29a4d r2e839dda 80 80 extern char *str_chr(const char *str, wchar_t ch); 81 81 extern char *str_rchr(const char *str, wchar_t ch); 82 extern wchar_t *wstr_chr(const wchar_t *wstr, wchar_t ch); 83 extern wchar_t *wstr_rchr(const wchar_t *wstr, wchar_t ch); 82 84 83 85 extern bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos); … … 86 88 extern char *str_dup(const char *); 87 89 extern char *str_ndup(const char *, size_t max_size); 90 91 extern void str_reverse(char* begin, char* end); 92 extern int size_t_str(size_t value, int base, char* str, size_t size); 88 93 89 94 extern int str_uint64(const char *, char **, unsigned int, bool, uint64_t *);
Note:
See TracChangeset
for help on using the changeset viewer.