Fixing hardcoded utf8 Encoding on QRCodeType.typeNumber
Showing 3 of 4 files from the diff.
Sources/QRCode.swift
changed.
Sources/QRCodeType.swift
changed.
Sources/QRCodeModel.swift
changed.
Other files ignored by Codecov
.gitignore
has changed.
@@ -29,7 +29,6 @@
Loading
29 | 29 | public let correctLevel: QRErrorCorrectLevel |
|
30 | 30 | /// If the image codes has a border around its content. |
|
31 | 31 | public let hasBorder: Bool |
|
32 | - | private let typeNumber: Int |
|
33 | 32 | private let model: QRCodeModel |
|
34 | 33 | ||
35 | 34 | /// Construct a QRCode instance. |
@@ -45,10 +44,10 @@
Loading
45 | 44 | encoding: String.Encoding = .utf8, |
|
46 | 45 | errorCorrectLevel: QRErrorCorrectLevel = .H, |
|
47 | 46 | withBorder hasBorder: Bool = true) { |
|
48 | - | guard let typeNumber = try? QRCodeType.typeNumber(of: text, errorCorrectLevel: errorCorrectLevel) |
|
49 | - | , let model = QRCodeModel(text: text, encoding: encoding, typeNumber: typeNumber, errorCorrectLevel: errorCorrectLevel) |
|
47 | + | ||
48 | + | guard let model = QRCodeModel(text: text, encoding: encoding, errorCorrectLevel: errorCorrectLevel) |
|
50 | 49 | else { return nil } |
|
51 | - | self.typeNumber = typeNumber |
|
50 | + | ||
52 | 51 | self.model = model |
|
53 | 52 | self.text = text |
|
54 | 53 | self.correctLevel = errorCorrectLevel |
@@ -68,8 +68,10 @@
Loading
68 | 68 | ||
69 | 69 | extension QRCodeType { |
|
70 | 70 | /// Get the type by string length |
|
71 | - | static func typeNumber(of text: String, errorCorrectLevel: QRErrorCorrectLevel) throws -> Int { |
|
72 | - | let textLength = text.utf8.count |
|
71 | + | static func typeNumber(of text: String, encoding: String.Encoding = .utf8, errorCorrectLevel: QRErrorCorrectLevel) throws -> Int { |
|
72 | + | ||
73 | + | let textLength = text.lengthOfBytes(using: encoding) |
|
74 | + | ||
73 | 75 | let maxTypeNumber = QRCodeLimitLength.count |
|
74 | 76 | ||
75 | 77 | var type = 1 |
@@ -30,14 +30,17 @@
Loading
30 | 30 | private let encodedText: QR8bitByte |
|
31 | 31 | private var dataCache: [Int] |
|
32 | 32 | ||
33 | - | init?(text: String, encoding: String.Encoding = .utf8, typeNumber: Int, errorCorrectLevel: QRErrorCorrectLevel) { |
|
33 | + | init?(text: String, encoding: String.Encoding = .utf8, errorCorrectLevel: QRErrorCorrectLevel) { |
|
34 | 34 | ||
35 | 35 | guard let encoded = QR8bitByte(text, encoding: encoding) else { |
|
36 | 36 | return nil |
|
37 | 37 | } |
|
38 | 38 | ||
39 | 39 | self.encodedText = encoded |
|
40 | - | self.typeNumber = typeNumber |
|
40 | + | ||
41 | + | guard let newTypeNumber = try? QRCodeType.typeNumber(of: text, encoding: encoding, errorCorrectLevel: errorCorrectLevel) else { return nil } |
|
42 | + | ||
43 | + | self.typeNumber = newTypeNumber |
|
41 | 44 | self.errorCorrectLevel = errorCorrectLevel |
|
42 | 45 | guard let dataCache = try? QRCodeModel.createData( |
|
43 | 46 | typeNumber: typeNumber, |
Files | Coverage |
---|---|
Sources | 93.71% |
Project Totals (14 files) | 93.71% |
52.3
TRAVIS_OS_NAME=osx
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.