| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
| 6 * This library is used to convert data from a map to a YAML string. | 6 * This library is used to convert data from a map to a YAML string. |
| 7 */ | 7 */ |
| 8 library dart2yaml; | 8 library dart2yaml; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } else { | 45 } else { |
| 46 yaml.write(_processElement(documentData[key])); | 46 yaml.write(_processElement(documentData[key])); |
| 47 } | 47 } |
| 48 }); | 48 }); |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * Returns an escaped String form of the inputted element. | 52 * Returns an escaped String form of the inputted element. |
| 53 */ | 53 */ |
| 54 String _processElement(var element) { | 54 String _processElement(var element) { |
| 55 return "\"${element.toString().replaceAll('\\', '\\\\') | 55 var contents = element.toString() |
| 56 .replaceAll("\"", "\\\"")}\"\n"; | 56 .replaceAll('\\', r'\\') |
| 57 .replaceAll('"', r'\"') |
| 58 .replaceAll('\n', r'\n'); |
| 59 return '"$contents"\n'; |
| 57 } | 60 } |
| 58 | 61 |
| 59 /** | 62 /** |
| 60 * Based on the depth in the file, this function returns the correct spacing | 63 * Based on the depth in the file, this function returns the correct spacing |
| 61 * for an element in the YAML output. | 64 * for an element in the YAML output. |
| 62 */ | 65 */ |
| 63 void _calcSpaces(int spaceLevel, StringBuffer yaml) { | 66 void _calcSpaces(int spaceLevel, StringBuffer yaml) { |
| 64 for (int i = 0; i < spaceLevel; i++) { | 67 for (int i = 0; i < spaceLevel; i++) { |
| 65 yaml.write(" "); | 68 yaml.write(" "); |
| 66 } | 69 } |
| 67 } | 70 } |
| OLD | NEW |