30 const void *_needle,
size_t nlen)
32#if defined(HAVE_MEMMEM) && (!defined(__GNUC__) || __GNUC__ >= 2)
36 return memmem(_haystack, hlen, _needle, nlen);
40 const char *p, *last_possible_start;
41 const char *haystack = (
const char*)_haystack;
42 const char *needle = (
const char*)_needle;
51 last_possible_start = haystack + hlen - nlen;
52 first = *(
const char*)needle;
53 while ((p = memchr(p, first, last_possible_start + 1 - p))) {
56 if (++p > last_possible_start) {
69tor_memstr(
const void *haystack,
size_t hlen,
const char *needle)
71 return tor_memmem(haystack, hlen, needle, strlen(needle));
78 static const char ZERO[] = {
79 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
81 while (len >=
sizeof(ZERO)) {
117 if (strchr(strip, *readp)) {
132 *s = TOR_TOLOWER(*s);
143 *s = TOR_TOUPPER(*s);
152 for (s = strchr(s, find); s; s = strchr(s + 1, find)) {
163 if (!TOR_ISPRINT(*s))
189 if (!TOR_ISSPACE(*s))
209 return strcmp(s1, s2);
219 size_t n = strlen(s2);
220 return strncmp(s1, s2, n);
229 size_t n = strlen(s2);
230 return strncasecmp(s1, s2, n);
243 size_t plen = strlen(prefix);
255 size_t n1 = strlen(s1), n2 = strlen(s2);
257 return strcmp(s1,s2);
259 return strncmp(s1+(n1-n2), s2, n2);
268 size_t n1 = strlen(s1), n2 = strlen(s2);
270 return strcasecmp(s1,s2);
272 return strncasecmp(s1+(n1-n2), s2, n2);
296 while (*s && *s !=
'\n')
309 raw_assert(eos && s <= eos);
324 while (s < eos && *s && *s !=
'\n')
336 while (*s ==
' ' || *s ==
'\t' || *s ==
'\r')
346 while (s < eos && (*s ==
' ' || *s ==
'\t' || *s ==
'\r'))
404 size_t needle_len = strlen(needle);
407 if (!strncmp(haystack, needle, needle_len))
410 haystack = strchr(haystack,
'\n');
428 size_t length = strlen(
string);
432 for (iter = 0; iter < length ; iter++) {
434 if (!(TOR_ISALPHA(
string[iter]) ||
435 string[iter] ==
'_'))
438 if (!(TOR_ISALPHA(
string[iter]) ||
439 TOR_ISDIGIT(
string[iter]) ||
440 string[iter] ==
'_'))
449#define TOP_BITS(x) ((uint8_t)(0xFF << (8 - (x))))
451#define LOW_BITS(x) ((uint8_t)(0xFF >> (8 - (x))))
490 uint32_t codepoint = c[0] & mask;
493 for (uint8_t i = 1; i < len; i++) {
497 codepoint |= (c[i] & mask);
500 if (len == 2 && codepoint <= 0x7f)
503 if (len == 3 && codepoint <= 0x7ff)
506 if (len == 4 && codepoint <= 0xffff)
509 if (codepoint >= 0xd800 && codepoint <= 0xdfff)
512 return codepoint <= 0x10ffff;
529 "BUG: string_is_utf8() called with NULL str but non-zero len.");
537 for (
size_t i = 0; i < len;) {
542 size_t next_char = i + num_bytes;
561 if (str && len >= 3 && (!
strcmpstart(str,
"\uFEFF") ||
Locale-independent character-type inspection (header)
int safe_mem_is_zero(const void *mem, size_t sz)
#define fast_memeq(a, b, c)
#define fast_memcmp(a, b, c)
Definitions for common sizes of cryptographic digests.
void tor_log_err_sigsafe(const char *m,...)
int tor_strisspace(const char *s)
const char * find_whitespace_eos(const char *s, const char *eos)
int strcasecmpstart(const char *s1, const char *s2)
void tor_strlower(char *s)
int strcmpstart(const char *s1, const char *s2)
int strcmpend(const char *s1, const char *s2)
static uint8_t bytes_in_char(uint8_t b)
const char * find_whitespace(const char *s)
void tor_strupper(char *s)
const char * eat_whitespace_eos(const char *s, const char *eos)
int fast_memcmpstart(const void *mem, size_t memlen, const char *prefix)
int strcasecmpend(const char *s1, const char *s2)
int tor_strisprint(const char *s)
int strcmp_opt(const char *s1, const char *s2)
int string_is_utf8_no_bom(const char *str, size_t len)
int tor_digest256_is_zero(const char *digest)
int fast_mem_is_zero(const char *mem, size_t len)
static bool validate_char(const uint8_t *c, uint8_t len)
int string_is_C_identifier(const char *string)
void tor_strstrip(char *s, const char *strip)
const char * find_str_at_start_of_line(const char *haystack, const char *needle)
const char * eat_whitespace(const char *s)
const char * eat_whitespace_eos_no_nl(const char *s, const char *eos)
const char * eat_whitespace_no_nl(const char *s)
int tor_strisnonupper(const char *s)
const void * tor_memmem(const void *_haystack, size_t hlen, const void *_needle, size_t nlen)
int string_is_utf8(const char *str, size_t len)
int tor_digest_is_zero(const char *digest)
void tor_strreplacechar(char *s, char find, char replacement)
static bool is_continuation_byte(uint8_t b)
Header for util_string.c.