Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: packages/charted/tool/build_unicode_segmentation_data.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: packages/charted/tool/build_unicode_segmentation_data.dart
diff --git a/packages/charted/tool/build_unicode_segmentation_data.dart b/packages/charted/tool/build_unicode_segmentation_data.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4ec1d4736a4d3dca9fd9cd47c3e17b4ef1959873
--- /dev/null
+++ b/packages/charted/tool/build_unicode_segmentation_data.dart
@@ -0,0 +1,77 @@
+//
+// Copyright 2014 Google Inc. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file or at
+// https://developers.google.com/open-source/licenses/bsd
+//
+
+library charted.tool.build_unicode_segmentation_data;
+
+import 'dart:async';
+import 'package:http/http.dart' as http;
+import 'package:charted/core/text_metrics/segmentation_utils.dart';
+
+/// Unicode version
+/// A new version of unicode is available every June.
+const VERSION = '7.0.0';
+
+/// URI for downloading the grapheme properties file.
+const UCD_PROPERTIES_URL =
+ 'http://www.unicode.org/Public/${VERSION}/ucd/auxiliary/GraphemeBreakProperty.txt';
+
+const LIBRARY_NAME = 'charted.core.text_metrics.segmentation_data';
+
+/// License header for the generated file.
+const HEADER = """
+//
+// Copyright 2014 Google Inc. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file or at
+// https://developers.google.com/open-source/licenses/bsd
+//
+// This is a generated file.
+// Please use tool/build_unicode_segmentation-data.dart to update
+//
+
+/// Code ranges by their types for use with grapheme segmentation
+/// of text in charts.
+library $LIBRARY_NAME;
+
+import "package:charted/core/text_metrics/segmentation_utils.dart";
+
+""";
+
+Future<String> _getPropertiesFile() => http.read(UCD_PROPERTIES_URL);
+
+void _dumpPropertiesData(String data) {
+ StringBuffer buffer = new StringBuffer();
+ RegExp lineRegExp =
+ new RegExp(r'([0-9A-F]{4})..([0-9A-F]{4})?\s+;\s([a-zA-Z]+)\s');
+
+ buffer.write(HEADER);
+ buffer.writeln('const CODE_POINT_BLOCKS = const[');
+
+ List<Iterable> items = [];
+ data.split('\n').forEach((String line) {
+ Match match = lineRegExp.matchAsPrefix(line);
+ if (match == null) return;
+
+ int start = int.parse(match.group(1), radix:16);
+ int end =
+ match.group(2) == null ? start : int.parse(match.group(2), radix:16);
+
+ items.add([start, end, CodeUnitCategory[match.group(3)]]);
+ items.sort((a, b) => a.first.compareTo(b.first));
+ });
+
+ buffer.write(items.map((List range) => range.join(', ')).join(',\n '));
+ buffer.writeln();
+ buffer.writeln('];');
+ print(buffer.toString());
+}
+
+main() {
+ _getPropertiesFile().then((data) => _dumpPropertiesData(data));
+}
« no previous file with comments | « packages/charted/test.disabled/transition/transition_test.dart ('k') | packages/charted/tool/hop_runner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698