-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Properties FFI #1269
Initial Properties FFI #1269
Changes from 10 commits
8770fb1
2fe554d
9475222
aac221c
a8bc76a
3c7b32e
35a2c75
b7df93e
f47e76e
a7c2296
637ac34
7a762e9
24c9965
58b2537
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef ICU4XUnicodeScriptMapProperty_H | ||
#define ICU4XUnicodeScriptMapProperty_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct ICU4XUnicodeScriptMapProperty ICU4XUnicodeScriptMapProperty; | ||
#include "ICU4XDataProvider.h" | ||
#include "ICU4XUnicodeScriptMapPropertyResult.h" | ||
#include "ICU4XStaticDataProvider.h" | ||
|
||
ICU4XUnicodeScriptMapPropertyResult ICU4XUnicodeScriptMapProperty_try_get(const ICU4XDataProvider* provider); | ||
|
||
ICU4XUnicodeScriptMapPropertyResult ICU4XUnicodeScriptMapProperty_try_get_from_static(const ICU4XStaticDataProvider* provider); | ||
|
||
uint32_t ICU4XUnicodeScriptMapProperty_get(const ICU4XUnicodeScriptMapProperty* self, char32_t cp); | ||
void ICU4XUnicodeScriptMapProperty_destroy(ICU4XUnicodeScriptMapProperty* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef ICU4XUnicodeScriptMapPropertyResult_H | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to have this in a separate file from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implementation detail of Diplomat. |
||
#define ICU4XUnicodeScriptMapPropertyResult_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
typedef struct ICU4XUnicodeScriptMapProperty ICU4XUnicodeScriptMapProperty; | ||
|
||
typedef struct ICU4XUnicodeScriptMapPropertyResult { | ||
ICU4XUnicodeScriptMapProperty* data; | ||
bool success; | ||
} ICU4XUnicodeScriptMapPropertyResult; | ||
|
||
void ICU4XUnicodeScriptMapPropertyResult_destroy(ICU4XUnicodeScriptMapPropertyResult* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef ICU4XUnicodeSetProperty_H | ||
#define ICU4XUnicodeSetProperty_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct ICU4XUnicodeSetProperty ICU4XUnicodeSetProperty; | ||
#include "ICU4XDataProvider.h" | ||
#include "ICU4XUnicodeSetPropertyResult.h" | ||
#include "ICU4XStaticDataProvider.h" | ||
|
||
ICU4XUnicodeSetPropertyResult ICU4XUnicodeSetProperty_try_get_ascii_hex_digit(const ICU4XDataProvider* provider); | ||
|
||
ICU4XUnicodeSetPropertyResult ICU4XUnicodeSetProperty_try_get_ascii_hex_digit_from_static(const ICU4XStaticDataProvider* provider); | ||
|
||
bool ICU4XUnicodeSetProperty_contains(const ICU4XUnicodeSetProperty* self, char32_t cp); | ||
void ICU4XUnicodeSetProperty_destroy(ICU4XUnicodeSetProperty* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef ICU4XUnicodeSetPropertyResult_H | ||
#define ICU4XUnicodeSetPropertyResult_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
typedef struct ICU4XUnicodeSetProperty ICU4XUnicodeSetProperty; | ||
|
||
typedef struct ICU4XUnicodeSetPropertyResult { | ||
ICU4XUnicodeSetProperty* data; | ||
bool success; | ||
} ICU4XUnicodeSetPropertyResult; | ||
|
||
void ICU4XUnicodeSetPropertyResult_destroy(ICU4XUnicodeSetPropertyResult* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
``properties_maps::ffi`` | ||
======================== | ||
|
||
.. cpp:class:: ICU4XCodePointMapData16 | ||
|
||
An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. For properties whose values fit into 16 bits. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/index.html>`__ for more information. | ||
|
||
.. cpp:function:: static ICU4XCodePointMapData16Response try_get_script(const ICU4XDataProvider& provider) | ||
|
||
Gets a map for Unicode property Script from a :cpp:class:`ICU4XDataProvider`. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/maps/fn.get_script.html>`__ for more information. | ||
|
||
.. cpp:function:: static ICU4XCodePointMapData16Response try_get_script_from_static(const ICU4XStaticDataProvider& provider) | ||
|
||
Gets a map for Unicode property Script from a :cpp:class:`ICU4XStaticDataProvider`. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/maps/fn.get_script.html>`__ for more information. | ||
|
||
.. cpp:function:: uint16_t get(char32_t cp) const | ||
|
||
Gets the value for a code point. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_codepointtrie/codepointtrie/struct.CodePointTrie.html#method.get_u32>`__ for more information. | ||
|
||
.. cpp:struct:: ICU4XCodePointMapData16Response | ||
|
||
.. cpp:member:: std::optional<ICU4XCodePointMapData16> data | ||
|
||
The :cpp:class:`ICU4XCodePointMapData16`, if creation was successful. | ||
|
||
.. cpp:member:: bool success | ||
|
||
Whether creating the :cpp:class:`ICU4XCodePointMapData16` was successful. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
``properties_sets::ffi`` | ||
======================== | ||
|
||
.. cpp:class:: ICU4XCodePointSetData | ||
|
||
An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/index.html>`__ for more information. | ||
|
||
.. cpp:function:: static ICU4XCodePointSetDataResult try_get_ascii_hex_digit(const ICU4XDataProvider& provider) | ||
|
||
Gets a set for Unicode property ascii_hex_digit from a :cpp:class:`ICU4XDataProvider`. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/sets/fn.get_ascii_hex_digit.html>`__ for more information. | ||
|
||
.. cpp:function:: static ICU4XCodePointSetDataResult try_get_ascii_hex_digit_from_static(const ICU4XStaticDataProvider& provider) | ||
|
||
Gets a set for Unicode property ascii_hex_digit from a :cpp:class:`ICU4XStaticDataProvider`. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/sets/fn.get_ascii_hex_digit.html>`__ for more information. | ||
|
||
.. cpp:function:: bool contains(char32_t cp) const | ||
|
||
Checks whether the code point is in the set. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_uniset/struct.UnicodeSet.html#method.contains>`__ for more information. | ||
|
||
.. cpp:struct:: ICU4XCodePointSetDataResult | ||
|
||
.. cpp:member:: std::optional<ICU4XCodePointSetData> data | ||
|
||
The :cpp:class:`ICU4XCodePointSetData`, if creation was successful. | ||
|
||
.. cpp:member:: bool success | ||
|
||
Whether creating the :cpp:class:`ICU4XCodePointSetData` was successful. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
a.out | ||
a.out.dSYM |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This file is part of ICU4X. For terms of use, please see the file | ||
# called LICENSE at the top level of the ICU4X source tree | ||
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
||
.DEFAULT_GOAL := test | ||
.PHONY: build test | ||
|
||
ALL_HEADERS := $(wildcard ../../include/*.hpp) $(wildcard ../../../c/include/*.h) | ||
ALL_RUST := $(wildcard ../../../src/*.rs) | ||
|
||
CXX?=g++ | ||
|
||
$(ALL_RUST): | ||
|
||
$(ALL_HEADERS): | ||
|
||
|
||
../../../../../target/debug/libicu_capi.a: $(ALL_RUST) | ||
cargo build -p icu_capi | ||
|
||
a.out: ../../../../../target/debug/libicu_capi.a $(ALL_HEADERS) test.cpp | ||
$(CXX) -std=c++17 test.cpp ../../../../../target/debug/libicu_capi.a -ldl -lpthread -lm -g | ||
|
||
build: a.out | ||
|
||
test: build | ||
./a.out |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// This file is part of ICU4X. For terms of use, please see the file | ||
// called LICENSE at the top level of the ICU4X source tree | ||
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
||
#include "../../include/ICU4XCodePointSetData.hpp" | ||
#include "../../include/ICU4XCodePointMapData16.hpp" | ||
#include "../../include/ICU4XCodePointMapData16Response.hpp" | ||
|
||
#include <iostream> | ||
|
||
const std::string_view path = "../../../../../provider/testdata/data/json/"; | ||
|
||
int test_set_property(ICU4XCodePointSetDataResult result, char32_t included, char32_t excluded) { | ||
if (!result.success) { | ||
std::cout << "Failed to create ICU4XCodePointSetData" << std::endl; | ||
return 1; | ||
} | ||
bool contains1 = result.data.value().contains(included); | ||
bool contains2 = result.data.value().contains(excluded); | ||
std::cout << std::hex; // print hex for U+#### | ||
if (contains1 && !contains2) { | ||
std::cout << "Set correctly contains U+" << included << " and not U+" << excluded << std::endl; | ||
} else { | ||
std::cout << "Set returns wrong result on U+" << included << " or U+" << excluded << std::endl; | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
int test_map_16_property(ICU4XCodePointMapData16Response result, char32_t sample, uint32_t expected) { | ||
if (!result.success) { | ||
std::cout << "Failed to create ICU4XCodePointMapData16" << std::endl; | ||
return 1; | ||
} | ||
uint32_t actual = result.data.value().get(sample); | ||
std::cout << std::hex; // print hex for U+#### | ||
if (actual == expected) { | ||
std::cout << "Code point U+" << sample << " correctly mapped to 0x" << actual << std::endl; | ||
} else { | ||
std::cout << "Code point U+" << sample << " incorrectly mapped to 0x" << actual << std::endl; | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
int main() { | ||
ICU4XDataProvider dp = ICU4XDataProvider::create_fs(path).provider.value(); | ||
int result; | ||
|
||
result = test_set_property( | ||
ICU4XCodePointSetData::try_get_ascii_hex_digit(dp), | ||
u'3', | ||
u'੩' | ||
); | ||
if (result != 0) { | ||
return result; | ||
} | ||
|
||
result = test_map_16_property( | ||
ICU4XCodePointMapData16::try_get_script(dp), | ||
u'木', | ||
17 // Script::Han | ||
); | ||
if (result != 0) { | ||
return result; | ||
} | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef ICU4XCodePointMapData16_H | ||
#define ICU4XCodePointMapData16_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct ICU4XCodePointMapData16 ICU4XCodePointMapData16; | ||
#include "ICU4XDataProvider.h" | ||
#include "ICU4XCodePointMapData16Response.h" | ||
#include "ICU4XStaticDataProvider.h" | ||
|
||
ICU4XCodePointMapData16Response ICU4XCodePointMapData16_try_get_script(const ICU4XDataProvider* provider); | ||
|
||
ICU4XCodePointMapData16Response ICU4XCodePointMapData16_try_get_script_from_static(const ICU4XStaticDataProvider* provider); | ||
|
||
uint16_t ICU4XCodePointMapData16_get(const ICU4XCodePointMapData16* self, char32_t cp); | ||
void ICU4XCodePointMapData16_destroy(ICU4XCodePointMapData16* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(thought)
This file is auto-generated, right?
Would it be possible to have Diplomat add a "this file was autogenerated by ..." comment at the top of generated files, to make it easier for reviewers / readers of the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That's a good idea. rust-diplomat/diplomat#100