Logo Search packages:      
Sourcecode: waimea version File versions  Download package

char* strwithin ( char *  s,
char  c1,
char  c2,
bool  eval_env 
)

Return string between to characters.

Duplicates and returns the string between c1 and c2 if c1 and c2 was found. Possible environment variables are evaluated if eval_env parameter is true. All special character sequences are replaced with real characters.

Parameters:
s String to search for c1 and c2 in
c1 Starting character
c2 Ending character
eval_env True if environment variables should be evaluated
Returns:
String within c1 and c2

Definition at line 2891 of file Resources.cc.

References environment_expansion().

                                                          {
    int i, n;
    char *str;
    char *__m_wastrdup_tmp;
    
    for (i = 0;; i++) {
        if (s[i] == '\0') break;
        if (s[i] == c1 && (i == 0 || s[i - 1] != '\\')) break;
    }
    if (s[i] == '\0') return NULL;
    
    for (n = i + 1;; n++) {
        if (s[n] == '\0') break;
        if (s[n] == c2 && s[n - 1] != '\\') break;
    }
    if (s[n] == '\0') return NULL; 
    
    s[n] = '\0';
    str = __m_wastrdup(s + i + 1);
    s[n] = c2;
    
    if (eval_env) {
        str = environment_expansion(str);
    }
    for (i = 0; str[i] != '\0'; i++) {
        if (str[i] == '\\' && 
            (str[i + 1] == '$' ||
             str[i + 1] == '\\' ||
             str[i + 1] == '"' ||
             str[i + 1] == '(' ||
             str[i + 1] == ')' ||
             str[i + 1] == '[' ||
             str[i + 1] == ']' ||
             str[i + 1] == '{' ||
             str[i + 1] == '}' ||
             str[i + 1] == '<' ||
             str[i + 1] == '>')) {
            for (n = 1; str[i + n] != '\0'; n++)
                str[i + n - 1] = str[i + n];
            str[i + n - 1] = '\0';
        }
    }
    return str;
}


Generated by  Doxygen 1.6.0   Back to index