private void processScalar() { ScalarEvent ev = (ScalarEvent)_event; if (null == _analysis) { _analysis = analyzeScalar(ev.Value); } if (0 == _style) { _style = chooseScalarStyle(); } bool split = !_simpleKeyContext; if (_style == '"') { writeDoubleQuoted(_analysis.Scalar, split); } else if (_style == '\'') { writeSingleQuoted(_analysis.Scalar, split); } else if (_style == '>') { writeFolded(_analysis.Scalar); } else if (_style == '|') { writeLiteral(_analysis.Scalar); } else { writePlain(_analysis.Scalar, split); } _analysis = null; _style = '\0'; }
private char chooseScalarStyle() { ScalarEvent ev = (ScalarEvent)_event; if (null == _analysis) { _analysis = analyzeScalar(ev.Value); } if (ev.Style == '"' || canonical || (_analysis.Empty && ev.Tag == "tag:yaml.org,2002:str")) { return '"'; } // if (ev.Style == 0 && ev.Implicit[0]) { if (ev.Style == 0) { if (!(_simpleKeyContext && (_analysis.Empty || _analysis.Multiline)) && ((_flowLevel != 0 && _analysis.AllowFlowPlain) || (_flowLevel == 0 && _analysis.AllowBlockPlain))) { return '\0'; } } if (ev.Style == 0 && ev.Implicit[0] && (!(_simpleKeyContext && (_analysis.Empty || _analysis.Multiline)) && (_flowLevel != 0 && _analysis.AllowFlowPlain || (_flowLevel == 0 && _analysis.AllowBlockPlain)))) { return '\0'; } if ((ev.Style == '|' || ev.Style == '>') && _flowLevel == 0 && _analysis.AllowBlock) { return '\''; } if ((ev.Style == 0 || ev.Style == '\'') && (_analysis.AllowSingleQuoted && !(_simpleKeyContext && _analysis.Multiline))) { return '\''; } if (_analysis.Multiline && (FIRST_SPACE.Matches(ev.Value).Count == 0) && !_analysis.SpecialCharacters) { return '|'; } return '"'; }
private bool checkSimpleKey() { int length = 0; if (_event is NodeEvent && null != ((NodeEvent)_event).Anchor) { if (null == _preparedAnchor) { _preparedAnchor = prepareAnchor(((NodeEvent)_event).Anchor); } length += _preparedAnchor.Length; } string tag = null; if (_event is ScalarEvent) { tag = ((ScalarEvent)_event).Tag; } else if (_event is CollectionStartEvent) { tag = ((CollectionStartEvent)_event).Tag; } if (tag != null) { if (null == _preparedTag) { _preparedTag = prepareTag(tag); } length += _preparedTag.Length; } if (_event is ScalarEvent) { if (null == _analysis) { _analysis = analyzeScalar(((ScalarEvent)_event).Value); length += _analysis.Scalar.Length; } } return (length < 128 && (_event is AliasEvent || (_event is ScalarEvent && !_analysis.Multiline) || checkEmptySequence() || checkEmptyMapping())); }
private void ProcessScalar() { if (this.analysis == null) this.analysis = this.AnalyzeScalar(((Events.Scalar) this.currentEvent).Value); if (this.style == Style.Plain) this.style = this.ChooseScalarStyle(); var split = !this.isSimpleKeyContext; switch (this.style) { case Style.Double: this.WriteDoubleQuoted(this.analysis.Scalar, split); break; case Style.Single: this.WriteSingleQuoted(this.analysis.Scalar, split); break; case Style.Folded: this.WriteFolded(this.analysis.Scalar); break; case Style.Literal: this.WriteLiteral(this.analysis.Scalar); break; default: this.WritePlain(this.analysis.Scalar, split); break; } this.analysis = null; this.style = Style.Plain; }
private Style ChooseScalarStyle() { var eventNode = (Events.Scalar)this.currentEvent; if (this.analysis == null) this.analysis = this.AnalyzeScalar(eventNode.Value); if (eventNode.Style == Style.Double || this.isCanonical) return Style.Double; if (eventNode.Style == Style.Plain && eventNode.ImplicitLevel == ScalarImplicitLevel.Plain) { if (!(this.isSimpleKeyContext && (this.analysis.IsEmpty || this.analysis.IsMultiline)) && (this.flowLevel != 0 && this.analysis.AllowFlowPlain || (this.flowLevel == 0 && this.analysis.AllowBlockPlain))) return Style.Plain; } if (eventNode.Style == Style.Folded || eventNode.Style == Style.Literal) if (this.flowLevel == 0 && !this.isSimpleKeyContext && this.analysis.AllowBlock) return eventNode.Style; if (eventNode.Style == Style.Plain || eventNode.Style == Style.Single) if (this.analysis.AllowSingleQuoted && ! (this.isSimpleKeyContext && this.analysis.IsMultiline)) return Style.Single; return Style.Double; }
private bool CheckSimpleKey() { var length = 0; var nodeEvent = this.currentEvent as Events.Node; if (nodeEvent != null) { if (nodeEvent.Anchor != null) { if (this.preparedAnchor == null) this.preparedAnchor = PrepareAnchor(nodeEvent.Anchor); length += this.preparedAnchor.Length; } var scalarEvent = nodeEvent as Events.Scalar; var collectionEvent = nodeEvent as Events.CollectionStart; if (scalarEvent != null || collectionEvent != null) { var tag = scalarEvent != null ? scalarEvent.Tag : collectionEvent.Tag; if (tag != null) { if (this.preparedTag == null) this.preparedTag = this.PrepareTag(tag); length += this.preparedTag.Length; } } if (scalarEvent != null) { if (this.analysis == null) this.analysis = this.AnalyzeScalar(scalarEvent.Value); length += this.analysis.Scalar.Length; } } return length < 128 && (this.currentEvent is Events.Alias || (this.currentEvent is Events.Scalar && !this.analysis.IsEmpty && !this.analysis.IsMultiline) || this.CheckEmptySequence() || this.CheckEmptyMapping()); }