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 <neilh@scintilla.org>
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 "CharacterSet.h"
13
14using namespace Lexilla;
15
16namespace Lexilla {
17
18int CompareCaseInsensitive(const char *a, const char *b) noexcept {
19 while (*a && *b) {
20 if (*a != *b) {
21 const char upperA = MakeUpperCase(*a);
22 const char upperB = MakeUpperCase(*b);
23 if (upperA != upperB)
24 return upperA - upperB;
25 }
26 a++;
27 b++;
28 }
29 // Either *a or *b is nul
30 return *a - *b;
31}
32
33int CompareNCaseInsensitive(const char *a, const char *b, size_t len) noexcept {
34 while (*a && *b && len) {
35 if (*a != *b) {
36 const char upperA = MakeUpperCase(*a);
37 const char upperB = MakeUpperCase(*b);
38 if (upperA != upperB)
39 return upperA - upperB;
40 }
41 a++;
42 b++;
43 len--;
44 }
45 if (len == 0)
46 return 0;
47 else
48 // Either *a or *b is nul
49 return *a - *b;
50}
51
52}
53