Exemplo n.º 1
0
 wildcard_matcher_t(const wchar_t * /*argv0*/, const wchar_t *pattern,
                    const match_options_t &opts, io_streams_t &streams)
     : string_matcher_t(opts, streams), wcpattern(parse_util_unescape_wildcards(pattern)) {
     if (opts.ignore_case) {
         for (size_t i = 0; i < wcpattern.length(); i++) {
             wcpattern[i] = towlower(wcpattern[i]);
         }
     }
 }
Exemplo n.º 2
0
// Helper function to abstract the repeat logic from string_repeat
// returns the to_repeat string, repeated count times.
static wcstring wcsrepeat(const wcstring &to_repeat, size_t count) {
    wcstring repeated;
    repeated.reserve(to_repeat.length() * count);

    for (size_t j = 0; j < count; j++) {
        repeated += to_repeat;
    }

    return repeated;
}
Exemplo n.º 3
0
/**
   Remove any prefix and suffix newlines from the specified
   string.
 */
static void trim(wcstring &str)
{
    if (str.empty())
        return;

    size_t pos = str.find_first_not_of(L" \n");
    if (pos > 0)
        str.erase(0, pos);

    pos = str.find_last_not_of(L" \n");
    if (pos != wcstring::npos && pos + 1 < str.length())
        str.erase(pos + 1);
}
Exemplo n.º 4
0
 wildcard_matcher_t(const wchar_t * /*argv0*/, const wchar_t *pattern, const options_t &opts,
                    io_streams_t &streams)
     : string_matcher_t(opts, streams), wcpattern(parse_util_unescape_wildcards(pattern)) {
     if (opts.ignore_case) {
         for (size_t i = 0; i < wcpattern.length(); i++) {
             wcpattern[i] = towlower(wcpattern[i]);
         }
     }
     if (opts.entire && !wcpattern.empty()) {
         if (wcpattern.front() != ANY_STRING) wcpattern.insert(0, 1, ANY_STRING);
         if (wcpattern.back() != ANY_STRING) wcpattern.push_back(ANY_STRING);
     }
 }
Exemplo n.º 5
0
// Helper function to abstract the repeat until logic from string_repeat
// returns the to_repeat string, repeated until max char has been reached.
static wcstring wcsrepeat_until(const wcstring &to_repeat, size_t max) {
    size_t count = max / to_repeat.length();
    size_t mod = max % to_repeat.length();

    return wcsrepeat(to_repeat, count) + to_repeat.substr(0, mod);
}