<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Henry,<div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On Aug 22, 2016, at 7:00 AM, Henry Betts via swift-corelibs-dev <<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I am new to the mailing list, and am interested in contributing to the swift project.</div></div></div></blockquote><div><br class=""></div>Welcome!</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""> </div><div class="">I’ve been having a play with the ICU library’s unit formatting functions, and have created a simple wrapper that could be used by the various measurement formatters as well as the date component formatter. At the moment, this wrapper is written in swift, but I’m thinking it might make more sense to implement it as a core foundation layer, so as not to expose ICU directly to swift.</div><div class=""><br class=""></div><div class="">The interface for this could look something like:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> CFUnitFormatterStyle{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> CFUnitFormatterStyleLong,</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> CFUnitFormatterStyleMedium,</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> ...</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">};</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> CFUnitFormatterUnit{</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> CFUnitFormatterUnit_Length_Meter,</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> ...</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> CFUnitFormatterUnit_Mass_Gram,</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> ...</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">};</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> CFUnitFormatterMeasure{</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">double</span><span style="font-variant-ligatures: no-common-ligatures" class=""> value;</span></div><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">CFUnitFormatterUnit</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> unit;</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">};</span></div></div></span></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">CFUnitFormatterRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> CFUnitFormatterCreate(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFAllocatorRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> allocator, </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFLocaleRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> locale, </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">CFUnitFormatterStyle</span><span style="font-variant-ligatures: no-common-ligatures" class=""> style, </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFNumberFormatterRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> numberFormatter);</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFStringRef</span> CFUnitFormatterCreateString(<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFAllocatorRef</span> allocator, <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">CFUnitFormatterRef</span> formatter, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">double</span> value, <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">CFUnitFormatterUnit</span> unit);</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFStringRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> CFUnitFormatterCreateStringWithMeasure(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFAllocatorRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> allocator, </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">CFUnitFormatterRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> formatter, </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">CFUnitFormatterMeasure</span><span style="font-variant-ligatures: no-common-ligatures" class=""> measure);</span></div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFStringRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> CFUnitFormatterCreateStringWithMeasures(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFAllocatorRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> allocator, </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">CFUnitFormatterRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> formatter, </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CFArrayRef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> measures);</span></div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class="">Looking for any thoughts and suggestions before I begin implementing this.</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Henry</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div></span></div></div></div></blockquote><div><br class=""></div><div>This approach makes sense - we have been putting stub functions into CF to use ICU, because ICU’s headers are not module-friendly (yet?). Our Darwin implementation also maps to the ICU constants for units (that I’m sure you found).</div><div><br class=""></div><div>I would love to be able to use ICU from Swift instead of implementing everything twice, but maybe that’s a tall order.</div><div><br class=""></div><div>- Tony</div><div><br class=""></div></div></div></body></html>