Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply .singleQuoted on representing Node.Scalar from String if Resolver.default resolves that to other than .str. #198

Merged
merged 5 commits into from
Jul 7, 2019

Conversation

norio-nomura
Copy link
Collaborator

Fixes #197

Apply `.singleQuoted` on representing `Node.Scalar` from `String` if `Resolver.default` resolves that to other than `.str`.
Fixes #197
@@ -230,7 +228,8 @@ extension URL: ScalarRepresentable {
extension String: ScalarRepresentable {
/// This value's `Node.scalar` representation.
public func represented() -> Node.Scalar {
return .init(self)
let scalar = Node.Scalar(self)
return scalar.resolvedTag.name == .str ? scalar : .init(self, Tag(.str), .singleQuoted)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The performance impact can be almost ignored since resolvedTag was previously called in serializeScalar(_:) on serializing.
https://github.com/jpsim/Yams/blob/41c33b6f96/Sources/Yams/Emitter.swift#L413

Copy link
Owner

@jpsim jpsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! Should we backport this to a 2.0.x release without the breaking changes?

@norio-nomura norio-nomura merged commit 0e210c0 into master Jul 7, 2019
@norio-nomura norio-nomura deleted the nn-smart-quoted-string branch July 7, 2019 06:54
@norio-nomura
Copy link
Collaborator Author

Should we backport this to a 2.0.x release without the breaking changes?

I'll branch yams-2.0-branch from 6694617 and open cherry-picking PR against that

norio-nomura added a commit that referenced this pull request Jul 7, 2019
Apply `.singleQuoted` on representing `Node.Scalar` from `String` if `Resolver.default` resolves that to other than `.str`.
norio-nomura added a commit that referenced this pull request Jul 7, 2019
…` from `String` if `Resolver.default` resolves that to other than `.str`.
ryohey added a commit to yonaskolb/XcodeGen that referenced this pull request Jul 15, 2021
Some values are now added quotes due to Yams 3.0.0 changes in jpsim/Yams#198
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yams.dump dumps numerical String values as Number
2 participants