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

Side by Side Diff: pkg/dart_messages/bin/message_id.dart

Issue 1514333002: Add dart_messages package. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add the converted shared_messages.json. Created 5 years 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 unified diff | Download patch
« no previous file with comments | « pkg/dart_messages/bin/json_converter.dart ('k') | pkg/dart_messages/lib/shared_messages.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:math' as math;
6
7 import '../lib/shared_messages.dart' as shared_messages;
8
9 math.Random random = new math.Random();
10
11 const idLength = 6;
12 final $A = "A".codeUnitAt(0);
13 final $Z = "Z".codeUnitAt(0);
14
15 String computeId() {
16 List charCodes = [];
17 for (int i = 0; i < idLength; i++) {
18 charCodes.add($A + random.nextInt($Z - $A));
19 }
20 return new String.fromCharCodes(charCodes);
21 }
22
23 /// Computes a random message ID that hasn't been used before.
24 void main() {
25 var usedIds =
26 shared_messages.MESSAGES.values.map((entry) => entry['id']).toSet();
27
28 print("${usedIds.length} existing ids");
29
30 var newId;
31 do {
32 newId = computeId();
33 } while (!usedIds.contains(newId));
34 print("Available id: $newId");
35 }
OLDNEW
« no previous file with comments | « pkg/dart_messages/bin/json_converter.dart ('k') | pkg/dart_messages/lib/shared_messages.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698