Design Pattern Examples
Overview of object-oriented design patterns
stricmp.cpp
Go to the documentation of this file.
1
8
9#include <string>
10#include <cstring>
11
12#include "stricmp.h"
13
14namespace Helpers
15{
16 int stricmp(const char* first, const char* second)
17 {
18#ifdef _MSC_VER
19 return _stricmp(first, second);
20#else
21 int result = -1;
22 if (first != nullptr && second != nullptr)
23 {
24 result = 0;
25 while (*first != '\0' && *second != '\0')
26 {
27 char first_c = toupper(*first);
28 char second_c = toupper(*second);
29 if (first_c < second_c)
30 {
31 result = -1;
32 break;
33 }
34 if (first_c > second_c)
35 {
36 result = 1;
37 break;
38 }
39 first++;
40 second++;
41 }
42 if (result == 0 && *first != *second)
43 {
44 // shorter string is lexically before longer string.
45 if (*first == '\0')
46 {
47 result = -1;
48 }
49 else
50 {
51 result = 1;
52 }
53 }
54 }
55 return result;
56#endif
57 }
58
59 int stricmp(const std::string& first, const std::string& second)
60 {
61 return stricmp(first.c_str(), second.c_str());
62 }
63
64} // end namespace
The namespace containing all the "helper" functions in the C++ code.
int stricmp(const char *first, const char *second)
Compare two strings in a case-insensitive manner to determine their alphabetical order relative to ea...
Definition: stricmp.cpp:16
Declaration of the stricmp function, case-insensitive string comparison for narrow character strings.