diff --git a/Sources/XMLCoder/Decoder/XMLDecoder.swift b/Sources/XMLCoder/Decoder/XMLDecoder.swift
index 641f3f69..69d8b4db 100644
--- a/Sources/XMLCoder/Decoder/XMLDecoder.swift
+++ b/Sources/XMLCoder/Decoder/XMLDecoder.swift
@@ -166,9 +166,8 @@ open class XMLDecoder {
guard !stringKey.isEmpty else {
return stringKey
}
- var result = stringKey
- let range = result.startIndex...result.index(after: result.startIndex)
- result.replaceSubrange(range, with: result[range].lowercased())
+ let firstLetter = stringKey.prefix(1).lowercased()
+ let result = firstLetter + stringKey.dropFirst()
return result
}
diff --git a/Tests/XMLCoderTests/KeyDecodingStrategyTest.swift b/Tests/XMLCoderTests/KeyDecodingStrategyTest.swift
new file mode 100644
index 00000000..a376310e
--- /dev/null
+++ b/Tests/XMLCoderTests/KeyDecodingStrategyTest.swift
@@ -0,0 +1,30 @@
+//
+// KeyDecodingStrategyTest.swift
+// XMLCoder
+//
+// Created by Max Desiatov on 02/05/2019.
+//
+
+import XCTest
+@testable import XMLCoder
+
+private let capitalized = """
+blah
+""".data(using: .utf8)!
+
+private struct Item: Codable, Equatable {
+ public let text: String
+
+ enum CodingKeys: String, CodingKey {
+ case text = "t"
+ }
+}
+
+final class KeyDecodingStrategyTest: XCTestCase {
+ func testCapitalized() throws {
+ let decoder = XMLDecoder()
+ decoder.keyDecodingStrategy = .convertFromCapitalized
+ let result = try decoder.decode(Item.self, from: capitalized)
+ XCTAssertEqual(result.text, "blah")
+ }
+}
diff --git a/XMLCoder.xcodeproj/project.pbxproj b/XMLCoder.xcodeproj/project.pbxproj
index edada86b..176edb7f 100644
--- a/XMLCoder.xcodeproj/project.pbxproj
+++ b/XMLCoder.xcodeproj/project.pbxproj
@@ -89,6 +89,7 @@
D158F12F2229892C0032B449 /* DynamicNodeDecoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D158F12E2229892C0032B449 /* DynamicNodeDecoding.swift */; };
D162674321F9B2AF0056D1D8 /* OptionalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D162674121F9B2850056D1D8 /* OptionalTests.swift */; };
D1761D1F2247F04500F53CEF /* DynamicNodeDecodingTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1761D1E2247F04500F53CEF /* DynamicNodeDecodingTest.swift */; };
+ D1A3D4AD227AD9BF00F28969 /* KeyDecodingStrategyTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1A3D4AB227AD9BC00F28969 /* KeyDecodingStrategyTest.swift */; };
D1AC9466224E3E63004AB49B /* AttributedEnumIntrinsicTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1AC9464224E3E1F004AB49B /* AttributedEnumIntrinsicTest.swift */; };
D1CB1EF521EA9599009CAF02 /* RJITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_37 /* RJITest.swift */; };
D1CFC8242226B13F00B03222 /* NamespaceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1CFC8222226AFB400B03222 /* NamespaceTest.swift */; };
@@ -210,6 +211,7 @@
D158F12E2229892C0032B449 /* DynamicNodeDecoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicNodeDecoding.swift; sourceTree = ""; };
D162674121F9B2850056D1D8 /* OptionalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalTests.swift; sourceTree = ""; };
D1761D1E2247F04500F53CEF /* DynamicNodeDecodingTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicNodeDecodingTest.swift; sourceTree = ""; };
+ D1A3D4AB227AD9BC00F28969 /* KeyDecodingStrategyTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyDecodingStrategyTest.swift; sourceTree = ""; };
D1AC9464224E3E1F004AB49B /* AttributedEnumIntrinsicTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributedEnumIntrinsicTest.swift; sourceTree = ""; };
D1CFC8222226AFB400B03222 /* NamespaceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NamespaceTest.swift; sourceTree = ""; };
D1E0C85121D8E6540042A261 /* ErrorContextTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorContextTest.swift; sourceTree = ""; };
@@ -408,6 +410,7 @@
OBJ_37 /* RJITest.swift */,
D14D8A8521F1D6B300B0D31A /* SingleChildTests.swift */,
D11815BF227788BA008836E4 /* SpacePreserveTest.swift */,
+ D1A3D4AB227AD9BC00F28969 /* KeyDecodingStrategyTest.swift */,
);
name = XMLCoderTests;
path = Tests/XMLCoderTests;
@@ -668,6 +671,7 @@
BF9457CF21CBB516005ACFDE /* IntBoxTests.swift in Sources */,
BF9457E021CBB68A005ACFDE /* DataBoxTests.swift in Sources */,
D162674321F9B2AF0056D1D8 /* OptionalTests.swift in Sources */,
+ D1A3D4AD227AD9BF00F28969 /* KeyDecodingStrategyTest.swift in Sources */,
BF9457F521CBB6BC005ACFDE /* DecimalTests.swift in Sources */,
OBJ_83 /* CDTest.swift in Sources */,
BF63EF6721D0F874001D38C5 /* XMLKeyTests.swift in Sources */,