summaryrefslogtreecommitdiff
path: root/crow/include/crow/ci_map.h
blob: bf50fd08a4f7739bdc5bcca28fb98b5c0f4172ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once

#include <algorithm>
#include <iostream>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/functional/hash.hpp>

namespace crow {

struct ci_key_eq {
  bool operator()(const std::string& left, const std::string& right) const {
    unsigned int lsz = left.size();
    unsigned int rsz = right.size();
    for (unsigned int i = 0; i < std::min(lsz, rsz); ++i) {
      auto lchar = tolower(left[i]);
      auto rchar = tolower(right[i]);
      if (lchar != rchar) {
        return lchar < rchar;
      }
    }

    if (rsz != lsz) {
      return lsz < rsz;
    }
    return 0;
  }
};

using ci_map = boost::container::flat_map<std::string, std::string, ci_key_eq>;
}