OILS / data_lang / pyj8.py View on Github | oilshell.org

27 lines, 10 significant
1#!/usr/bin/env python2
2from __future__ import print_function
3
4from mycpp import mylib
5from mycpp.mylib import log
6
7import fastfunc
8
9_ = log
10
11LOSSY_JSON = 1 << 3
12
13
14def WriteString(s, options, buf):
15 # type: (str, int, mylib.BufWriter) -> None
16 """Write encoded J8 string to buffer.
17
18 The C++ version is optimized to avoid the intermediate string.
19 """
20 j8_fallback = not (options & LOSSY_JSON)
21 #print('j8_fallback %d' % j8_fallback)
22 buf.write(fastfunc.J8EncodeString(s, j8_fallback))
23
24
25PartIsUtf8 = fastfunc.PartIsUtf8
26
27# vim: sw=4