MiKTeX 26.5-next
A scalable TeX distribution
Loading...
Searching...
No Matches
ci_string.h
1// see: http://www.gotw.ca/gotw/029.htm
2
3#pragma once
4
5#if !defined(E034F645499649F392B9201728F88A26)
6#define E034F645499649F392B9201728F88A26
7
8#include <miktex/Core/config.h>
9
10#include <cctype>
11#include <functional>
12#include <string>
13
15
16#include "Debug.h"
17
18MIKTEX_CORE_BEGIN_NAMESPACE;
19
21 public std::char_traits<char>
22{
23 static bool eq(char ch1, char ch2)
24 {
25 MIKTEX_ASSERT(static_cast<unsigned>(ch1) < 128 && static_cast<unsigned>(ch2) < 128);
26 return tolower(ch1) == tolower(ch2);
27 }
28
29 static bool lt(char ch1, char ch2)
30 {
31 MIKTEX_ASSERT(static_cast<unsigned>(ch1) < 128 && static_cast<unsigned>(ch2) < 128);
32 return tolower(ch1) < tolower(ch2);
33 }
34
35 static int compare(const char* s1, const char* s2, size_t n)
36 {
37 return MiKTeX::Util::CeeStringCompare(s1, s2, n, true);
38 }
39
40 static const char* find(const char* s, int n, const char& ch)
41 {
42 while (n-- > 0 && tolower(*s) != tolower(ch))
43 {
44 ++s;
45 }
46 return s;
47 }
48};
49
50typedef std::basic_string<char, ci_char_traits> ci_string;
51
52MIKTEX_CORE_END_NAMESPACE;
53
54namespace std
55{
56 template <> struct hash<MiKTeX::Core::ci_string>
57 {
58 size_t operator()(const MiKTeX::Core::ci_string& str) const
59 {
60 // see http://www.isthe.com/chongo/tech/comp/fnv/index.html
61#if defined(_M_AMD64) || defined(_M_X64) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(__arch64__)
62 MIKTEX_ASSERT(sizeof(size_t) == 8);
63 const size_t FNV_prime = 1099511628211ULL;
64 const size_t offset_basis = 14695981039346656037ULL;
65#else
66 MIKTEX_ASSERT(sizeof(size_t) == 4);
67 const size_t FNV_prime = 16777619;
68 const size_t offset_basis = 2166136261;
69#endif
70 size_t hash = offset_basis;
71 for (MiKTeX::Core::ci_string::const_iterator it = str.begin(); it != str.end(); ++it)
72 {
73 char ch = *it;
74 MIKTEX_ASSERT(static_cast<unsigned>(ch) < 128);
75 ch = tolower(ch);
76 hash ^= (size_t)ch;
77 hash *= FNV_prime;
78 }
79 return hash;
80 }
81 };
82}
83
84#endif
Inline functions.
Definition ci_string.h:22