Make installation only need a C++11 compiler
diff --git a/MANIFEST.in b/MANIFEST.in
index 31e80ce..0b8f63a 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,4 +1,5 @@
include LICENSE
+include make_escape_dct.py
include Makefile
include pyjson5.cpp
include pyjson5.pyx
diff --git a/make_escape_dct.py b/make_escape_dct.py
new file mode 100644
index 0000000..20955e4
--- /dev/null
+++ b/make_escape_dct.py
@@ -0,0 +1,44 @@
+from os.path import join, abspath, dirname
+
+
+def generate():
+ unescaped = 0
+ with open('./src/_escape_dct.hpp', 'wt') as f:
+ print('const EscapeDct::Items EscapeDct::items = {', file=f)
+ for c in range(0x100):
+ if c == ord('\\'):
+ s = '\\\\'
+ elif c == ord('\b'):
+ s = '\\b'
+ elif c == ord('\f'):
+ s = '\\f'
+ elif c == ord('\n'):
+ s = '\\n'
+ elif c == ord('\r'):
+ s = '\\r'
+ elif c == ord('\t'):
+ s = '\\t'
+ elif (c < 0x20) or (c >= 0x7f) or (chr(c) in '''"'&<>\\'''):
+ s = f'\\u{c:04x}'
+ else:
+ s = f'{c:c}'
+ if c < 128:
+ unescaped |= 1 << c
+
+ t = [
+ f"'{c}'" if c != '\\' else f"'\\\\'"
+ for c in s
+ ] + ['0'] * 7
+ t[7] = f'{len(s)}'
+ print(' {' + ', '.join(t[:8]) + '},', file=f)
+ print('};', file=f)
+
+ escaped = unescaped ^ ((1 << 128) - 1)
+ print('const unsigned __int128 EscapeDct::is_escaped_array = (', file=f)
+ print(f' ((unsigned __int128) 0x{(escaped >> 64):016x} << 64) |', file=f)
+ print(f' ((unsigned __int128) 0x{(escaped & ((1 << 64) - 1)):016x})', file=f)
+ print(');', file=f)
+
+
+if __name__ == '__main__':
+ generate()
diff --git a/setup.py b/setup.py
index ec9fe7e..13de9f3 100755
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,7 @@
extra_compile_args = [
- '-std=c++14', '-O2', '-fPIC', '-ggdb1', '-pipe',
+ '-std=c++11', '-O2', '-fPIC', '-ggdb1', '-pipe',
'-fomit-frame-pointer', '-fstack-protector-strong',
]
diff --git a/src/VERSION b/src/VERSION
index 8b90190..99543d9 100644
--- a/src/VERSION
+++ b/src/VERSION
@@ -1 +1 @@
-"0.4.4"
+"0.4.5"
diff --git a/src/_escape_dct.hpp b/src/_escape_dct.hpp
new file mode 100644
index 0000000..e895cda
--- /dev/null
+++ b/src/_escape_dct.hpp
@@ -0,0 +1,262 @@
+const EscapeDct::Items EscapeDct::items = {
+ {'\\', 'u', '0', '0', '0', '0', 0, 6},
+ {'\\', 'u', '0', '0', '0', '1', 0, 6},
+ {'\\', 'u', '0', '0', '0', '2', 0, 6},
+ {'\\', 'u', '0', '0', '0', '3', 0, 6},
+ {'\\', 'u', '0', '0', '0', '4', 0, 6},
+ {'\\', 'u', '0', '0', '0', '5', 0, 6},
+ {'\\', 'u', '0', '0', '0', '6', 0, 6},
+ {'\\', 'u', '0', '0', '0', '7', 0, 6},
+ {'\\', 'b', 0, 0, 0, 0, 0, 2},
+ {'\\', 't', 0, 0, 0, 0, 0, 2},
+ {'\\', 'n', 0, 0, 0, 0, 0, 2},
+ {'\\', 'u', '0', '0', '0', 'b', 0, 6},
+ {'\\', 'f', 0, 0, 0, 0, 0, 2},
+ {'\\', 'r', 0, 0, 0, 0, 0, 2},
+ {'\\', 'u', '0', '0', '0', 'e', 0, 6},
+ {'\\', 'u', '0', '0', '0', 'f', 0, 6},
+ {'\\', 'u', '0', '0', '1', '0', 0, 6},
+ {'\\', 'u', '0', '0', '1', '1', 0, 6},
+ {'\\', 'u', '0', '0', '1', '2', 0, 6},
+ {'\\', 'u', '0', '0', '1', '3', 0, 6},
+ {'\\', 'u', '0', '0', '1', '4', 0, 6},
+ {'\\', 'u', '0', '0', '1', '5', 0, 6},
+ {'\\', 'u', '0', '0', '1', '6', 0, 6},
+ {'\\', 'u', '0', '0', '1', '7', 0, 6},
+ {'\\', 'u', '0', '0', '1', '8', 0, 6},
+ {'\\', 'u', '0', '0', '1', '9', 0, 6},
+ {'\\', 'u', '0', '0', '1', 'a', 0, 6},
+ {'\\', 'u', '0', '0', '1', 'b', 0, 6},
+ {'\\', 'u', '0', '0', '1', 'c', 0, 6},
+ {'\\', 'u', '0', '0', '1', 'd', 0, 6},
+ {'\\', 'u', '0', '0', '1', 'e', 0, 6},
+ {'\\', 'u', '0', '0', '1', 'f', 0, 6},
+ {' ', 0, 0, 0, 0, 0, 0, 1},
+ {'!', 0, 0, 0, 0, 0, 0, 1},
+ {'\\', 'u', '0', '0', '2', '2', 0, 6},
+ {'#', 0, 0, 0, 0, 0, 0, 1},
+ {'$', 0, 0, 0, 0, 0, 0, 1},
+ {'%', 0, 0, 0, 0, 0, 0, 1},
+ {'\\', 'u', '0', '0', '2', '6', 0, 6},
+ {'\\', 'u', '0', '0', '2', '7', 0, 6},
+ {'(', 0, 0, 0, 0, 0, 0, 1},
+ {')', 0, 0, 0, 0, 0, 0, 1},
+ {'*', 0, 0, 0, 0, 0, 0, 1},
+ {'+', 0, 0, 0, 0, 0, 0, 1},
+ {',', 0, 0, 0, 0, 0, 0, 1},
+ {'-', 0, 0, 0, 0, 0, 0, 1},
+ {'.', 0, 0, 0, 0, 0, 0, 1},
+ {'/', 0, 0, 0, 0, 0, 0, 1},
+ {'0', 0, 0, 0, 0, 0, 0, 1},
+ {'1', 0, 0, 0, 0, 0, 0, 1},
+ {'2', 0, 0, 0, 0, 0, 0, 1},
+ {'3', 0, 0, 0, 0, 0, 0, 1},
+ {'4', 0, 0, 0, 0, 0, 0, 1},
+ {'5', 0, 0, 0, 0, 0, 0, 1},
+ {'6', 0, 0, 0, 0, 0, 0, 1},
+ {'7', 0, 0, 0, 0, 0, 0, 1},
+ {'8', 0, 0, 0, 0, 0, 0, 1},
+ {'9', 0, 0, 0, 0, 0, 0, 1},
+ {':', 0, 0, 0, 0, 0, 0, 1},
+ {';', 0, 0, 0, 0, 0, 0, 1},
+ {'\\', 'u', '0', '0', '3', 'c', 0, 6},
+ {'=', 0, 0, 0, 0, 0, 0, 1},
+ {'\\', 'u', '0', '0', '3', 'e', 0, 6},
+ {'?', 0, 0, 0, 0, 0, 0, 1},
+ {'@', 0, 0, 0, 0, 0, 0, 1},
+ {'A', 0, 0, 0, 0, 0, 0, 1},
+ {'B', 0, 0, 0, 0, 0, 0, 1},
+ {'C', 0, 0, 0, 0, 0, 0, 1},
+ {'D', 0, 0, 0, 0, 0, 0, 1},
+ {'E', 0, 0, 0, 0, 0, 0, 1},
+ {'F', 0, 0, 0, 0, 0, 0, 1},
+ {'G', 0, 0, 0, 0, 0, 0, 1},
+ {'H', 0, 0, 0, 0, 0, 0, 1},
+ {'I', 0, 0, 0, 0, 0, 0, 1},
+ {'J', 0, 0, 0, 0, 0, 0, 1},
+ {'K', 0, 0, 0, 0, 0, 0, 1},
+ {'L', 0, 0, 0, 0, 0, 0, 1},
+ {'M', 0, 0, 0, 0, 0, 0, 1},
+ {'N', 0, 0, 0, 0, 0, 0, 1},
+ {'O', 0, 0, 0, 0, 0, 0, 1},
+ {'P', 0, 0, 0, 0, 0, 0, 1},
+ {'Q', 0, 0, 0, 0, 0, 0, 1},
+ {'R', 0, 0, 0, 0, 0, 0, 1},
+ {'S', 0, 0, 0, 0, 0, 0, 1},
+ {'T', 0, 0, 0, 0, 0, 0, 1},
+ {'U', 0, 0, 0, 0, 0, 0, 1},
+ {'V', 0, 0, 0, 0, 0, 0, 1},
+ {'W', 0, 0, 0, 0, 0, 0, 1},
+ {'X', 0, 0, 0, 0, 0, 0, 1},
+ {'Y', 0, 0, 0, 0, 0, 0, 1},
+ {'Z', 0, 0, 0, 0, 0, 0, 1},
+ {'[', 0, 0, 0, 0, 0, 0, 1},
+ {'\\', '\\', 0, 0, 0, 0, 0, 2},
+ {']', 0, 0, 0, 0, 0, 0, 1},
+ {'^', 0, 0, 0, 0, 0, 0, 1},
+ {'_', 0, 0, 0, 0, 0, 0, 1},
+ {'`', 0, 0, 0, 0, 0, 0, 1},
+ {'a', 0, 0, 0, 0, 0, 0, 1},
+ {'b', 0, 0, 0, 0, 0, 0, 1},
+ {'c', 0, 0, 0, 0, 0, 0, 1},
+ {'d', 0, 0, 0, 0, 0, 0, 1},
+ {'e', 0, 0, 0, 0, 0, 0, 1},
+ {'f', 0, 0, 0, 0, 0, 0, 1},
+ {'g', 0, 0, 0, 0, 0, 0, 1},
+ {'h', 0, 0, 0, 0, 0, 0, 1},
+ {'i', 0, 0, 0, 0, 0, 0, 1},
+ {'j', 0, 0, 0, 0, 0, 0, 1},
+ {'k', 0, 0, 0, 0, 0, 0, 1},
+ {'l', 0, 0, 0, 0, 0, 0, 1},
+ {'m', 0, 0, 0, 0, 0, 0, 1},
+ {'n', 0, 0, 0, 0, 0, 0, 1},
+ {'o', 0, 0, 0, 0, 0, 0, 1},
+ {'p', 0, 0, 0, 0, 0, 0, 1},
+ {'q', 0, 0, 0, 0, 0, 0, 1},
+ {'r', 0, 0, 0, 0, 0, 0, 1},
+ {'s', 0, 0, 0, 0, 0, 0, 1},
+ {'t', 0, 0, 0, 0, 0, 0, 1},
+ {'u', 0, 0, 0, 0, 0, 0, 1},
+ {'v', 0, 0, 0, 0, 0, 0, 1},
+ {'w', 0, 0, 0, 0, 0, 0, 1},
+ {'x', 0, 0, 0, 0, 0, 0, 1},
+ {'y', 0, 0, 0, 0, 0, 0, 1},
+ {'z', 0, 0, 0, 0, 0, 0, 1},
+ {'{', 0, 0, 0, 0, 0, 0, 1},
+ {'|', 0, 0, 0, 0, 0, 0, 1},
+ {'}', 0, 0, 0, 0, 0, 0, 1},
+ {'~', 0, 0, 0, 0, 0, 0, 1},
+ {'\\', 'u', '0', '0', '7', 'f', 0, 6},
+ {'\\', 'u', '0', '0', '8', '0', 0, 6},
+ {'\\', 'u', '0', '0', '8', '1', 0, 6},
+ {'\\', 'u', '0', '0', '8', '2', 0, 6},
+ {'\\', 'u', '0', '0', '8', '3', 0, 6},
+ {'\\', 'u', '0', '0', '8', '4', 0, 6},
+ {'\\', 'u', '0', '0', '8', '5', 0, 6},
+ {'\\', 'u', '0', '0', '8', '6', 0, 6},
+ {'\\', 'u', '0', '0', '8', '7', 0, 6},
+ {'\\', 'u', '0', '0', '8', '8', 0, 6},
+ {'\\', 'u', '0', '0', '8', '9', 0, 6},
+ {'\\', 'u', '0', '0', '8', 'a', 0, 6},
+ {'\\', 'u', '0', '0', '8', 'b', 0, 6},
+ {'\\', 'u', '0', '0', '8', 'c', 0, 6},
+ {'\\', 'u', '0', '0', '8', 'd', 0, 6},
+ {'\\', 'u', '0', '0', '8', 'e', 0, 6},
+ {'\\', 'u', '0', '0', '8', 'f', 0, 6},
+ {'\\', 'u', '0', '0', '9', '0', 0, 6},
+ {'\\', 'u', '0', '0', '9', '1', 0, 6},
+ {'\\', 'u', '0', '0', '9', '2', 0, 6},
+ {'\\', 'u', '0', '0', '9', '3', 0, 6},
+ {'\\', 'u', '0', '0', '9', '4', 0, 6},
+ {'\\', 'u', '0', '0', '9', '5', 0, 6},
+ {'\\', 'u', '0', '0', '9', '6', 0, 6},
+ {'\\', 'u', '0', '0', '9', '7', 0, 6},
+ {'\\', 'u', '0', '0', '9', '8', 0, 6},
+ {'\\', 'u', '0', '0', '9', '9', 0, 6},
+ {'\\', 'u', '0', '0', '9', 'a', 0, 6},
+ {'\\', 'u', '0', '0', '9', 'b', 0, 6},
+ {'\\', 'u', '0', '0', '9', 'c', 0, 6},
+ {'\\', 'u', '0', '0', '9', 'd', 0, 6},
+ {'\\', 'u', '0', '0', '9', 'e', 0, 6},
+ {'\\', 'u', '0', '0', '9', 'f', 0, 6},
+ {'\\', 'u', '0', '0', 'a', '0', 0, 6},
+ {'\\', 'u', '0', '0', 'a', '1', 0, 6},
+ {'\\', 'u', '0', '0', 'a', '2', 0, 6},
+ {'\\', 'u', '0', '0', 'a', '3', 0, 6},
+ {'\\', 'u', '0', '0', 'a', '4', 0, 6},
+ {'\\', 'u', '0', '0', 'a', '5', 0, 6},
+ {'\\', 'u', '0', '0', 'a', '6', 0, 6},
+ {'\\', 'u', '0', '0', 'a', '7', 0, 6},
+ {'\\', 'u', '0', '0', 'a', '8', 0, 6},
+ {'\\', 'u', '0', '0', 'a', '9', 0, 6},
+ {'\\', 'u', '0', '0', 'a', 'a', 0, 6},
+ {'\\', 'u', '0', '0', 'a', 'b', 0, 6},
+ {'\\', 'u', '0', '0', 'a', 'c', 0, 6},
+ {'\\', 'u', '0', '0', 'a', 'd', 0, 6},
+ {'\\', 'u', '0', '0', 'a', 'e', 0, 6},
+ {'\\', 'u', '0', '0', 'a', 'f', 0, 6},
+ {'\\', 'u', '0', '0', 'b', '0', 0, 6},
+ {'\\', 'u', '0', '0', 'b', '1', 0, 6},
+ {'\\', 'u', '0', '0', 'b', '2', 0, 6},
+ {'\\', 'u', '0', '0', 'b', '3', 0, 6},
+ {'\\', 'u', '0', '0', 'b', '4', 0, 6},
+ {'\\', 'u', '0', '0', 'b', '5', 0, 6},
+ {'\\', 'u', '0', '0', 'b', '6', 0, 6},
+ {'\\', 'u', '0', '0', 'b', '7', 0, 6},
+ {'\\', 'u', '0', '0', 'b', '8', 0, 6},
+ {'\\', 'u', '0', '0', 'b', '9', 0, 6},
+ {'\\', 'u', '0', '0', 'b', 'a', 0, 6},
+ {'\\', 'u', '0', '0', 'b', 'b', 0, 6},
+ {'\\', 'u', '0', '0', 'b', 'c', 0, 6},
+ {'\\', 'u', '0', '0', 'b', 'd', 0, 6},
+ {'\\', 'u', '0', '0', 'b', 'e', 0, 6},
+ {'\\', 'u', '0', '0', 'b', 'f', 0, 6},
+ {'\\', 'u', '0', '0', 'c', '0', 0, 6},
+ {'\\', 'u', '0', '0', 'c', '1', 0, 6},
+ {'\\', 'u', '0', '0', 'c', '2', 0, 6},
+ {'\\', 'u', '0', '0', 'c', '3', 0, 6},
+ {'\\', 'u', '0', '0', 'c', '4', 0, 6},
+ {'\\', 'u', '0', '0', 'c', '5', 0, 6},
+ {'\\', 'u', '0', '0', 'c', '6', 0, 6},
+ {'\\', 'u', '0', '0', 'c', '7', 0, 6},
+ {'\\', 'u', '0', '0', 'c', '8', 0, 6},
+ {'\\', 'u', '0', '0', 'c', '9', 0, 6},
+ {'\\', 'u', '0', '0', 'c', 'a', 0, 6},
+ {'\\', 'u', '0', '0', 'c', 'b', 0, 6},
+ {'\\', 'u', '0', '0', 'c', 'c', 0, 6},
+ {'\\', 'u', '0', '0', 'c', 'd', 0, 6},
+ {'\\', 'u', '0', '0', 'c', 'e', 0, 6},
+ {'\\', 'u', '0', '0', 'c', 'f', 0, 6},
+ {'\\', 'u', '0', '0', 'd', '0', 0, 6},
+ {'\\', 'u', '0', '0', 'd', '1', 0, 6},
+ {'\\', 'u', '0', '0', 'd', '2', 0, 6},
+ {'\\', 'u', '0', '0', 'd', '3', 0, 6},
+ {'\\', 'u', '0', '0', 'd', '4', 0, 6},
+ {'\\', 'u', '0', '0', 'd', '5', 0, 6},
+ {'\\', 'u', '0', '0', 'd', '6', 0, 6},
+ {'\\', 'u', '0', '0', 'd', '7', 0, 6},
+ {'\\', 'u', '0', '0', 'd', '8', 0, 6},
+ {'\\', 'u', '0', '0', 'd', '9', 0, 6},
+ {'\\', 'u', '0', '0', 'd', 'a', 0, 6},
+ {'\\', 'u', '0', '0', 'd', 'b', 0, 6},
+ {'\\', 'u', '0', '0', 'd', 'c', 0, 6},
+ {'\\', 'u', '0', '0', 'd', 'd', 0, 6},
+ {'\\', 'u', '0', '0', 'd', 'e', 0, 6},
+ {'\\', 'u', '0', '0', 'd', 'f', 0, 6},
+ {'\\', 'u', '0', '0', 'e', '0', 0, 6},
+ {'\\', 'u', '0', '0', 'e', '1', 0, 6},
+ {'\\', 'u', '0', '0', 'e', '2', 0, 6},
+ {'\\', 'u', '0', '0', 'e', '3', 0, 6},
+ {'\\', 'u', '0', '0', 'e', '4', 0, 6},
+ {'\\', 'u', '0', '0', 'e', '5', 0, 6},
+ {'\\', 'u', '0', '0', 'e', '6', 0, 6},
+ {'\\', 'u', '0', '0', 'e', '7', 0, 6},
+ {'\\', 'u', '0', '0', 'e', '8', 0, 6},
+ {'\\', 'u', '0', '0', 'e', '9', 0, 6},
+ {'\\', 'u', '0', '0', 'e', 'a', 0, 6},
+ {'\\', 'u', '0', '0', 'e', 'b', 0, 6},
+ {'\\', 'u', '0', '0', 'e', 'c', 0, 6},
+ {'\\', 'u', '0', '0', 'e', 'd', 0, 6},
+ {'\\', 'u', '0', '0', 'e', 'e', 0, 6},
+ {'\\', 'u', '0', '0', 'e', 'f', 0, 6},
+ {'\\', 'u', '0', '0', 'f', '0', 0, 6},
+ {'\\', 'u', '0', '0', 'f', '1', 0, 6},
+ {'\\', 'u', '0', '0', 'f', '2', 0, 6},
+ {'\\', 'u', '0', '0', 'f', '3', 0, 6},
+ {'\\', 'u', '0', '0', 'f', '4', 0, 6},
+ {'\\', 'u', '0', '0', 'f', '5', 0, 6},
+ {'\\', 'u', '0', '0', 'f', '6', 0, 6},
+ {'\\', 'u', '0', '0', 'f', '7', 0, 6},
+ {'\\', 'u', '0', '0', 'f', '8', 0, 6},
+ {'\\', 'u', '0', '0', 'f', '9', 0, 6},
+ {'\\', 'u', '0', '0', 'f', 'a', 0, 6},
+ {'\\', 'u', '0', '0', 'f', 'b', 0, 6},
+ {'\\', 'u', '0', '0', 'f', 'c', 0, 6},
+ {'\\', 'u', '0', '0', 'f', 'd', 0, 6},
+ {'\\', 'u', '0', '0', 'f', 'e', 0, 6},
+ {'\\', 'u', '0', '0', 'f', 'f', 0, 6},
+};
+const unsigned __int128 EscapeDct::is_escaped_array = (
+ ((unsigned __int128) 0x8000000010000000 << 64) |
+ ((unsigned __int128) 0x500000c4ffffffff)
+);
diff --git a/src/native.hpp b/src/native.hpp
index 4dcbce0..be1b650 100644
--- a/src/native.hpp
+++ b/src/native.hpp
@@ -5,7 +5,6 @@
#include <type_traits>
namespace JSON5EncoderCpp {
-inline namespace {
template <class From>
constexpr std::uint32_t cast_to_uint32(
@@ -24,33 +23,30 @@
std::is_signed<From>::value
>::type* = nullptr
) {
- using UnsignedFrom = typename std::make_unsigned<From>::type;
- UnsignedFrom unsigned_from = static_cast<UnsignedFrom>(from);
- return cast_to_uint32(unsigned_from);
+ return cast_to_uint32(static_cast<typename std::make_unsigned<From>::type>(from));
}
template <class From>
constexpr std::int32_t cast_to_int32(const From &from) {
- std::uint32_t unsigned_from = cast_to_uint32(from);
- return static_cast<std::int32_t>(unsigned_from);
+ return static_cast<std::int32_t>(cast_to_uint32(from));
}
struct AlwaysTrue {
- constexpr inline AlwaysTrue() = default;
+ inline AlwaysTrue() = default;
inline ~AlwaysTrue() = default;
- constexpr inline AlwaysTrue(const AlwaysTrue&) = default;
- constexpr inline AlwaysTrue(AlwaysTrue&&) = default;
- constexpr inline AlwaysTrue &operator =(const AlwaysTrue&) = default;
- constexpr inline AlwaysTrue &operator =(AlwaysTrue&&) = default;
+ inline AlwaysTrue(const AlwaysTrue&) = default;
+ inline AlwaysTrue(AlwaysTrue&&) = default;
+ inline AlwaysTrue &operator =(const AlwaysTrue&) = default;
+ inline AlwaysTrue &operator =(AlwaysTrue&&) = default;
template <class T>
- constexpr inline AlwaysTrue(T&&) : AlwaysTrue() {}
+ inline AlwaysTrue(T&&) : AlwaysTrue() {}
template <class T>
- constexpr inline bool operator ==(T&&) const { return true; }
+ inline bool operator ==(T&&) const { return true; }
- constexpr inline operator bool () const { return true; }
+ inline operator bool () const { return true; }
};
bool obj_has_iter(const PyObject *obj) {
@@ -63,91 +59,30 @@
struct EscapeDct {
using Item = std::array<char, 8>; // 7 are needed, 1 length
static constexpr std::size_t length = 0x100;
+ using Items = Item[length];
- Item items[length];
- unsigned __int128 is_escaped_array;
+ static const Items items;
+ static const unsigned __int128 is_escaped_array;
- static constexpr Item unicode_item(size_t index) {
- return {{
- '\\',
- 'u',
- HEX[(index / 16 / 16 / 16 % 16)],
- HEX[(index / 16 / 16 % 16)],
- HEX[(index / 16 % 16)],
- HEX[(index % 16)],
- 0,
- 6,
- }};
- }
-
- static constexpr Item escaped_item(char chr) {
- return {{ '\\', chr, 0, 0, 0, 0, 0, 2 }};
- }
-
- static constexpr Item verbatim_item(size_t chr) {
- return {{ (char) (unsigned char) chr, 0, 0, 0, 0, 0, 0, 1 }};
- }
-
- inline bool is_escaped(std::uint32_t c) const {
+ static inline bool is_escaped(std::uint32_t c) {
return (c >= 0x0080) || (is_escaped_array & (
static_cast<unsigned __int128>(1) <<
static_cast<std::uint8_t>(c)
));
}
- inline std::size_t find_unescaped_range(const Py_UCS1 *start, Py_ssize_t length) const {
+ template <class S>
+ static inline std::size_t find_unescaped_range(const S *start, Py_ssize_t length) {
Py_ssize_t index = 0;
while ((index < length) && !is_escaped(start[index])) {
++index;
}
return index;
}
-
- inline std::size_t find_unescaped_range(const Py_UCS2 *start, Py_ssize_t length) const {
- Py_ssize_t index = 0;
- while ((index < length) && !is_escaped(start[index])) {
- ++index;
- }
- return index;
- }
-
- inline std::size_t find_unescaped_range(const Py_UCS4 *start, Py_ssize_t length) const {
- Py_ssize_t index = 0;
- while ((index < length) && !is_escaped(start[index])) {
- ++index;
- }
- return index;
- }
-
- constexpr EscapeDct() :
- items(),
- is_escaped_array(static_cast<unsigned __int128>(0) - 1)
- {
- for (std::size_t i = 0; i < length; ++i) {
- items[i] = unicode_item(i);
- }
- for (std::size_t i = 0x20; i < 0x7f; ++i) {
- switch (i) {
- case '"': case '\'': case '&': case '<': case '>': case '\\':
- break;
- default:
- items[i] = verbatim_item(i);
-
- is_escaped_array &= ~(
- static_cast<unsigned __int128>(1) <<
- static_cast<std::uint8_t>(i)
- );
- }
- }
- items[(std::uint8_t) '\\'] = escaped_item('\\');
- items[(std::uint8_t) '\b'] = escaped_item('b');
- items[(std::uint8_t) '\f'] = escaped_item('f');
- items[(std::uint8_t) '\n'] = escaped_item('n');
- items[(std::uint8_t) '\r'] = escaped_item('r');
- items[(std::uint8_t) '\t'] = escaped_item('t');
- }
};
+#include "./_escape_dct.hpp"
+
const EscapeDct ESCAPE_DCT;
const char VERSION[] =
@@ -161,4 +96,3 @@
static constexpr std::size_t LONGDESCRIPTION_LENGTH = sizeof(LONGDESCRIPTION) - 1;
}
-}