Commit Graph

150 Commits

Author SHA1 Message Date
KJ Tsanaktsidis da26ebcfbc Add formatting for durations e.g. "2h 4min. 2sec."
Uses unumf_* to format the individual components of the duration, and
ulistfmt_* to join them. That's roughly analogous with what the C++
MeasureFormatter class does internally.

I asked about some feedback for this approach on the ICU mailing list
too: https://sourceforge.net/p/icu/mailman/message/37645785/
2022-12-20 11:13:42 +01:00
KJ Tsanaktsidis 44b11a658f Add a helper for attaching functions if present 2022-12-20 11:13:42 +01:00
Craig Alan Pettersen 57a5b61d05 Merge commit 'refs/pull/32/head' of https://github.com/erickguan/ffi-icu into collator_improvements 2022-05-31 15:05:09 -05:00
Damian Nelson b57e49bad5 v0.4.3 2022-04-15 11:30:42 -07:00
KJ Tsanaktsidis bf6cfa6bb1
Don't add am/pm marker if there is no time in the format string
Currently, doing something like `format(time, time: :none, hour_cycle:
'h12')` will give a string like "10/04/2021 PM" - the am/pm marker is
added to the skeleton even though the skeleton has no other time
markers.
2022-04-15 14:08:48 +10:00
Damian Nelson 2554722181 v0.4.2 2022-04-06 16:54:51 -07:00
KJ Tsanaktsidis 514f145c1a
Add support for h11/h12/h23/h24 hour cycle
The hour cycle can be directly specified to the call to #format, or
inferred from an "@hours=" keyword on the locale.

The algorithm for fixing up the skeletons & patterns is the same as that
used in Firefox:
https://github.com/tc39/ecma402/issues/665#issuecomment-1084833809
2022-04-06 16:36:43 +10:00
Damian Nelson 59a20a72d8
Merge pull request #54 from KJTsanaktsidis/ktsanaktsidis/allow_overriding_icu_on_macos
Allow overriding libicu on MacOS with FFI_ICU_LIB
2022-04-01 17:29:02 -07:00
KJ Tsanaktsidis e8b6b6bfdf
Allow overriding libicu on MacOS with FFI_ICU_LIB 2022-04-01 16:03:08 +11:00
KJ Tsanaktsidis 5f63e6ff1d
Use the correct function to delete udatpg objects
The skeleton generator is currently using udat_close to delete objects
created with udatpg_open; it should be using udatpg_close instead.

The C-side implementation of udat_close calls straight into the C++
delete operator:

    U_CAPI void U_EXPORT2
    udat_close(UDateFormat* format)
    {
        delete (DateFormat*)format;
    }

The destructor on the DateFormat class is virtual, so i'm frankly
astonished this isn't just chasing and calling a pointer to nowhere. I
guess we got "lucky" and DateFormat and DateTimePatternGenerator have
a similar enough layout by chance that this works. However it's entirely
at the whim of the compiler as to whether this keeps working or not, so
we should fix it and call the correct cleanup function.
2022-04-01 13:28:59 +11:00
Damian Nelson a3d2a14dcf v0.4.1 2022-03-24 14:10:14 -07:00
KJ Tsanaktsidis 8a3058f591
Fix memory saftey issues in passing UcharPointer's to ICU
ICU expects the length of these pointers to be expressed in
_characters_, not _bytes_. This leads to ICU attempting to read past the
end of e.g. a provided pattern.

