1 #ifndef STR_H 2 #define STR_H 3 /* 4 * Copyright (c) 2001 Marc Espie. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS 16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD 19 * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 /* pos = Str_rchri(str, end, c); 29 * strrchr on intervals. */ 30 extern char *Str_rchri(const char *, const char *, int); 31 32 /* copy = Str_concati(s1, e1, s2, e2, sep); 33 * Concatenate strings s1/e1 and s2/e2, wedging separator sep if != 0. */ 34 extern char *Str_concati(const char *, const char *, const char *, const char *, int); 35 #define Str_concat(s1, s2, sep) Str_concati(s1, strchr(s1, '\0'), s2, strchr(s2, '\0'), sep) 36 37 /* copy = Str_dupi(str, end); 38 * strdup on intervals. */ 39 extern char *Str_dupi(const char *, const char *); 40 41 /* copy = escape_dupi(str, end, set); 42 * copy string str/end. All escape sequences such as \c with c in set 43 * are handled as well. */ 44 extern char *escape_dupi(const char *, const char *, const char *); 45 46 47 extern char **brk_string(const char *, int *, char **); 48 49 50 /* Iterate through a string word by word, 51 * without copying anything. 52 * More light-weight than brk_string, handles \ ' " as well. 53 * 54 * position = s; 55 * while ((begin = iterate_words(&position)) != NULL) { 56 * do_something_with_word_interval(begin, position); 57 * } 58 */ 59 extern const char *iterate_words(const char **); 60 61 /* match = Str_Matchi(str, estr, pat, end); 62 * Checks if string str/estr matches pattern pat/end */ 63 extern bool Str_Matchi(const char *, const char *, const char *, const char *); 64 #define Str_Match(string, pattern) \ 65 Str_Matchi(string, strchr(string, '\0'), pattern, strchr(pattern, '\0')) 66 67 extern const char *Str_SYSVMatch(const char *, const char *, size_t *); 68 extern void Str_SYSVSubst(Buffer, const char *, const char *, size_t); 69 #endif 70