-
Notifications
You must be signed in to change notification settings - Fork 1
/
codex.hpp
59 lines (52 loc) · 1.45 KB
/
codex.hpp
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
#pragma once
#include <cstdint>
#include <string>
namespace escape
{
std::string html( const std::string &text );
std::string url( const std::string &text );
std::string uri( const std::string &text );
std::string js( const std::string &text );
}
namespace unescape
{
std::string html( const std::string &text );
std::string url( const std::string &text );
std::string uri( const std::string &text );
std::string js( const std::string &text );
}
namespace encode
{
namespace html
{
// ' -> '
std::string hex( unsigned ch );
// ' -> '
std::string dec( unsigned ch );
}
namespace uri
{
// ' -> %27 ; % -> %25
std::string hex( unsigned ch );
// ( hello, world ) -> hello=world&
std::string strings( const std::string &key, const std::string &value );
}
namespace string
{
// " -> \" ; hello "world" -> hello \"world\"
std::string quote( const std::string &text );
// brace( hello, {} ) -> {hello}
std::string brace( const std::string &text, const char emb[2] = "\"\"" );
}
}
namespace decode
{}
namespace utf8
{
const char* decode(const char* str, int maxbytes, std::uint32_t* result);
const char* encode(std::uint32_t codepoint, char* str);
int strlen(const char* str);
int strnlen(const char* str, int bytes);
bool is_continuation_byte(int byte);
bool is_initial_byte(int byte);
}