-
Notifications
You must be signed in to change notification settings - Fork 40
/
utility.cpp
60 lines (48 loc) · 1.1 KB
/
utility.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "annotation/utility.hpp"
#include "common/throw.hpp"
#include <string_view>
#include <string>
#include <functional>
#include <stdexcept>
#include <limits>
#include <cstdint>
namespace Kanachan{
namespace{
using std::placeholders::_1;
} // namepsace *unnamed*
std::uint_fast8_t pai2Num(std::string_view const &pai)
{
if (pai.size() != 2u) {
KANACHAN_THROW<std::invalid_argument>(_1) << "pai = " << pai;
}
std::uint_fast8_t base = std::numeric_limits<std::uint_fast8_t>::max();
switch (pai[1u]) {
case 'm':
base = 0u;
break;
case 'p':
base = 10u;
break;
case 's':
base = 20u;
break;
case 'z':
base = 30u;
break;
default:
KANACHAN_THROW<std::invalid_argument>(_1) << "pai = " << pai;
}
std::uint_fast8_t num = pai[0u] - '0';
if (pai[1u] == 'z') {
if (pai[0u] == '0' || pai[0u] >= '8') {
KANACHAN_THROW<std::invalid_argument>(_1) << "pai = " << pai;
}
--num;
}
return base + num;
}
std::uint_fast8_t pai2Num(std::string const &pai)
{
return pai2Num(std::string_view(pai.cbegin(), pai.cend()));
}
} // namespace Kanachan