]> mj.ucw.cz Git - libucw.git/blob - ucw/string.h
Added string functions for matching of prefixes and suffixes
[libucw.git] / ucw / string.h
1 /*
2  *      UCW Library -- String Routines
3  *
4  *      (c) 2006 Pavel Charvat <pchar@ucw.cz>
5  *      (c) 2007--2011 Martin Mares <mj@ucw.cz>
6  *
7  *      This software may be freely distributed and used according to the terms
8  *      of the GNU Lesser General Public License.
9  */
10
11 #ifndef _UCW_STRING_H
12 #define _UCW_STRING_H
13
14 /* string.c */
15
16 #ifdef CONFIG_DARWIN
17 uns strnlen(const char *str, uns n);
18 #endif
19
20 char *str_format_flags(char *dest, const char *fmt, uns flags);
21 uns str_count_char(const char *str, uns chr);
22
23 /* str-esc.c */
24
25 char *str_unesc(char *dest, const char *src);
26
27 /* str-split.c */
28
29 int str_sepsplit(char *str, uns sep, char **rec, uns max);
30 int str_wordsplit(char *str, char **rec, uns max);
31
32 /* str-(i)match.c: Matching of shell patterns */
33
34 int str_match_pattern(const char *patt, const char *str);
35 int str_match_pattern_nocase(const char *patt, const char *str);
36
37 /* str-hex.c */
38
39 void mem_to_hex(char *dest, const byte *src, uns bytes, uns flags);
40 const char *hex_to_mem(byte *dest, const char *src, uns max_bytes, uns flags);
41
42 // Bottom 8 bits of flags are an optional separator of bytes, the rest is:
43 #define MEM_TO_HEX_UPCASE 0x100
44
45 /* str-fix.c */
46
47 int str_has_prefix(char *str, char *prefix);            /** Tests if @str starts with @prefix. **/
48 int str_has_suffix(char *str, char *suffix);            /** Tests if @str ends with @suffix. **/
49
50 /**
51  * Let @str and @prefix be hierarchical names with components separated by
52  * a character @sep. Returns true if @str starts with @prefix, respecting
53  * component boundaries.
54  *
55  * For example, when @sep is '/' and @str is "/usr/local/bin", then:
56  * - "/usr/local" is a prefix
57  * - "/usr/local/" is a prefix, too
58  * - "/usr/loc" is not,
59  * - "/usr/local/bin" is a prefix,
60  * - "/usr/local/bin/" is not,
61  * - "/" is a prefix,
62  * - "" is a prefix,
63  **/
64 int str_hier_prefix(char *str, char *prefix, uns sep);
65 int str_hier_suffix(char *str, char *suffix, uns sep);  /** Like @str_hier_prefix(), but for suffixes. **/
66
67 #endif