[swift-corelibs-dev] Measurement Formatters & ICU

Tony Parker anthony.parker at apple.com
Mon Aug 22 12:10:48 CDT 2016


Hi Henry,

> On Aug 22, 2016, at 7:00 AM, Henry Betts via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
> 
> Hi,
> 
> I am new to the mailing list, and am interested in contributing to the swift project.

Welcome!

>  
> 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.
> 
> The interface for this could look something like:
> 
> enum CFUnitFormatterStyle{
>     
>     CFUnitFormatterStyleLong,
>     CFUnitFormatterStyleMedium,
>     ...
>     
> };
> 
> enum CFUnitFormatterUnit{
>     
>     CFUnitFormatterUnit_Length_Meter,
>     ...
>     CFUnitFormatterUnit_Mass_Gram,
>     ...
>     
> };
> 
> struct CFUnitFormatterMeasure{
>     
>     double value;
>     CFUnitFormatterUnit unit;
>     
> };
> 
> CFUnitFormatterRef CFUnitFormatterCreate(CFAllocatorRef allocator, CFLocaleRef locale, CFUnitFormatterStyle style, CFNumberFormatterRef numberFormatter);
> 
> CFStringRef CFUnitFormatterCreateString(CFAllocatorRef allocator, CFUnitFormatterRef formatter, double value, CFUnitFormatterUnit unit);
> 
> CFStringRef CFUnitFormatterCreateStringWithMeasure(CFAllocatorRef allocator, CFUnitFormatterRef formatter, CFUnitFormatterMeasure measure);
> 
> CFStringRef CFUnitFormatterCreateStringWithMeasures(CFAllocatorRef allocator, CFUnitFormatterRef formatter, CFArrayRef measures);
> 
> 
> Looking for any thoughts and suggestions before I begin implementing this.
> 
> Henry
> 

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).

I would love to be able to use ICU from Swift instead of implementing everything twice, but maybe that’s a tall order.

- Tony

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20160822/29550b26/attachment.html>


More information about the swift-corelibs-dev mailing list