[gnome-characters/wip/exalm/unistring: 8/15] lib: Add a script for generating blocks
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters/wip/exalm/unistring: 8/15] lib: Add a script for generating blocks
- Date: Fri, 26 Nov 2021 09:25:03 +0000 (UTC)
commit 710f60d80a401dbb5e65169ddd9a4505dd1474d8
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Fri Nov 26 04:36:18 2021 +0500
lib: Add a script for generating blocks
We'll need this too.
lib/gen-blocks.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
---
diff --git a/lib/gen-blocks.py b/lib/gen-blocks.py
new file mode 100755
index 0000000..2c2181a
--- /dev/null
+++ b/lib/gen-blocks.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python3
+
+# Input: https://www.unicode.org/Public/UNIDATA/Blocks.txt
+
+import io
+import re
+
+class Builder(object):
+ def __init__(self):
+ pass
+
+ def read(self, infile):
+ names = []
+ for line in infile:
+ if line.startswith('#'):
+ continue
+ line = line.strip()
+ if len(line) == 0:
+ continue
+ range, name = line.split(';', 2)
+ start, end = range.split('..')
+ name = name.lstrip()
+
+ names.append((start, end, name))
+
+ return names
+
+ def write(self, data):
+ print('''\
+struct Block
+{
+ gunichar start;
+ gunichar end;
+ const char *name;
+};''')
+ print('static const struct Block all_blocks[] =\n {')
+ s = ''
+ offset = 0
+ for start, end, name in data:
+ print(' {{ 0x{0}, 0x{1}, "{2}" }},'.format(start, end, name))
+ print(' };')
+
+if __name__ == '__main__':
+ import argparse
+
+ parser = argparse.ArgumentParser(description='build')
+ parser.add_argument('infile', type=argparse.FileType('r'),
+ help='input file')
+ args = parser.parse_args()
+
+ builder = Builder()
+ # FIXME: argparse.FileType(encoding=...) is available since Python 3.4
+ data = builder.read(io.open(args.infile.name, encoding='utf_8_sig'))
+ builder.write(data)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]