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
|
#include "string.ih"
static bool s_initialized;
static regex_t s_strip;
static regmatch_t pmatch[2];
char *string_strip(char **str)
{
if (!s_initialized)
{
s_initialized = true;
if
(
regcomp
(
&s_strip,
"^[[:space:]]*"
"("
"([^[:space:]].*[^[:space:]])"
"|"
"[^[:space:]]*"
")"
"[[:space:]]*$"
,
REG_EXTENDED | REG_NEWLINE
)
)
{
message_show(MSG_EMERG);
message("string_strip() regcomp() failed");
}
}
if (regexec(&s_strip, *str, 2, pmatch, 0)) /* no match */
**str = 0;
else
{
(*str)[pmatch[1].rm_eo] = 0;
*str += pmatch[1].rm_so;
}
return *str;
}
|