Because FFI allocates an extra 7 bytes for every malloc call (to
guarantee that it can qword-align everything), this more often than not
leads to ICU reading _unitialized_ memory, rather than _unmapped_
memory, and thus date patterns etc wind up containing garbage.
2022-03-16 16:20:41 +11:00
Konstantinos Tsanaktsidis d2241ad65f
Fix number formatter following removal of Fixnum / Bignum from ruby-next (#50)
The current ruby head in CI removes Fixnum and Bignum classes, which has led to broken builds.

This fix attempts to coalesce the passed-in number to an `int64_t`; if that fails, it falls back to calling `unum_format_decimal` - if the versions of ICU does not support `unum_format_decimal`, a `RangeError` will be raised (which should not be an issue for modern versions of ICU)
2022-03-15 18:15:44 -07:00
Erick Guan 0c6f8b201f
Merge pull request #47 from ccutrer/patch-1
automatically include any Debian multi-arch
2021-08-16 23:16:58 +02:00
Damian Nelson 5b39a7f4e8 v0.4.0 2021-08-16 11:51:24 -07:00
Cody Cutrer d9d6e89c72 automatically include any Debian multi-arch
I could make it "correct" with

```
`dpkg-architecture -qDEB_TARGET_MULTIARCH`.strip
```

but that seems weird to shell out
2021-08-16 10:41:12 -06:00
Damian Nelson 2652ed491b
Update lib/ffi-icu/time_formatting.rb
Co-authored-by: Igor Justino <697824+dadah89@users.noreply.github.com>
2021-08-12 21:02:09 -07:00
Damian Nelson 6b74fac1bd Extract skeleton code and cleanup 2021-08-11 11:56:53 -07:00
Damian Nelson f71e1fabeb Add support for skeleton date formats 2021-03-25 00:02:32 -07:00
Damian Nelson 7fc5d65f6d v0.3.0 2021-01-14 13:56:36 -08:00
Jacob Burroughs 8be8aebbba Support macos big sur
Also makes tests pass against newer icu and ruby

fixes #44
2020-12-02 11:29:43 -06:00
Alex Schmitt d6c036c621
Remove support for EOL Ruby versions (#42)
Support for 1.9 ended on Feb 23, 2015 - https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/
Support for 2.4 ended on April 5, 2020 - https://www.ruby-lang.org/en/news/2020/04/05/support-of-ruby-2-4-has-ended/
2020-10-09 08:16:20 -07:00
Erick Guan e34d13436c
version bump 2019-10-15 00:41:19 +08:00
Damian Nelson f64f574a2c
Update Travis Ruby versions and fix requires 2019-08-09 12:54:32 -07:00
Damian Nelson cd50d38210
Increase read_uchar_buffer size 2019-08-06 11:09:47 -07:00
Cody Cutrer 217e4c0dba allow manipulating attributes of collators 2016-01-29 09:26:37 -07:00
Cody Cutrer e1f9626bd1 add Collator#collation_key method
similar to direct comparison, but more efficient if you need to compare
the same string multiple times
2016-01-29 09:18:52 -07:00
Jari Bakken 246b13f4eb Bump version 2015-10-26 12:34:11 +01:00
Kulgar 9bd0935c5e Solving issue #29 2015-10-16 17:26:43 +02:00
Jari Bakken e6a69a29e4 Bump version to 0.1.9 2015-10-08 17:30:15 +02:00
Erick Guan d0292e198a FIX: wrapper normalizer api with version check #26 2015-10-08 09:22:22 +02:00
Jari Bakken 41ed3fac5c Bump version to 0.1.8 2015-10-01 13:18:10 -07:00
Erick Guan 8999c8f7cb add new normalization api support 2015-09-25 15:40:41 +02:00
Jari Bakken 43d2566d38 Bump version to 0.1.7 2015-07-12 12:26:49 +02:00
Marek Veber a784229dc4 fix "TZ_MAP ||=" -> "TZ_MAP =" 2015-07-12 12:11:29 +02:00
Marek Veber 577cd0e67c rename get_date_format -> date_format
change @@tz_map -> TZ_MAP
2015-07-10 15:03:56 +02:00
Marek Veber 8fee23c82c fix - typo 2015-07-10 14:36:24 +02:00
Marek Veber 0988cfc099 fix - typo 2015-07-10 14:20:27 +02:00
Marek Veber 190e5c4027 Merge remote-tracking branch 'upstream/master' into time-formating 2015-07-10 00:04:56 +02:00
Marek Veber 63a49dd5c4 fix - indent 2015-07-10 00:00:42 +02:00
Jari Bakken 175a323826 Merge pull request #16 from sethk/translit_osx
Treat ‘length’ in UCharBuffer as number of UChars.
2015-07-09 21:42:18 +02:00
Marek Veber 1f3e32d003 implamentation of Time Formatting/Parsing 2015-07-09 02:28:04 +02:00
Marek Veber e4317de96e add support for Time Formatting/Parsing 2015-07-08 17:54:56 +02:00
Jari Bakken 281eaa2101 Bump version to 0.1.6 2015-06-05 09:58:24 +02:00
Charlie Savage d6db18cc4b Supports embedded null characters when detecting encodings. This comes up when using net/http. Assume a response body contains an xml document encoded in utf-16. Net/http will say its encoding is assci-us and thus calling #detect will raise an exception due to the embedded null bytes. 2015-06-03 10:52:41 -06:00
Jari Bakken 7283431bdf Bump version to 0.1.5 2015-04-09 09:37:14 +02:00
J. Maurice c00e6f81c8 Add ICU library search patterns for BSD 2015-04-09 15:33:01 +09:00
Seth Kingsley 58b3ca6fe5 Treat ‘length’ in UCharBuffer as number of UChars.
Fixes buffer overflows on OS X.
2014-12-13 03:30:51 -08:00
Jari Bakken e5676ed23a Ignore transliteration spec + add warning 2014-10-22 18:13:33 +02:00
Jari Bakken 5cd4db3fa6 Bump version to 0.1.4 2014-10-22 17:44:26 +02:00