OLD | NEW |
1 // | 1 // |
2 // Copyright 2014 Google Inc. All rights reserved. | 2 // Copyright 2014 Google Inc. All rights reserved. |
3 // | 3 // |
4 // Use of this source code is governed by a BSD-style | 4 // Use of this source code is governed by a BSD-style |
5 // license that can be found in the LICENSE file or at | 5 // license that can be found in the LICENSE file or at |
6 // https://developers.google.com/open-source/licenses/bsd | 6 // https://developers.google.com/open-source/licenses/bsd |
7 // | 7 // |
8 | 8 |
9 library charted.tool.build_unicode_segmentation_data; | 9 library charted.tool.build_unicode_segmentation_data; |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 Future<String> _getPropertiesFile() => http.read(UCD_PROPERTIES_URL); | 46 Future<String> _getPropertiesFile() => http.read(UCD_PROPERTIES_URL); |
47 | 47 |
48 void _dumpPropertiesData(String data) { | 48 void _dumpPropertiesData(String data) { |
49 StringBuffer buffer = new StringBuffer(); | 49 StringBuffer buffer = new StringBuffer(); |
50 RegExp lineRegExp = | 50 RegExp lineRegExp = |
51 new RegExp(r'([0-9A-F]{4})..([0-9A-F]{4})?\s+;\s([a-zA-Z]+)\s'); | 51 new RegExp(r'([0-9A-F]{4})..([0-9A-F]{4})?\s+;\s([a-zA-Z]+)\s'); |
52 | 52 |
53 buffer.write(HEADER); | 53 buffer.write(HEADER); |
54 buffer.writeln('const CODE_POINT_BLOCKS = const['); | 54 buffer.writeln('const CODE_POINT_BLOCKS = const['); |
55 | 55 |
56 List<Iterable> items = []; | 56 List<List> items = []; |
57 data.split('\n').forEach((String line) { | 57 data.split('\n').forEach((String line) { |
58 Match match = lineRegExp.matchAsPrefix(line); | 58 Match match = lineRegExp.matchAsPrefix(line); |
59 if (match == null) return; | 59 if (match == null) return; |
60 | 60 |
61 int start = int.parse(match.group(1), radix:16); | 61 int start = int.parse(match.group(1), radix:16); |
62 int end = | 62 int end = |
63 match.group(2) == null ? start : int.parse(match.group(2), radix:16); | 63 match.group(2) == null ? start : int.parse(match.group(2), radix:16); |
64 | 64 |
65 items.add([start, end, CodeUnitCategory[match.group(3)]]); | 65 items.add([start, end, CodeUnitCategory[match.group(3)]]); |
66 items.sort((a, b) => a.first.compareTo(b.first)); | 66 items.sort((a, b) => a.first.compareTo(b.first)); |
67 }); | 67 }); |
68 | 68 |
69 buffer.write(items.map((List range) => range.join(', ')).join(',\n ')); | 69 buffer.write(items.map((List range) => range.join(', ')).join(',\n ')); |
70 buffer.writeln(); | 70 buffer.writeln(); |
71 buffer.writeln('];'); | 71 buffer.writeln('];'); |
72 print(buffer.toString()); | 72 print(buffer.toString()); |
73 } | 73 } |
74 | 74 |
75 main() { | 75 main() { |
76 _getPropertiesFile().then((data) => _dumpPropertiesData(data)); | 76 _getPropertiesFile().then((data) => _dumpPropertiesData(data)); |
77 } | 77 } |
OLD | NEW |