source: icGREP/icgrep-devel/UCD-scripts/cformat.py

Last change on this file was 6192, checked in by cameron, 10 months ago

Updates for Unicode 11.0 plus Emoji properties

File size: 2.1 KB
Line 
1import UCD_config, sys, time, re
2from datetime import date
3
4header_template = r"""#ifndef %s
5#define %s
6/*
7 *  Copyright (c) %s International Characters, Inc.
8 *  This software is licensed to the public under the Open Software License 3.0.
9 *  icgrep is a trademark of International Characters, Inc.
10 *
11 *  This file is generated by %s - manual edits may be lost.
12 */
13
14"""
15
16cpp_template = r"""
17/*
18 *  Copyright (c) %s International Characters, Inc.
19 *  This software is licensed to the public under the Open Software License 3.0.
20 *  icgrep is a trademark of International Characters, Inc.
21 *
22 *  This file is generated by %s - manual edits may be lost.
23 */
24
25#include "%s.h"
26"""
27
28def open_header_file_for_write(filename):
29    generator_name = sys.argv[0]
30    f = open(UCD_config.UCD_output_dir + '/' + filename + '.h', 'w')
31    substitute_name_char_re = re.compile('[-\s]')
32    hname = substitute_name_char_re.sub('_', filename.upper()) + '_H'
33    f.write(header_template % (hname, hname, date.today().year, generator_name))
34    return f
35
36def open_cpp_file_for_write(filename):
37   generator_name = sys.argv[0]
38
39   f = open(UCD_config.UCD_output_dir + '/' + filename + '.cpp', 'w')
40   hname = filename.upper() + '_H'
41   f.write(cpp_template % (date.today().year, generator_name, filename))
42   return f
43
44
45
46
47def close_header_file(f):
48   f.write("\n#endif\n")
49   f.close()
50
51def close_cpp_file(f):
52   f.close()
53
54def write_imports(f, import_list):
55   for i in sorted(import_list): f.write("#include %s\n" % i)
56
57def multiline_fill(item_list, separator = ",", indent = 4, max_line_length = 75):
58  lines = ""
59  sep_with_space = separator + " "
60  while len(item_list) > 0:
61    items_this_line = item_list[:1]
62    length_this_line = len(item_list[0])
63    item_list = item_list[1:]
64    while (len(item_list) > 0) and (length_this_line + len(item_list[0]) + len(sep_with_space) <= max_line_length-indent):
65      items_this_line.append(item_list[0])
66      length_this_line += len(item_list[0]) + len(sep_with_space)
67      item_list = item_list[1:]
68    lines += sep_with_space.join(items_this_line)
69    if len(item_list) > 0: lines += separator + "\n" + (" " * indent)
70  return lines
71
72
Note: See TracBrowser for help on using the repository browser.