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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 return "\"${element.toString().replaceAll('\\', '\\\\') |
56 .replaceAll("\"", "\\\"")}\"\n"; | 56 .replaceAll("\"", "\\\"").replaceAll("\n", "\\n")}\"\n"; |
Bob Nystrom
2013/07/15 22:16:03
You can make this a little cleaner if you use raw
janicejl
2013/07/15 22:38:43
Done.
| |
57 } | 57 } |
58 | 58 |
59 /** | 59 /** |
60 * Based on the depth in the file, this function returns the correct spacing | 60 * Based on the depth in the file, this function returns the correct spacing |
61 * for an element in the YAML output. | 61 * for an element in the YAML output. |
62 */ | 62 */ |
63 void _calcSpaces(int spaceLevel, StringBuffer yaml) { | 63 void _calcSpaces(int spaceLevel, StringBuffer yaml) { |
64 for (int i = 0; i < spaceLevel; i++) { | 64 for (int i = 0; i < spaceLevel; i++) { |
65 yaml.write(" "); | 65 yaml.write(" "); |
66 } | 66 } |
67 } | 67 } |
OLD | NEW |