[haiku-development] Re: ICU, Locale Kit, and separators

  • From: pulkomandy <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 16 Nov 2012 18:38:36 +0100

On Fri, Nov 16, 2012 at 12:19:21PM -0500, John Scipione wrote:
> Maybe ICU keeps these separator symbols secret because they aren't
> universal across locales?

Yes. There is no reason the separator would have to exist at all, be
constant accross the time of day, etc. This makes it difficult to
handle.

The trick is you can get that information for a given date or time. In
the Locale kit this is done using :
Locale::FormatDate (or FormatTime) with fieldPosition/fieldCount
parameters (this will format the date and tell you where are the
boundaries between fields)
Locale::GetDateFields (or GetTimeFields) which will tell you what each
field actually is (hour, minute, separator, ...). you can then substring
the date string to get the separator if that's what you really, really
want. But most of the time you shouldn't need that as ICU (and Locale
Kit) should be the only one handling formatting.

Need a custom format ? Then you can use the BFormattingConventions
class, as pointed by Oliver. Start with a Locale object, get its
formatting convention, tweak it as needed, and then use it to format
your stuff.

Parsing should work the same, but it wasn't wrapped yet in a Locale Kit
API. It should be easy enough to do and maybe a good time to actually
move the formatting stuff out of the Locale class inside the various
*Format classes that are meant for it (possibly leaving the current
methods in Locale working as shortcuts to the actual ones).

-- 
Adrien.

Other related posts: