-
-
Notifications
You must be signed in to change notification settings - Fork 331
/
str_util.h
43 lines (34 loc) · 883 Bytes
/
str_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* str_util.h
*
*/
#ifndef STR_UTIL_H
#define STR_UTIL_H
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
int str_tokenize(char *s, const char *delim, char **tokens, int max_tokens);
// String copy with guaranteed null termination
char *strncpyz(char *dest, size_t dest_size, const char *src, size_t num);
char *strcpyz(char *dest, size_t dest_size, const char *src);
template<size_t N>
char *strncpyz(char (&dest)[N], const char *src, size_t num)
{
return strncpyz(dest, N, src, num);
}
template<size_t N>
char *strcpyz(char (&dest)[N], const char *src)
{
return strcpyz(dest, N, src);
}
template<size_t N>
size_t sprintfz(char (&dest)[N], const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
size_t r = vsnprintf(dest, N, fmt, args);
va_end(args);
return r;
}
unsigned int str_hash(const char *s, unsigned int initial = 5381);
#endif // STR_UTIL_H