OSSIA
Open Scenario System for Interactive Application
constexpr_string_map.hpp
1 #pragma once
2 #include <stdexcept>
3 #include <string_view>
4 
5 namespace ossia
6 {
7 struct small_string
8 {
9  static constexpr int size() { return 64; }
10  char arr[64];
11  constexpr const char& operator[](int i) const { return arr[i]; }
12  constexpr char& operator[](int i) { return arr[i]; }
13 
14  friend constexpr small_string operator+(small_string lhs, small_string rhs)
15  {
16  bool past_lhs = false;
17  int k = 0;
18  for(int i = 0; i < small_string::size(); i++)
19  {
20  if(lhs[i] == 0)
21  {
22 
23  for(int k = 0; k < small_string::size(); k++)
24  {
25  if(i + k > small_string::size())
26  {
27  throw std::runtime_error("string too long");
28  }
29 
30  lhs[i + k] = rhs[k];
31  }
32  }
33  }
34  return lhs;
35  }
36 
37  template <std::size_t N>
38  friend constexpr small_string operator+(small_string lhs, const char (&rhs)[N])
39  {
40  bool past_lhs = false;
41  int k = 0;
42  for(int i = 0; i < size(); i++)
43  {
44  if(lhs[i] == 0)
45  {
46  if(i + N > small_string::size())
47  {
48  throw std::runtime_error("string too long");
49  }
50 
51  for(int k = 0; k < N; k++)
52  {
53  lhs[i + k] = rhs[k];
54  }
55  }
56  }
57  return lhs;
58  }
59 };
60 
61 constexpr small_string to_lower(std::string_view arr)
62 {
63  if(arr.size() > small_string::size())
64  throw std::runtime_error("string too long");
65 
66  small_string s{};
67  int i = 0;
68  for(; i < arr.size(); i++)
69  {
70  char in = arr[i];
71  if(in <= 'Z' && in >= 'A')
72  s[i] = in - ('Z' - 'z');
73  }
74  s[i + 1] = 0;
75  return s;
76 }
77 }
Definition: git_info.h:7