Comments (2)
Doesn't look like this is specific to Yams
but rather CYaml
Emitter.swift
private func serializeScalar(_ scalar: Node.Scalar) throws {
...
let scalar_style = yaml_scalar_style_t(rawValue: scalar.style.rawValue) // Returns `any` as that's what's passed in.
...
}
Looking at this, a possible solution could be in Representer.swift
with something like this:
private func canBecomeNumber(_ value: String) -> Bool {
return Double(value) != nil
}
private func represent(_ value: Any) throws -> Node {
if let string = value as? String {
if value is String && canBecomeNumber(string) {
return Node(string, .implicit, .singleQuoted)
}
return Node(string)
} else if let representable = value as? NodeRepresentable {
return try representable.represented()
}
throw YamlError.representer(problem: "Failed to represent \(value)")
}
If you're okay with this I can put up a PR.
from yams.
Thank you for filing an issue!
Could you provide test code to reproduce the issue?
The code I tried is as follows:
func testSrializeNumberInSingleQuote() throws {
let yaml = """
value1: '10.0'
value2: !!str '10.0'
"""
let node = try Yams.compose(yaml: yaml)
let updatedNode = try node.represented()
let serialized = try Yams.serialize(node: updatedNode)
print(serialized)
}
result:
Test Suite 'Selected tests' started at 2019-02-16 09:23:46.575
Test Suite 'YamsTests.xctest' started at 2019-02-16 09:23:46.576
Test Suite 'EmitterTests' started at 2019-02-16 09:23:46.578
Test Case '-[YamsTests.EmitterTests testSrializeNumberInSingleQuote]' started.
value1: '10.0'
value2: '10.0'
Test Case '-[YamsTests.EmitterTests testSrializeNumberInSingleQuote]' passed (0.135 seconds).
Test Suite 'EmitterTests' passed at 2019-02-16 09:23:46.714.
Executed 1 test, with 0 failures (0 unexpected) in 0.135 (0.136) seconds
Test Suite 'YamsTests.xctest' passed at 2019-02-16 09:23:46.715.
Executed 1 test, with 0 failures (0 unexpected) in 0.135 (0.139) seconds
Test Suite 'Selected tests' passed at 2019-02-16 09:23:46.716.
Executed 1 test, with 0 failures (0 unexpected) in 0.135 (0.140) seconds
Program ended with exit code: 0```
from yams.
Related Issues (20)
- Array / Sequence single-line flow style format encoding option? HOT 2
- Can't seem to build or import Yams (Xcode 13.2.1) HOT 2
- Add options to force using quotes for strings encoding HOT 2
- Ordered Map support HOT 1
- Error parsing markdown "code" backticks at end of line
- Compatible with SwiftyJSON
- Decode class with inheritance
- Yams without Foundation? HOT 9
- Re-enable Jazzy CI job
- Re-enable Windows SwiftPM CI jobs
- The problem with encoding floating points HOT 1
- Documentation generation fails in Swift Package Index HOT 2
- Failure to represent empty dictionary
- How does Yams serialize enum cases?
- Emojis get escaped when serializing HOT 1
- Empty keys cannot be decoded
- Strings with newlines should be encoded as multiline literals HOT 1
- Serialize loss tag HOT 1
- Yams should fail if there are duplicate keys in a mapping
- Failed to debug project with LLDB in SPM
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yams.