Changeset 5520 for pjproject/trunk/pjlib/src/pj/string.c
- Timestamp:
- Jan 11, 2017 4:38:29 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/string.c
r4704 r5520 29 29 #endif 30 30 31 PJ_DEF(pj_ssize_t) pj_strspn(const pj_str_t *str, const pj_str_t *set_char) 32 { 33 pj_ssize_t i, j, count = 0; 34 for (i = 0; i < str->slen; i++) { 35 if (count != i) 36 break; 37 38 for (j = 0; j < set_char->slen; j++) { 39 if (str->ptr[i] == set_char->ptr[j]) 40 count++; 41 } 42 } 43 return count; 44 } 45 46 47 PJ_DEF(pj_ssize_t) pj_strspn2(const pj_str_t *str, const char *set_char) 48 { 49 pj_ssize_t i, j, count = 0; 50 for (i = 0; i < str->slen; i++) { 51 if (count != i) 52 break; 53 54 for (j = 0; set_char[j] != 0; j++) { 55 if (str->ptr[i] == set_char[j]) 56 count++; 57 } 58 } 59 return count; 60 } 61 62 63 PJ_DEF(pj_ssize_t) pj_strcspn(const pj_str_t *str, const pj_str_t *set_char) 64 { 65 pj_ssize_t i, j; 66 for (i = 0; i < str->slen; i++) { 67 for (j = 0; j < set_char->slen; j++) { 68 if (str->ptr[i] == set_char->ptr[j]) 69 return i; 70 } 71 } 72 return i; 73 } 74 75 76 PJ_DECL(pj_ssize_t) pj_strcspn2(const pj_str_t *str, const char *set_char) 77 { 78 pj_ssize_t i, j; 79 for (i = 0; i < str->slen; i++) { 80 for (j = 0; set_char[j] != 0; j++) { 81 if (str->ptr[i] == set_char[j]) 82 return i; 83 } 84 } 85 return i; 86 } 87 88 89 PJ_DEF(pj_ssize_t) pj_strtok(const pj_str_t *str, const pj_str_t *delim, 90 pj_str_t *tok, pj_size_t start_idx) 91 { 92 pj_ssize_t str_idx; 93 94 tok->slen = 0; 95 if ((str->slen == 0) || ((pj_size_t)str->slen < start_idx)) { 96 return str->slen; 97 } 98 99 tok->ptr = str->ptr + start_idx; 100 tok->slen = str->slen - start_idx; 101 102 str_idx = pj_strspn(tok, delim); 103 if (start_idx+str_idx == (pj_size_t)str->slen) { 104 return str->slen; 105 } 106 tok->ptr += str_idx; 107 tok->slen -= str_idx; 108 109 tok->slen = pj_strcspn(tok, delim); 110 return start_idx + str_idx; 111 } 112 113 114 PJ_DECL(pj_ssize_t) pj_strtok2(const pj_str_t *str, const char *delim, 115 pj_str_t *tok, pj_size_t start_idx) 116 { 117 pj_ssize_t str_idx; 118 119 tok->slen = 0; 120 if ((str->slen == 0) || ((pj_size_t)str->slen < start_idx)) { 121 return str->slen; 122 } 123 124 tok->ptr = str->ptr + start_idx; 125 tok->slen = str->slen - start_idx; 126 127 str_idx = pj_strspn2(tok, delim); 128 if (start_idx + str_idx == (pj_size_t)str->slen) { 129 return str->slen; 130 } 131 tok->ptr += str_idx; 132 tok->slen -= str_idx; 133 134 tok->slen = pj_strcspn2(tok, delim); 135 return start_idx + str_idx; 136 } 137 31 138 32 139 PJ_DEF(char*) pj_strstr(const pj_str_t *str, const pj_str_t *substr)
Note: See TracChangeset
for help on using the changeset viewer.