contra/source/html_special.cpp
2024-02-19 14:09:28 +01:00

45 lines
984 B
C++

#include "html_special.hpp"
#include <stdint.h>
const size_t html_special_table_size =
sizeof(html_special_table)
/
sizeof(html_special_table[0]);
extern "C"
const char * html_special_table_lookup(const char * const name) {
// XXX: this should be a iterating-decreasing jump search
for (size_t i = 0; i < html_special_table_size; i++) {
if (!strcmp(name, html_special_table[i][0])) {
return html_special_table[i][1];
}
}
return NULL;
}
extern "C"
const char * html_special_to_utf8(const char * const special) {
static std::string r;
r = std::string(special);
trim(r);
uint32_t i;
sscanf(r.c_str(), "%u", &i);
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> conv1;
r = conv1.to_bytes(i);
return r.c_str();
}
extern "C"
const char * utf8_to_html_special(const char * const utf) {
for (size_t i = 0; i < html_special_table_size; i++) {
if (!strcmp(utf, html_special_table[i][2])) {
return html_special_table[i][0];
}
}
return utf;
}