Skip to content

Commit 7a7512f

Browse files
authored
Merge pull request #421 from zapcannon87/master
fix: formatted JSON string of Object probably NOT right
2 parents e5101d2 + df6e686 commit 7a7512f

19 files changed

+30
-202
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
17.7.0
1+
17.7.1

LeanCloud.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'LeanCloud'
3-
s.version = '17.7.0'
3+
s.version = '17.7.1'
44
s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' }
55
s.summary = 'LeanCloud Swift SDK'
66
s.homepage = 'https://leancloud.cn/'

LeanCloudTests/LCObjectTestCase.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -345,38 +345,6 @@ class LCObjectTestCase: BaseTestCase {
345345
dictionary.foo = "bar"
346346
XCTAssertEqual(dictionary.foo?.stringValue, "bar")
347347
}
348-
349-
func testJSONString() {
350-
XCTAssertEqual(LCNull().jsonString, "null")
351-
XCTAssertEqual(LCNumber(1).jsonString, "1")
352-
XCTAssertEqual(LCNumber(3.14).jsonString, "3.14")
353-
XCTAssertEqual(LCBool(true).jsonString, "true")
354-
XCTAssertEqual(LCString("foo").jsonString, "\"foo\"")
355-
XCTAssertEqual(try LCArray(unsafeObject: [1, true, [0, false]]).jsonString, """
356-
[
357-
1,
358-
true,
359-
[
360-
0,
361-
false
362-
]
363-
]
364-
""")
365-
XCTAssertEqual(try LCDictionary(unsafeObject: ["foo": "bar", "bar": ["bar": "baz"]]).jsonString, """
366-
{
367-
"bar": {
368-
"bar": "baz"
369-
},
370-
"foo": "bar"
371-
}
372-
""")
373-
XCTAssertEqual(LCObject().jsonString, """
374-
{
375-
"__type": "Object",
376-
"className": "LCObject"
377-
}
378-
""")
379-
}
380348

381349
func testBatchChildren() {
382350
let object1 = LCObject(className: "BatchChildren")

Sources/Foundation/ACL.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ public final class LCACL: NSObject, LCValue, LCValueExtension {
6868
return value
6969
}
7070

71-
func formattedJSONString(indentLevel: Int, numberOfSpacesForOneIndentLevel: Int = 4) -> String {
72-
return LCDictionary(value).formattedJSONString(indentLevel: indentLevel, numberOfSpacesForOneIndentLevel: numberOfSpacesForOneIndentLevel)
73-
}
74-
75-
public var jsonString: String {
76-
return formattedJSONString(indentLevel: 0)
77-
}
78-
7971
public var rawValue: Any {
8072
return self
8173
}

Sources/Foundation/Array.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ public class LCArray: NSObject, LCValue, Collection, ExpressibleByArrayLiteral {
100100
return self.value.map { $0.jsonValue }
101101
}
102102

103-
public var jsonString: String {
104-
return self.formattedJSONString(indentLevel: 0)
105-
}
106-
107103
public var rawValue: Any {
108104
return self.value.map { $0.rawValue }
109105
}
@@ -160,19 +156,4 @@ extension LCArray: LCValueExtension {
160156
func differInPlace(_ elements: [Element]) {
161157
self.value = (self.value - elements)
162158
}
163-
164-
func formattedJSONString(indentLevel: Int, numberOfSpacesForOneIndentLevel: Int = 4) -> String {
165-
if self.value.isEmpty {
166-
return "[]"
167-
}
168-
let lastIndent = " " * (numberOfSpacesForOneIndentLevel * indentLevel)
169-
let bodyIndent = " " * (numberOfSpacesForOneIndentLevel * (indentLevel + 1))
170-
let body = self.value
171-
.compactMap {
172-
($0 as? LCValueExtension)?.formattedJSONString(
173-
indentLevel: indentLevel + 1,
174-
numberOfSpacesForOneIndentLevel: numberOfSpacesForOneIndentLevel) }
175-
.joined(separator: ",\n" + bodyIndent)
176-
return "[\n\(bodyIndent)\(body)\n\(lastIndent)]"
177-
}
178159
}

Sources/Foundation/Bool.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ public final class LCBool: NSObject, LCValue, LCValueExtension, ExpressibleByBoo
5858
return value
5959
}
6060

