Skip to content

Commit

Permalink
Added ECI segment also for Latin-1 encoding since some strings are no…
Browse files Browse the repository at this point in the history
…t recognized by iOS's scanner otherwise
  • Loading branch information
YourMJK committed Aug 19, 2022
1 parent 886eb4e commit 651c6d1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Sources/QRCodeGenerator/Segment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,17 @@ public struct Segment {
/**
* Returns a list of zero, one or two segments to represent the given text string. With
* `strictEncoding` enabled, the result will contain a byte segment with the text encoded
* in either ISO-8859-1 (Latin-1) if possible or in UTF-8 with an ECI segment prepended
* indicating the deviation from the standard encoding. Without `strictEncoding`, the
* result will be a single byte segment with UTF-8 encoded data.
* in either ISO-8859-1 (Latin-1) if possible or in UTF-8 if otherwise. In both cases,
* an ECI segment will be prepended indicating the used encoding. Without `strictEncoding`,
* the result will be a single byte segment with UTF-8 encoded data.
*/
public static func makeSegments(byteEncodedText text: String, strictEncoding: Bool = false) throws -> [Segment] {
var result: [Segment] = []
if text.isEmpty {
// Leave result empty
} else if strictEncoding {
if let latin1Data = text.data(using: .isoLatin1) {
try result.append(makeECI(designator: 3))
try result.append(makeBytes(data: latin1Data))
} else {
try result.append(makeECI(designator: 26))
Expand Down

0 comments on commit 651c6d1

Please sign in to comment.