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