-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathunidecode.hpp
More file actions
43 lines (32 loc) · 1.23 KB
/
unidecode.hpp
File metadata and controls
43 lines (32 loc) · 1.23 KB
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
//
// Created by Marek on 30.9.2019.
//
#pragma once
#include "common.hpp"
#include "sections.hpp"
namespace unidecode {
template<typename InputIterator, typename OutputIterator>
void Unidecode(const InputIterator& in_begin, const InputIterator& in_end, OutputIterator out_it) {
for (auto it = in_begin; it != in_end; ++it) {
unicode_char codepoint = *it;
// TODO: function from this !
if (codepoint < 0x80) {
*out_it = static_cast<char>(codepoint);
++out_it;
} else if (codepoint <= 0xeffff) { // Characters in Private Use Area and above are ignored
uint32_t section = codepoint >> 8;
uint32_t position = codepoint & 0xff; // only ast two hex digits
// TODO: assert section < then xyz
auto table = kUnidecodeData[section];
if (table != nullptr) { // TODO: check if position < table size
const char* symbol = table[position];
while (*symbol != 0) {
*out_it = *symbol;
++out_it;
symbol++;
}
}
}
}
}
}