4e4e5cc7c7b3add3659acb04152b051cc7d36d39
[reactos.git] / rosapps / smartpdf / baseutils / str_util.h
1 /* Written by Krzysztof Kowalczyk (http://blog.kowalczyk.info)
2 The author disclaims copyright to this source code. */
3 #ifndef STR_UTIL_H_
4 #define STR_UTIL_H_
5
6 #ifdef __cplusplus
7 extern "C"
8 {
9 #endif
10
11 /* DOS is 0xd 0xa */
12 #define DOS_NEWLINE "\x0d\x0a"
13 /* Mac is single 0xd */
14 #define MAC_NEWLINE "\x0d"
15 /* Unix is single 0xa (10) */
16 #define UNIX_NEWLINE "\x0a"
17 #define UNIX_NEWLINE_C 0xa
18
19 #ifdef _WIN32
20 #define DIR_SEP_CHAR '\\'
21 #define DIR_SEP_STR "\\"
22 #else
23 #define DIR_SEP_CHAR '/'
24 #define DIR_SEP_STR "/"
25 #endif
26
27 void no_op(void);
28
29 #ifdef DEBUG
30 #ifdef _WIN32
31 #define DBG_OUT win32_dbg_out
32 #define DBG_OUT_HEX win32_dbg_out_hex
33 #else
34 #define DBG_OUT printf
35 #define DBG_OUT_HEX(...) no_op()
36 #endif
37 #else
38 #define DBG_OUT(...) no_op()
39 #define DBG_OUT_HEX(...) no_op()
40 #endif
41
42 int char_is_ws_or_zero(char c);
43 int char_is_ws(char c);
44 int char_is_digit(char c);
45
46 /* TODO: should probably be based on MSVC version */
47 #if defined(__GNUC__) || !defined(_WIN32) || (_MSC_VER < 1400)
48 void strcpy_s(char *dst, size_t dstLen, const char *src);
49 #endif
50
51 #define str_len strlen
52 int str_eq(const char *str1, const char *str2);
53 int str_ieq(const char *str1, const char *str2);
54 #define str_eq_no_case str_ieq
55 int str_eqn(const char *str1, const char *str2, int len);
56 int str_startswith(const char *str, const char *txt);
57 int str_startswithi(const char *str, const char *txt);
58 int str_endswith(const char *str, const char *end);
59 int str_endswithi(const char *str, const char *end);
60 int str_endswith_char(const char *str, char c);
61 int str_empty(const char *str);
62 int str_copy(char *dst, size_t dst_cch_size, const char *src);
63 int str_copyn(char *dst, size_t dst_cch_size, const char *src, size_t src_cch_size);
64 char * str_dup(const char *str);
65 char * str_dupn(const char *str, size_t len);
66 char * str_cat(const char *str1, const char *str2);
67 char * str_cat3(const char *str1, const char *str2, const char *str3);
68 char * str_cat4(const char *str1, const char *str2, const char *str3, const char *str4);
69 char * str_url_encode(const char *str);
70 int char_needs_url_escape(char c);
71 int str_contains(const char *str, char c);
72 char * str_printf_args(const char *format, va_list args);
73 char * str_printf(const char *format, ...);
74 const char *str_find_char(const char *txt, char c);
75 char * str_split_iter(char **txt, char c);
76 char * str_normalize_newline(const char *txt, const char *replace);
77 void str_strip_left(char *txt, const char *to_strip);
78 void str_strip_ws_left(char *txt);
79 void str_strip_right(char *txt, const char *to_strip);
80 void str_strip_ws_right(char *txt);
81 void str_strip_both(char *txt, const char *to_strip);
82 void str_strip_ws_both(char *txt);
83 char * str_escape(const char *txt);
84 char * str_parse_possibly_quoted(char **txt);
85
86 #ifdef DEBUG
87 void str_util_test(void);
88 #endif
89
90 typedef struct str_item str_item;
91 typedef struct str_array str_array;
92
93 struct str_item {
94 void * opaque; /* opaque data that the user can use */
95 char str[1];
96 };
97
98 struct str_array {
99 int items_allocated;
100 int items_count;
101 str_item ** items;
102 };
103
104 void str_array_init(str_array *str_arr);
105 void str_array_free(str_array *str_arr);
106 void str_array_delete(str_array *str_arr);
107 str_item *str_array_set(str_array *str_arr, int index, const char *str);
108 str_item *str_array_add(str_array *str_arr, const char *str);
109 str_item *str_array_get(str_array *str_arr, int index);
110 int str_array_get_count(str_array *str_arr);
111 int str_array_exists_no_case(str_array *str_arr, const char *str);
112 str_item *str_array_add_no_dups(str_array *str_arr, const char *str);
113
114 #ifdef __cplusplus
115 }
116 #endif
117 #endif