ATF_TC_BODY(nul, tc) { ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL); ATF_CHECK(wcscasecmp(L"", L"") == 0); ATF_CHECK(wcsncasecmp(L"", L"", 50) == 0); ATF_CHECK(wcsncasecmp(L"", L"", 0) == 0); }
/* * stress_wcsncasecmp() * stress on wcsncasecmp */ static void stress_wcsncasecmp( const char *name, wchar_t *str1, const size_t len1, wchar_t *str2, const size_t len2) { register size_t i; (void)len2; for (i = 1; i < len1; i++) { WCSCHK(name, 0 == wcsncasecmp(str1, str1, len1)); WCSCHK(name, 0 == wcsncasecmp(str2, str2, len2)); WCSCHK(name, 0 != wcsncasecmp(str2, str1, len2)); WCSCHK(name, 0 != wcsncasecmp(str1, str2, len1)); WCSCHK(name, 0 != wcsncasecmp(str1 + i, str1, len1)); WCSCHK(name, 0 != wcsncasecmp(str1, str1 + i, len1)); WCSCHK(name, 0 == wcsncasecmp(str1 + i, str1 + i, len1)); WCSCHK(name, 0 != wcsncasecmp(str1 + i, str2, len1)); WCSCHK(name, 0 != wcsncasecmp(str2, str1 + i, len2)); } }
bool replace_matches(const wchar_t *arg) { wcstring result; if (patlen == 0) { result = arg; } else { int replaced = 0; const wchar_t *cur = arg; while (*cur != L'\0') { if ((opts.all || replaced == 0) && (opts.ignore_case ? wcsncasecmp(cur, pattern, patlen) : wcsncmp(cur, pattern, patlen)) == 0) { result += replacement; cur += patlen; replaced++; total_replaced++; } else { result += *cur; cur++; } } } if (!opts.quiet) { streams.out.append(result); streams.out.append(L'\n'); } return true; }
static TACommandVerdict wcsncasecmp_cmd(TAThread thread,TAInputStream stream) { int res; wchar_t *s1; wchar_t *s2; size_t n; // Prepare s1 = ta_wcsalign(readWString(&stream)); //align on copy s2 = ta_wcsalign(readWString(&stream)); //align on copy n = readSize(&stream); START_TARGET_OPERATION(thread); res = wcsncasecmp(s1, s2, n); END_TARGET_OPERATION(thread); // Response writeInt(thread,res); sendResponse(thread); ta_dealloc_memory(s1); ta_dealloc_memory(s2); return taDefaultVerdict; }
int FdoCommonOSUtil::wcsnicmp(const wchar_t *s1, const wchar_t *s2, size_t len) { #ifdef _WIN32 return _wcsnicmp (s1, s2, len); #else return wcsncasecmp (s1, s2, len); #endif }
tb_long_t tb_wcsnicmp(tb_wchar_t const* s1, tb_wchar_t const* s2, tb_size_t n) { // check tb_assert_and_check_return_val(s1 && s2, 0); # ifdef TB_COMPILER_IS_MSVC return _wcsnicmp(s1, s2, n); # else return wcsncasecmp(s1, s2, n); # endif }
int main(int argc, char *argv[]) { printf("1..6\n"); setlocale(LC_CTYPE, "C"); assert(wcscasecmp(L"", L"") == 0); assert(wcsncasecmp(L"", L"", 50) == 0); assert(wcsncasecmp(L"", L"", 0) == 0); printf("ok 1 - wcscasecmp\n"); assert(wcscasecmp(L"abc", L"abc") == 0); assert(wcscasecmp(L"ABC", L"ABC") == 0); assert(wcscasecmp(L"abc", L"ABC") == 0); assert(wcscasecmp(L"ABC", L"abc") == 0); printf("ok 2 - wcscasecmp\n"); assert(wcscasecmp(L"abc", L"xyz") < 0); assert(wcscasecmp(L"ABC", L"xyz") < 0); assert(wcscasecmp(L"abc", L"XYZ") < 0); assert(wcscasecmp(L"ABC", L"XYZ") < 0); assert(wcscasecmp(L"xyz", L"abc") > 0); assert(wcscasecmp(L"XYZ", L"abc") > 0); assert(wcscasecmp(L"xyz", L"ABC") > 0); assert(wcscasecmp(L"XYZ", L"ABC") > 0); printf("ok 3 - wcscasecmp\n"); assert(wcscasecmp(L"abc", L"ABCD") < 0); assert(wcscasecmp(L"ABC", L"abcd") < 0); assert(wcscasecmp(L"abcd", L"ABC") > 0); assert(wcscasecmp(L"ABCD", L"abc") > 0); printf("ok 4 - wcscasecmp\n"); assert(wcsncasecmp(L"abc", L"ABCD", 4) < 0); assert(wcsncasecmp(L"ABC", L"abcd", 4) < 0); assert(wcsncasecmp(L"abcd", L"ABC", 4) > 0); assert(wcsncasecmp(L"ABCD", L"abc", 4) > 0); assert(wcsncasecmp(L"abc", L"ABCD", 3) == 0); assert(wcsncasecmp(L"ABC", L"abcd", 3) == 0); printf("ok 5 - wcsncasecmp\n"); assert(wcscasecmp(L"λ", L"Λ") != 0); setlocale(LC_CTYPE, "el_GR.UTF-8"); assert(wcscasecmp(L"λ", L"Λ") == 0); assert(wcscasecmp(L"λ", L"Ω") < 0); assert(wcscasecmp(L"Ω", L"λ") > 0); printf("ok 6 - greek\n"); exit(0); }
/** Test if the message msg contains the command cmd */ static bool match(const wchar_t *msg, const wchar_t *cmd) { size_t len = wcslen(cmd); if (wcsncasecmp(msg, cmd, len) != 0) return false; if (msg[len] && msg[len]!= L' ' && msg[len] != L'\t') return false; return true; }
/** Test if the message msg contains the command cmd */ static int match(const wchar_t *msg, const wchar_t *cmd) { size_t len = wcslen(cmd); if (wcsncasecmp(msg, cmd, len) != 0) return 0; if (msg[len] && msg[len]!= L' ' && msg[len] != L'\t') return 0; return 1; }
ATF_TC_BODY(wcsncasecmp, tc) { ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL); ATF_CHECK(wcsncasecmp(L"abc", L"ABCD", 4) < 0); ATF_CHECK(wcsncasecmp(L"ABC", L"abcd", 4) < 0); ATF_CHECK(wcsncasecmp(L"abcd", L"ABC", 4) > 0); ATF_CHECK(wcsncasecmp(L"ABCD", L"abc", 4) > 0); ATF_CHECK(wcsncasecmp(L"abc", L"ABCD", 3) == 0); ATF_CHECK(wcsncasecmp(L"ABC", L"abcd", 3) == 0); }
/* * Same as wcsstr but case-insensitive. */ wchar_t * wcscasestr(const wchar_t *s, const wchar_t *find) { wchar_t c, sc; size_t len; if ((c = *find++) != 0) { c = (wchar_t)towlower((wchar_t)c); len = wcslen(find); do { do { if ((sc = *s++) == 0) return (NULL); } while ((wchar_t)towlower((wchar_t)sc) != c); } while (wcsncasecmp(s, find, len) != 0); s--; } return ((wchar_t *)s); }
int wcsnicmp(const wchar_t *s1, const wchar_t *s2, size_t n) { //#ifdef __APPLE__ #if 1 size_t i; for (i = 0; i < n && s1[i] != L'\0' && s2[i] != L'\0'; i++) { wint_t x = towlower(s1[i]); wint_t y = towlower(s2[i]); if (x != y) return x - y; } return (i >= n) ? 0 : towlower(s1[i]) - towlower(s2[i]); #else return(wcsncasecmp(s1, s2, n)); #endif }
/* * Returns a pointer to first occurrence of the first character in s2 in s1 with * respect to Unicode characters and disregarding case. */ char * strcasechr(const char *s1, const char *s2) { wchar_t wc1, wc2; switch (mbtowc(&wc2, s2, MB_CUR_MAX)) { case -1: mbtowc(NULL, NULL, MB_CUR_MAX); /* FALLTHROUGH */ case 0: return NULL; } for (; *s1; s1++) { if (mbtowc(&wc1, s1, MB_CUR_MAX) == -1) { mbtowc(NULL, NULL, MB_CUR_MAX); continue; } if (wcsncasecmp(&wc1, &wc2, 1) == 0) return (char *)s1; } return NULL; }
/// Test if \c name is a string describing the signal named \c canonical. static int match_signal_name(const wchar_t *canonical, const wchar_t *name) { if (wcsncasecmp(name, L"sig", 3) == 0) name += 3; return wcscasecmp(canonical + 3, name) == 0; }
int wcsncasecmp_l(const wchar_t *l, const wchar_t *r, size_t n, locale_t locale) { return wcsncasecmp(l, r, n); }
/** * Compare two strings alphabetically in a case insensitive manner. * Be aware, only ASCII characters are case insensitive, non-ASCII * characters are case sensitive. * * This is a GNU-compliant slibc extension. * * @param a A negative value is returned if this is the lesser. * @param b A positive value is returned if this is the lesser. * @return Zero is returned if `a` and `b` are equal, otherwise, * see the specifications for `a` and `b`. * * @since Always. */ int wcscasecmp(const wchar_t* a, const wchar_t* b) { return wcsncasecmp(a, b, SIZE_MAX); }
/** * Parses a JSON encoded value to a JSONValue object * * @access protected * * @param wchar_t** data Pointer to a wchar_t* that contains the data * * @return JSONValue* Returns a pointer to a JSONValue object on success, NULL on error */ JSONValue *JSONValue::Parse(const wchar_t **data) { // Is it a string? if (**data == '"') { std::wstring str; if (!JSON::ExtractString(&(++(*data)), str)) return NULL; else return new JSONValue(str); } // Is it a boolean? else if ((simplejson_wcsnlen(*data, 4) && wcsncasecmp(*data, L"true", 4) == 0) || (simplejson_wcsnlen(*data, 5) && wcsncasecmp(*data, L"false", 5) == 0)) { bool value = wcsncasecmp(*data, L"true", 4) == 0; (*data) += value ? 4 : 5; return new JSONValue(value); } // Is it a null? else if (simplejson_wcsnlen(*data, 4) && wcsncasecmp(*data, L"null", 4) == 0) { (*data) += 4; return new JSONValue(); } // Is it a number? else if (**data == L'-' || (**data >= L'0' && **data <= L'9')) { // Negative? bool neg = **data == L'-'; if (neg) (*data)++; double number = 0.0; // Parse the whole part of the number - only if it wasn't 0 if (**data == L'0') (*data)++; else if (**data >= L'1' && **data <= L'9') number = JSON::ParseInt(data); else return NULL; // Could be a decimal now... if (**data == '.') { (*data)++; // Not get any digits? if (!(**data >= L'0' && **data <= L'9')) return NULL; // Find the decimal and sort the decimal place out // Use ParseDecimal as ParseInt won't work with decimals less than 0.1 // thanks to Javier Abadia for the report & fix double decimal = JSON::ParseDecimal(data); // Save the number number += decimal; } // Could be an exponent now... if (**data == L'E' || **data == L'e') { (*data)++; // Check signage of expo bool neg_expo = false; if (**data == L'-' || **data == L'+') { neg_expo = **data == L'-'; (*data)++; } // Not get any digits? if (!(**data >= L'0' && **data <= L'9')) return NULL; // Sort the expo out double expo = JSON::ParseInt(data); for (double i = 0.0; i < expo; i++) number = neg_expo ? (number / 10.0) : (number * 10.0); } // Was it neg? if (neg) number *= -1; return new JSONValue(number); } // An object? else if (**data == L'{') { JSONObject object; (*data)++; while (**data != 0) { // Whitespace at the start? if (!JSON::SkipWhitespace(data)) { FREE_OBJECT(object); return NULL; } // Special case - empty object if (object.size() == 0 && **data == L'}') { (*data)++; return new JSONValue(object); } // We want a string now... std::wstring name; if (!JSON::ExtractString(&(++(*data)), name)) { FREE_OBJECT(object); return NULL; } // More whitespace? if (!JSON::SkipWhitespace(data)) { FREE_OBJECT(object); return NULL; } // Need a : now if (*((*data)++) != L':') { FREE_OBJECT(object); return NULL; } // More whitespace? if (!JSON::SkipWhitespace(data)) { FREE_OBJECT(object); return NULL; } // The value is here JSONValue *value = Parse(data); if (value == NULL) { FREE_OBJECT(object); return NULL; } // Add the name:value if (object.find(name) != object.end()) delete object[name]; object[name] = value; // More whitespace? if (!JSON::SkipWhitespace(data)) { FREE_OBJECT(object); return NULL; } // End of object? if (**data == L'}') { (*data)++; return new JSONValue(object); } // Want a , now if (**data != L',') { FREE_OBJECT(object); return NULL; } (*data)++; } // Only here if we ran out of data FREE_OBJECT(object); return NULL; } // An array? else if (**data == L'[') { JSONArray array; (*data)++; while (**data != 0) { // Whitespace at the start? if (!JSON::SkipWhitespace(data)) { FREE_ARRAY(array); return NULL; } // Special case - empty array if (array.size() == 0 && **data == L']') { (*data)++; return new JSONValue(array); } // Get the value JSONValue *value = Parse(data); if (value == NULL) { FREE_ARRAY(array); return NULL; } // Add the value array.push_back(value); // More whitespace? if (!JSON::SkipWhitespace(data)) { FREE_ARRAY(array); return NULL; } // End of array? if (**data == L']') { (*data)++; return new JSONValue(array); } // Want a , now if (**data != L',') { FREE_ARRAY(array); return NULL; } (*data)++; } // Only here if we ran out of data FREE_ARRAY(array); return NULL; } // Ran out of possibilites, it's bad! else { return NULL; } }
/// Matches the string against the wildcard, and if the wildcard is a possible completion of the /// string, the remainder of the string is inserted into the out vector. /// /// We ignore ANY_STRING_RECURSIVE here. The consequence is that you cannot tab complete ** /// wildcards. This is historic behavior. static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc, const wc_complete_pack_t ¶ms, complete_flags_t flags, std::vector<completion_t> *out, bool is_first_call = false) { assert(str != NULL); assert(wc != NULL); // Maybe early out for hidden files. We require that the wildcard match these exactly (i.e. a // dot); ANY_STRING not allowed. if (is_first_call && str[0] == L'.' && wc[0] != L'.') { return false; } // Locate the next wildcard character position, e.g. ANY_CHAR or ANY_STRING. const size_t next_wc_char_pos = wildcard_find(wc); // Maybe we have no more wildcards at all. This includes the empty string. if (next_wc_char_pos == wcstring::npos) { string_fuzzy_match_t match = string_fuzzy_match_string(wc, str); // If we're allowing fuzzy match, any match is OK. Otherwise we require a prefix match. bool match_acceptable; if (params.expand_flags & EXPAND_FUZZY_MATCH) { match_acceptable = match.type != fuzzy_match_none; } else { match_acceptable = match_type_shares_prefix(match.type); } if (!match_acceptable || out == NULL) { return match_acceptable; } // Wildcard complete. bool full_replacement = match_type_requires_full_replacement(match.type) || (flags & COMPLETE_REPLACES_TOKEN); // If we are not replacing the token, be careful to only store the part of the string after // the wildcard. assert(!full_replacement || std::wcslen(wc) <= std::wcslen(str)); wcstring out_completion = full_replacement ? params.orig : str + std::wcslen(wc); wcstring out_desc = resolve_description(params.orig, &out_completion, params.expand_flags, params.desc_func); // Note: out_completion may be empty if the completion really is empty, e.g. tab-completing // 'foo' when a file 'foo' exists. complete_flags_t local_flags = flags | (full_replacement ? COMPLETE_REPLACES_TOKEN : 0); append_completion(out, out_completion, out_desc, local_flags, match); return match_acceptable; } else if (next_wc_char_pos > 0) { // Here we have a non-wildcard prefix. Note that we don't do fuzzy matching for stuff before // a wildcard, so just do case comparison and then recurse. if (std::wcsncmp(str, wc, next_wc_char_pos) == 0) { // Normal match. return wildcard_complete_internal(str + next_wc_char_pos, wc + next_wc_char_pos, params, flags, out); } if (wcsncasecmp(str, wc, next_wc_char_pos) == 0) { // Case insensitive match. return wildcard_complete_internal(str + next_wc_char_pos, wc + next_wc_char_pos, params, flags | COMPLETE_REPLACES_TOKEN, out); } return false; // no match } // Our first character is a wildcard. assert(next_wc_char_pos == 0); switch (wc[0]) { case ANY_CHAR: { if (str[0] == L'\0') { return false; } return wildcard_complete_internal(str + 1, wc + 1, params, flags, out); } case ANY_STRING: { // Hackish. If this is the last character of the wildcard, then just complete with // the empty string. This fixes cases like "f*<tab>" -> "f*o". if (wc[1] == L'\0') { return wildcard_complete_internal(L"", L"", params, flags, out); } // Try all submatches. Issue #929: if the recursive call gives us a prefix match, // just stop. This is sloppy - what we really want to do is say, once we've seen a // match of a particular type, ignore all matches of that type further down the // string, such that the wildcard produces the "minimal match.". bool has_match = false; for (size_t i = 0; str[i] != L'\0'; i++) { const size_t before_count = out ? out->size() : 0; if (wildcard_complete_internal(str + i, wc + 1, params, flags, out)) { // We found a match. has_match = true; // If out is NULL, we don't care about the actual matches. If out is not // NULL but we have a prefix match, stop there. if (out == NULL || has_prefix_match(out, before_count)) { break; } } } return has_match; } case ANY_STRING_RECURSIVE: { // We don't even try with this one. return false; } default: { DIE("unreachable code reached"); break; } } DIE("unreachable code reached"); }
int wcscasecmp(const wchar_t *l, const wchar_t *r) { return wcsncasecmp(l, r, -1); }
int wcsncasecmp_l(const wchar_t* ws1, const wchar_t* ws2, size_t n, locale_t) { return wcsncasecmp(ws1, ws2, n); }
bool string_prefixes_string_case_insensitive(const wcstring &proposed_prefix, const wcstring &value) { size_t prefix_size = proposed_prefix.size(); return prefix_size <= value.size() && wcsncasecmp(proposed_prefix.c_str(), value.c_str(), prefix_size) == 0; }
inline INT CharTraits<WCHAR>::StrICmp( CONST WCHAR* A, CONST WCHAR* B, SIZE_T N ) { return wcsncasecmp( A, B, N ); }