| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'package:barback/barback.dart'; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 class CodedMessageConverter extends Transformer |
| 10 implements LazyTransformer { |
| 11 |
| 12 // A constructor named "asPlugin" is required. It can be empty, but |
| 13 // it must be present. |
| 14 CodedMessageConverter.asPlugin(); |
| 15 |
| 16 Future<bool> isPrimary(AssetId id) { |
| 17 return new Future.value(id.extension == '.txt'); |
| 18 } |
| 19 |
| 20 Future declareOutputs(DeclaringTransform transform) { |
| 21 return new Future.value(transform.primaryId.changeExtension('.shhhhh')); |
| 22 } |
| 23 |
| 24 Future apply(Transform transform) { |
| 25 return transform.primaryInput.readAsString().then((content) { |
| 26 |
| 27 // The output file is created with the '.shhhhh' extension. |
| 28 var id = transform.primaryInput.id.changeExtension('.shhhhh'); |
| 29 |
| 30 StringBuffer newContent = new StringBuffer(); |
| 31 for (int i = 0; i < content.length; i++ ) { |
| 32 newContent.write(rot13(content[i])); |
| 33 } |
| 34 transform.addOutput(new Asset.fromString(id, newContent.toString())); |
| 35 }); |
| 36 } |
| 37 |
| 38 rot13(var ch) { |
| 39 var c = ch.codeUnitAt(0); |
| 40 if (c >= 'a'.codeUnitAt(0) && c <= 'm'.codeUnitAt(0)) c += 13; |
| 41 else if (c >= 'A'.codeUnitAt(0) && c <= 'M'.codeUnitAt(0)) c += 13; |
| 42 else if (c >= 'n'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0)) c -= 13; |
| 43 else if (c >= 'N'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0)) c -= 13; |
| 44 return new String.fromCharCode(c); |
| 45 } |
| 46 } |
| OLD | NEW |