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