<div dir="ltr">Is the preferred approach to mirror Foundation as closely as possible (e.g. under Linux basically do nothing), or is implementing something like stringEncodingForData under the hood preferable in this case?</div><div class="gmail_extra"><br><div class="gmail_quote">On 21 June 2017 at 17:43, Tony Parker <span dir="ltr"><<a href="mailto:anthony.parker@apple.com" target="_blank">anthony.parker@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Hi Andy,<div><br></div><div><div><span class=""><br><blockquote type="cite"><div>On Jun 21, 2017, at 7:39 AM, Andy Best via swift-corelibs-dev <<a href="mailto:swift-corelibs-dev@swift.org" target="_blank">swift-corelibs-dev@swift.org</a>> wrote:</div><br class="m_8981510993544425545Apple-interchange-newline"><div><div dir="ltr">Hey,<div><br></div><div>I've been looking at the init(contentsOfFile, usedEncoding) initializer for NSString in corelibs-foundation.</div><div><br></div><div>Am I right in thinking that this method should use some method to attempt to detect the character encoding of the file before returning a decoded String?</div></div></div></blockquote><div><br></div></span>In this case, the Foundation implementation just looks at an extended attribute of the file to see if it contains the encoding. If it doesn’t have the xattr then we don’t attempt to guess (name of xattr is “com.apple.TextEncoding”).</div><div><br></div><div>Foundation has another API which attempts to guess the encoding of a data blob, but I think we left it out of the swift-corelibs stubs:</div><div><br></div><div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">+ (<span style="color:#4f8187">NSStringEncoding</span>)<wbr>stringEncodingForData:(<span style="color:#4f8187">NSData</span> *)data</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> encodingOptions:(<span style="color:#ba2da2">nullable</span> <span style="color:#4f8187">NSDictionary</span><<span style="color:#4f8187">NSStringEncodingD<wbr>etectionOptionsKey</span>, <span style="color:#ba2da2">id</span>> *)opts</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> convertedString:(<span style="color:#4f8187">NSString</span> * <span style="color:#ba2da2">_Nullable</span> * <span style="color:#ba2da2">_Nullable</span>)string</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"> usedLossyConversion:(<span style="color:#ba2da2">nullable</span> <span style="color:#ba2da2">BOOL</span> *)usedLossyConversion <span style="color:#78492a">API_AVAILABLE</span>(macos(<span style="color:#272ad8">10.10</span>), ios(<span style="color:#272ad8">8.0</span>), watchos(<span style="color:#272ad8">2.0</span>), tvos(<span style="color:#272ad8">9.0</span>));</div><div><br></div><div>- Tony</div></div><div><br><blockquote type="cite"><div><span class=""><div dir="ltr"><div><br></div><div>If so, I've been working on a pure Swift library to detect string encodings, and wondered if continued work on it might be useful for implementing this missing method?</div><div><br></div><div>Andy</div></div></span>
______________________________<wbr>_________________<br>swift-corelibs-dev mailing list<br><a href="mailto:swift-corelibs-dev@swift.org" target="_blank">swift-corelibs-dev@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>corelibs-dev</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>