(state, string, level, iskey)
| 10535 | // • Ending newline => removed then restored. |
| 10536 | // Importantly, this keeps the "+" chomp indicator from gaining an extra line. |
| 10537 | function writeScalar(state, string, level, iskey) { |
| 10538 | state.dump = (function () { |
| 10539 | if (string.length === 0) { |
| 10540 | return "''"; |
| 10541 | } |
| 10542 | if (!state.noCompatMode && |
| 10543 | DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) { |
| 10544 | return "'" + string + "'"; |
| 10545 | } |
| 10546 | |
| 10547 | var indent = state.indent * Math.max(1, level); // no 0-indent scalars |
| 10548 | // As indentation gets deeper, let the width decrease monotonically |
| 10549 | // to the lower bound min(state.lineWidth, 40). |
| 10550 | // Note that this implies |
| 10551 | // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound. |
| 10552 | // state.lineWidth > 40 + state.indent: width decreases until the lower bound. |
| 10553 | // This behaves better than a constant minimum width which disallows narrower options, |
| 10554 | // or an indent threshold which causes the width to suddenly increase. |
| 10555 | var lineWidth = state.lineWidth === -1 |
| 10556 | ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent); |
| 10557 | |
| 10558 | // Without knowing if keys are implicit/explicit, assume implicit for safety. |
| 10559 | var singleLineOnly = iskey |
| 10560 | // No block styles in flow mode. |
| 10561 | || (state.flowLevel > -1 && level >= state.flowLevel); |
| 10562 | function testAmbiguity(string) { |
| 10563 | return testImplicitResolving(state, string); |
| 10564 | } |
| 10565 | |
| 10566 | switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) { |
| 10567 | case STYLE_PLAIN: |
| 10568 | return string; |
| 10569 | case STYLE_SINGLE: |
| 10570 | return "'" + string.replace(/'/g, "''") + "'"; |
| 10571 | case STYLE_LITERAL: |
| 10572 | return '|' + blockHeader(string, state.indent) |
| 10573 | + dropEndingNewline(indentString(string, indent)); |
| 10574 | case STYLE_FOLDED: |
| 10575 | return '>' + blockHeader(string, state.indent) |
| 10576 | + dropEndingNewline(indentString(foldString(string, lineWidth), indent)); |
| 10577 | case STYLE_DOUBLE: |
| 10578 | return '"' + escapeString(string, lineWidth) + '"'; |
| 10579 | default: |
| 10580 | throw new YAMLException('impossible error: invalid scalar style'); |
| 10581 | } |
| 10582 | }()); |
| 10583 | } |
| 10584 | |
| 10585 | // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9. |
| 10586 | function blockHeader(string, indentPerLevel) { |
no test coverage detected