30 const void *_needle,
size_t nlen)
32 #if defined(HAVE_MEMMEM) && (!defined(__GNUC__) || __GNUC__ >= 2)
34 return memmem(_haystack, hlen, _needle, nlen);
38 const char *p, *last_possible_start;
39 const char *haystack = (
const char*)_haystack;
40 const char *needle = (
const char*)_needle;
49 last_possible_start = haystack + hlen - nlen;
50 first = *(
const char*)needle;
51 while ((p = memchr(p, first, last_possible_start + 1 - p))) {
54 if (++p > last_possible_start) {
67 tor_memstr(
const void *haystack,
size_t hlen,
const char *needle)
69 return tor_memmem(haystack, hlen, needle, strlen(needle));
76 static const char ZERO[] = {
77 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,
79 while (len >=
sizeof(ZERO)) {
115 if (strchr(strip, *readp)) {
130 *s = TOR_TOLOWER(*s);
141 *s = TOR_TOUPPER(*s);
150 for (s = strchr(s, find); s; s = strchr(s + 1, find)) {
161 if (!TOR_ISPRINT(*s))
187 if (!TOR_ISSPACE(*s))
207 return strcmp(s1, s2);
217 size_t n = strlen(s2);
218 return strncmp(s1, s2, n);
227 size_t n = strlen(s2);
228 return strncasecmp(s1, s2, n);
241 size_t plen = strlen(prefix);
253 size_t n1 = strlen(s1), n2 = strlen(s2);
255 return strcmp(s1,s2);
257 return strncmp(s1+(n1-n2), s2, n2);
266 size_t n1 = strlen(s1), n2 = strlen(s2);
268 return strcasecmp(s1,s2);
270 return strncasecmp(s1+(n1-n2), s2, n2);
294 while (*s && *s !=
'\n')
307 raw_assert(eos && s <= eos);
322 while (s < eos && *s && *s !=
'\n')
334 while (*s ==
' ' || *s ==
'\t' || *s ==
'\r')
344 while (s < eos && (*s ==
' ' || *s ==
'\t' || *s ==
'\r'))
402 size_t needle_len = strlen(needle);
405 if (!strncmp(haystack, needle, needle_len))
408 haystack = strchr(haystack,
'\n');
426 size_t length = strlen(
string);
430 for (iter = 0; iter < length ; iter++) {
432 if (!(TOR_ISALPHA(
string[iter]) ||
433 string[iter] ==
'_'))
436 if (!(TOR_ISALPHA(
string[iter]) ||
437 TOR_ISDIGIT(
string[iter]) ||
438 string[iter] ==
'_'))
447 #define TOP_BITS(x) ((uint8_t)(0xFF << (8 - (x))))
449 #define LOW_BITS(x) ((uint8_t)(0xFF >> (8 - (x))))
488 uint32_t codepoint = c[0] & mask;
491 for (uint8_t i = 1; i < len; i++) {
495 codepoint |= (c[i] & mask);
498 if (len == 2 && codepoint <= 0x7f)
501 if (len == 3 && codepoint <= 0x7ff)
504 if (len == 4 && codepoint <= 0xffff)
507 if (codepoint >= 0xd800 && codepoint <= 0xdfff)
510 return codepoint <= 0x10ffff;
527 "BUG: string_is_utf8() called with NULL str but non-zero len.");
535 for (
size_t i = 0; i < len;) {
540 size_t next_char = i + num_bytes;
559 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 * eat_whitespace_eos_no_nl(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)
const char * find_whitespace_eos(const char *s, const char *eos)
static uint8_t bytes_in_char(uint8_t b)
const char * find_whitespace(const char *s)
void tor_strupper(char *s)
int fast_memcmpstart(const void *mem, size_t memlen, const char *prefix)
const void * tor_memmem(const void *_haystack, size_t hlen, const void *_needle, size_t nlen)
int strcasecmpend(const char *s1, const char *s2)
int tor_strisprint(const char *s)
const char * eat_whitespace_eos(const char *s, const char *eos)
int strcmp_opt(const char *s1, const char *s2)
const char * eat_whitespace(const char *s)
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 * eat_whitespace_no_nl(const char *s)
int tor_strisnonupper(const char *s)
const char * find_str_at_start_of_line(const char *haystack, const char *needle)
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.