source: proto/charsetcompiler/UCD/cformat.py @ 4367

Last change on this file since 4367 was 4317, checked in by cameron, 5 years ago

Case-insensitive matching: generator program

File size: 1.3 KB
Line 
1
2header_template = r"""#ifndef %s
3#define %s
4/*
5 *  Copyright (c) 2014 International Characters, Inc.
6 *  This software is licensed to the public under the Open Software License 3.0.
7 *  icgrep is a trademark of International Characters, Inc.
8 *
9 *  This file is generated by %s - manual edits may be lost.
10 */
11
12"""
13
14def open_header_file_for_write(filename, generator_name='UCD_properties.py'):
15   f = open(filename + '.h', 'w')
16   hname = filename.upper() + '_H'
17   f.write(header_template % (hname, hname, generator_name))
18   return f
19
20def close_header_file(f):
21   f.write("\n#endif\n")
22   f.close()
23
24def write_imports(f, import_list):
25   for i in import_list: f.write("#include %s\n" % i)
26
27
28def multiline_fill(item_list, separator = ",", indent = 4, max_line_length = 75):
29  lines = ""
30  sep_with_space = separator + " "
31  while len(item_list) > 0:
32    items_this_line = item_list[:1]
33    length_this_line = len(item_list[0])
34    item_list = item_list[1:]
35    while (len(item_list) > 0) and (length_this_line + len(item_list[0]) + len(sep_with_space) <= max_line_length-indent):
36      items_this_line.append(item_list[0])
37      length_this_line += len(item_list[0]) + len(sep_with_space)
38      item_list = item_list[1:]
39    lines += sep_with_space.join(items_this_line)
40    if len(item_list) > 0: lines += separator + "\n" + (" " * indent)
41  return lines
42
43
Note: See TracBrowser for help on using the repository browser.