| 1 |
// Scintilla source code edit control |
| 2 |
/** @file CharacterSet.cxx |
| 3 |
** Simple case functions for ASCII. |
| 4 |
** Lexer infrastructure. |
| 5 |
**/ |
| 6 |
// Copyright 1998-2010 by Neil Hodgson <[email protected]> |
| 7 |
// The License.txt file describes the conditions under which this software may be distributed. |
| 8 |
|
| 9 |
#include <cstdlib> |
| 10 |
#include <cassert> |
| 11 |
|
| 12 |
#include <string_view> |
| 13 |
|
| 14 |
#include "CharacterSet.h" |
| 15 |
|
| 16 |
using namespace Lexilla; |
| 17 |
|
| 18 |
namespace Lexilla { |
| 19 |
|
| 20 |
int CompareCaseInsensitive(const char *a, const char *b) noexcept { |
| 21 |
while (*a && *b) { |
| 22 |
if (*a != *b) { |
| 23 |
const char upperA = MakeUpperCase(*a); |
| 24 |
const char upperB = MakeUpperCase(*b); |
| 25 |
if (upperA != upperB) |
| 26 |
return upperA - upperB; |
| 27 |
} |
| 28 |
a++; |
| 29 |
b++; |
| 30 |
} |
| 31 |
// Either *a or *b is nul |
| 32 |
return *a - *b; |
| 33 |
} |
| 34 |
|
| 35 |
bool EqualCaseInsensitive(std::string_view a, std::string_view b) noexcept { |
| 36 |
if (a.length() != b.length()) { |
| 37 |
return false; |
| 38 |
} |
| 39 |
for (size_t i = 0; i < a.length(); i++) { |
| 40 |
if (MakeUpperCase(a[i]) != MakeUpperCase(b[i])) { |
| 41 |
return false; |
| 42 |
} |
| 43 |
} |
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
int CompareNCaseInsensitive(const char *a, const char *b, size_t len) noexcept { |
| 48 |
while (*a && *b && len) { |
| 49 |
if (*a != *b) { |
| 50 |
const char upperA = MakeUpperCase(*a); |
| 51 |
const char upperB = MakeUpperCase(*b); |
| 52 |
if (upperA != upperB) |
| 53 |
return upperA - upperB; |
| 54 |
} |
| 55 |
a++; |
| 56 |
b++; |
| 57 |
len--; |
| 58 |
} |
| 59 |
if (len == 0) |
| 60 |
return 0; |
| 61 |
else |
| 62 |
// Either *a or *b is nul |
| 63 |
return *a - *b; |
| 64 |
} |
| 65 |
|
| 66 |
} |