61-
func formattedJSONString(indentLevel: Int, numberOfSpacesForOneIndentLevel: Int = 4) -> String {
62-
return "\(value)"
63-
}
64-
65-
public var jsonString: String {
66-
return formattedJSONString(indentLevel: 0)
67-
}
68-
6961
public var rawValue: Any {
7062
return self.value
7163
}

Sources/Foundation/Data.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,6 @@ public final class LCData: NSObject, LCValue, LCValueExtension {
9797
]
9898
}
9999

100-
func formattedJSONString(indentLevel: Int, numberOfSpacesForOneIndentLevel: Int = 4) -> String {
101-
return LCDictionary(typedJSONValue).formattedJSONString(indentLevel: indentLevel, numberOfSpacesForOneIndentLevel: numberOfSpacesForOneIndentLevel)
102-
}
103-
104-
public var jsonString: String {
105-
return formattedJSONString(indentLevel: 0)
106-
}
107-
108100
public var rawValue: Any {
109101
return self.value
110102
}

Sources/Foundation/Date.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,6 @@ public final class LCDate: NSObject, LCValue, LCValueExtension {
132132
]
133133
}
134134

135-
func formattedJSONString(indentLevel: Int, numberOfSpacesForOneIndentLevel: Int = 4) -> String {
136-
return LCDictionary(typedJSONValue).formattedJSONString(indentLevel: indentLevel, numberOfSpacesForOneIndentLevel: numberOfSpacesForOneIndentLevel)
137-
}
138-
139-
public var jsonString: String {
140-
return formattedJSONString(indentLevel: 0)
141-
}
142-
143135
public var rawValue: Any {
144136
return self.value
145137
}

Sources/Foundation/Dictionary.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,6 @@ public final class LCDictionary: NSObject, LCValue, LCValueExtension, Collection
155155
return value.compactMapValue { value in value.jsonValue }
156156
}
157157

158-
func formattedJSONString(indentLevel: Int, numberOfSpacesForOneIndentLevel: Int = 4) -> String {
159-
if value.isEmpty {
160-
return "{}"
161-
}
162-
163-
let lastIndent = " " * (numberOfSpacesForOneIndentLevel * indentLevel)
164-
let bodyIndent = " " * (numberOfSpacesForOneIndentLevel * (indentLevel + 1))
165-
let body = value
166-
.map { (key, value) in (key, (value as! LCValueExtension).formattedJSONString(indentLevel: indentLevel + 1, numberOfSpacesForOneIndentLevel: numberOfSpacesForOneIndentLevel)) }
167-
.sorted { (left, right) in left.0 < right.0 }
168-
.map { (key, value) in "\"\(key.doubleQuoteEscapedString)\": \(value)" }
169-
.joined(separator: ",\n" + bodyIndent)
170-
171-
return "{\n\(bodyIndent)\(body)\n\(lastIndent)}"
172-
}
173-
174-
public var jsonString: String {
175-
return formattedJSONString(indentLevel: 0)
176-
}
177-
178158
public var rawValue: Any {
179159
let v: [String: Any] = self.value.mapValue { value in value.rawValue }
180160
return v

Sources/Foundation/GeoPoint.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ public final class LCGeoPoint: NSObject, LCValue, LCValueExtension {
104104
]
105105
}
106106

107-
func formattedJSONString(indentLevel: Int, numberOfSpacesForOneIndentLevel: Int = 4) -> String {
108-
return LCDictionary(typedJSONValue).formattedJSONString(indentLevel: indentLevel, numberOfSpacesForOneIndentLevel: numberOfSpacesForOneIndentLevel)
109-
}
110-
111-
public var jsonString: String {
112-
return formattedJSONString(indentLevel: 0)
113-
}
114-
115107
public var rawValue: Any {
116108
return self
117109
}

0 commit comments

Comments
 (0)