<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Andy,<div class=""><br class=""></div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jun 21, 2017, at 7:39 AM, Andy Best via swift-corelibs-dev &lt;<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hey,<div class=""><br class=""></div><div class="">I've been looking at the init(contentsOfFile, usedEncoding) initializer for NSString in corelibs-foundation.</div><div class=""><br class=""></div><div class="">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 class=""></div>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 class=""></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 class=""></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">+ (<span style="color: #4f8187" class="">NSStringEncoding</span>)stringEncodingForData:(<span style="color: #4f8187" class="">NSData</span> *)data</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; encodingOptions:(<span style="color: #ba2da2" class="">nullable</span> <span style="color: #4f8187" class="">NSDictionary</span>&lt;<span style="color: #4f8187" class="">NSStringEncodingDetectionOptionsKey</span>, <span style="color: #ba2da2" class="">id</span>&gt; *)opts</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; convertedString:(<span style="color: #4f8187" class="">NSString</span> * <span style="color: #ba2da2" class="">_Nullable</span> * <span style="color: #ba2da2" class="">_Nullable</span>)string</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; usedLossyConversion:(<span style="color: #ba2da2" class="">nullable</span> <span style="color: #ba2da2" class="">BOOL</span> *)usedLossyConversion <span style="color: #78492a" class="">API_AVAILABLE</span>(macos(<span style="color: #272ad8" class="">10.10</span>), ios(<span style="color: #272ad8" class="">8.0</span>), watchos(<span style="color: #272ad8" class="">2.0</span>), tvos(<span style="color: #272ad8" class="">9.0</span>));</div><div class=""><br class=""></div><div class="">- Tony</div></div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Andy</div></div>
_______________________________________________<br class="">swift-corelibs-dev mailing list<br class=""><a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev<br class=""></div></blockquote></div><br class=""></div></body></html>