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

Side by Side Diff: packages/barback/example/lazy_transformer/lib/transformer.dart

Issue 3014633002: Roll to pickup pool changes (Closed)
Patch Set: Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:barback/barback.dart'; 5 import 'package:barback/barback.dart';
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 class CodedMessageConverter extends Transformer implements LazyTransformer { 9 class CodedMessageConverter extends Transformer implements LazyTransformer {
10
11 // A constructor named "asPlugin" is required. It can be empty, but 10 // A constructor named "asPlugin" is required. It can be empty, but
12 // it must be present. 11 // it must be present.
13 CodedMessageConverter.asPlugin(); 12 CodedMessageConverter.asPlugin();
14 13
15 Future<bool> isPrimary(AssetId id) async => id.extension == '.txt'; 14 Future<bool> isPrimary(AssetId id) async => id.extension == '.txt';
16 15
17 Future declareOutputs(DeclaringTransform transform) { 16 void declareOutputs(DeclaringTransform transform) {
18 transform.declareOutput(transform.primaryId.changeExtension('.shhhhh')); 17 transform.declareOutput(transform.primaryId.changeExtension('.shhhhh'));
19 } 18 }
20 19
21 Future apply(Transform transform) async { 20 Future apply(Transform transform) async {
22 var content = await transform.primaryInput.readAsString(); 21 var content = await transform.primaryInput.readAsString();
23 22
24 // The output file is created with the '.shhhhh' extension. 23 // The output file is created with the '.shhhhh' extension.
25 var id = transform.primaryInput.id.changeExtension('.shhhhh'); 24 var id = transform.primaryInput.id.changeExtension('.shhhhh');
26 25
27 var newContent = new StringBuffer(); 26 var newContent = new StringBuffer();
28 for (var i = 0; i < content.length; i++) { 27 for (var i = 0; i < content.length; i++) {
29 newContent.write(rot13(content[i])); 28 newContent.write(rot13(content[i]));
30 } 29 }
31 transform.addOutput(new Asset.fromString(id, newContent.toString())); 30 transform.addOutput(new Asset.fromString(id, newContent.toString()));
32 } 31 }
33 32
34 rot13(var ch) { 33 rot13(var ch) {
35 var c = ch.codeUnitAt(0); 34 var c = ch.codeUnitAt(0);
36 if (c >= 'a'.codeUnitAt(0) && c <= 'm'.codeUnitAt(0)) c += 13; 35 if (c >= 'a'.codeUnitAt(0) && c <= 'm'.codeUnitAt(0)) {
37 else if (c >= 'A'.codeUnitAt(0) && c <= 'M'.codeUnitAt(0)) c += 13; 36 c += 13;
38 else if (c >= 'n'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0)) c -= 13; 37 } else if (c >= 'A'.codeUnitAt(0) && c <= 'M'.codeUnitAt(0)) {
39 else if (c >= 'N'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0)) c -= 13; 38 c += 13;
39 } else if (c >= 'n'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0)) {
40 c -= 13;
41 } else if (c >= 'N'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0)) {
42 c -= 13;
43 }
40 return new String.fromCharCode(c); 44 return new String.fromCharCode(c);
41 } 45 }
42 } 46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698