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

Unified Diff: lib/protobuf/plugin/DartHelpers.dart

Issue 10595002: Protocol Buffer runtime library and 'protoc' plugin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Work around http://code.google.com/p/dart/issues/detail?id=3806 Created 8 years, 6 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
« no previous file with comments | « lib/protobuf/plugin/DartFile.dart ('k') | lib/protobuf/plugin/EnumGenerator.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/protobuf/plugin/DartHelpers.dart
diff --git a/lib/protobuf/plugin/DartHelpers.dart b/lib/protobuf/plugin/DartHelpers.dart
new file mode 100644
index 0000000000000000000000000000000000000000..591e90e197843af9a9ea6ab7112b4ac783fa882b
--- /dev/null
+++ b/lib/protobuf/plugin/DartHelpers.dart
@@ -0,0 +1,93 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+String dotsToCamelCase(String input, [bool capitalize = false]) =>
+ _toCamelCase(input, ".", capitalize);
+String underscoresToCamelCase(String input, [bool capitalize = false]) =>
+ _toCamelCase(input, "_", capitalize);
+String _toCamelCase(String input, String separator, bool capitalize) {
+ bool capNextLetter = capitalize;
+ int separatorCode = separator.charCodes()[0];
+ List<int> sb = [];
+ for (int i = 0; i < input.length; i++) {
+ int char = input.charCodeAt(i);
+ if (_StringUtils.isUppercaseLetter(char)) {
+ if (capNextLetter) {
+ sb.add(char);
+ } else {
+ sb.add(_StringUtils.toLowercase(char));
+ }
+ capNextLetter = false;
+ } else if (_StringUtils.isLowercaseLetter(char)) {
+ if (capNextLetter) {
+ sb.add(_StringUtils.toUppercase(char));
+ } else {
+ sb.add(char);
+ }
+ capNextLetter = false;
+ } else {
+ if (char != separatorCode) {
+ sb.add(char);
+ }
+ capNextLetter = true;
+ }
+ }
+
+ return new String.fromCharCodes(sb);
+}
+
+String titlecase(String input) {
+ if (input.length > 0) {
+ int initial = input.charCodeAt(0);
+ if (_StringUtils.isLowercaseLetter(initial)) {
+ return "${new String.fromCharCodes([_StringUtils.toUppercase(initial)])}"
+ "${input.substring(1)}";
+ }
+ }
+ return input;
+}
+
+class FilenameUtils {
+ static String basename(String filename) {
+ int b = filename.lastIndexOf("/", filename.length - 1);
+ int e = filename.lastIndexOf(".", filename.length - 1);
+ if (e <= 0) e = filename.length - 1;
+ return filename.substring(b + 1, e);
+ }
+}
+
+class _StringUtils {
+ static final int char_A = 65; // "A".charCodeAt(0);
+ static final int char_Z = 90; // "Z".charCodeAt(0);
+
+ static final int char_a = 97; // "a".charCodeAt(0);
+ static final int char_z = 122; // "z".charCodeAt(0);
+
+ static final int char_0 = 48; // "0".charCodeAt(0);
+ static final int char_9 = 58; // "9".charCodeAt(0);
+
+ static bool isLowercaseLetter(int char) =>
+ (char_a <= char) && (char <= char_z);
+ static bool isNumeric(int char) => (char_0 <= char) && (char <= char_9);
+ static bool isUppercaseLetter(int char) =>
+ (char_A <= char) && (char <= char_Z);
+ static int toLowercase(int char) => char + (char_a - char_A);
+ static int toUppercase(int char) => char - (char_a - char_A);
+}
+
+class _Bitmask {
+ _Bitmask();
+ String operator[](int index) => "0x${(1 << (index - 1)).toRadixString(16)}";
+}
+
+class _BitmaskUtils {
+ static _Bitmask _bitmask;
+
+ static _Bitmask get bit_masks() {
+ if (_bitmask == null) {
+ _bitmask = new _Bitmask();
+ }
+ return _bitmask;
+ }
+}
« no previous file with comments | « lib/protobuf/plugin/DartFile.dart ('k') | lib/protobuf/plugin/EnumGenerator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698