1// Scintilla source code edit control
2/** @file CharacterType.cxx
3 ** Tests for character type and case-insensitive comparisons.
4 **/
5// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
6// The License.txt file describes the conditions under which this software may be distributed.
7
8#include <cstdlib>
9#include <cassert>
10
11#include "CharacterType.h"
12
13using namespace Scintilla::Internal;
14
15namespace Scintilla::Internal {
16
17int CompareCaseInsensitive(const char *a, const char *b) noexcept {
18 while (*a && *b) {
19 if (*a != *b) {
20 const char upperA = MakeUpperCase(*a);
21 const char upperB = MakeUpperCase(*b);
22 if (upperA != upperB)
23 return upperA - upperB;
24 }
25 a++;
26 b++;
27 }
28 // Either *a or *b is nul
29 return *a - *b;
30}
31
32int CompareNCaseInsensitive(const char *a, const char *b, size_t len) noexcept {
33 while (*a && *b && len) {
34 if (*a != *b) {
35 const char upperA = MakeUpperCase(*a);
36 const char upperB = MakeUpperCase(*b);
37 if (upperA != upperB)
38 return upperA - upperB;
39 }
40 a++;
41 b++;
42 len--;
43 }
44 if (len == 0)
45 return 0;
46 else
47 // Either *a or *b is nul
48 return *a - *b;
49}
50
51}
52