Add Latin1 to Unicode codecs

The Latin1 encoding seems to be missing from the list of text encodings in the standard library. i need this encoding to support PNG text chunks as defined in the format standard. i thought about extending Swift.Unicode to vend this codec so that text chunks could use an API spelled like

.parse(textChunk, as: Unicode.Latin1.self)

but this would mean that my extension would conflict with any other framework that also vends its own support for Latin1, which given how common a text encoding it is, seems like a real possibility. that tells me that this codec really belongs in the standard library, not in third-party extensions. i could namespace the text encoding to a framework-specific namespace like PNG.Latin1, but that just wouldn’t make any sense given that ASCII lives in Swift.Unicode.

as for the argument that goes “well if we support Latin1 then we have to support every text encoding that exists”, Swift already supports ASCII in the standard library, so there is precedent and justification for privileging the more common text encodings. And there is no reason why additional regional encodings can’t be added later.


This was accepted (but not implemented) as part of the SE-0163 proposed solution:

The standard library currently lacks a Latin1 codec, so a enum Latin1: Unicode.Encoding type will be added.

1 Like

that proposal is 3 years old, is there a reason why it hasn’t been implemented?

Terms of Service

Privacy Policy

Cookie Policy