-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
976 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef ICU4XCodePointMapData16Response_H | ||
#define ICU4XCodePointMapData16Response_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; | ||
|
||
typedef struct ICU4XCodePointMapData16Response { | ||
ICU4XCodePointMapData16* data; | ||
bool success; | ||
} ICU4XCodePointMapData16Response; | ||
|
||
void ICU4XCodePointMapData16Response_destroy(ICU4XCodePointMapData16Response* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef ICU4XCodePointSetData_H | ||
#define ICU4XCodePointSetData_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct ICU4XCodePointSetData ICU4XCodePointSetData; | ||
#include "ICU4XDataProvider.h" | ||
#include "ICU4XCodePointSetDataResult.h" | ||
#include "ICU4XStaticDataProvider.h" | ||
|
||
ICU4XCodePointSetDataResult ICU4XCodePointSetData_try_get_ascii_hex_digit(const ICU4XDataProvider* provider); | ||
|
||
ICU4XCodePointSetDataResult ICU4XCodePointSetData_try_get_ascii_hex_digit_from_static(const ICU4XStaticDataProvider* provider); | ||
|
||
bool ICU4XCodePointSetData_contains(const ICU4XCodePointSetData* self, char32_t cp); | ||
void ICU4XCodePointSetData_destroy(ICU4XCodePointSetData* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef ICU4XCodePointSetDataResult_H | ||
#define ICU4XCodePointSetDataResult_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
typedef struct ICU4XCodePointSetData ICU4XCodePointSetData; | ||
|
||
typedef struct ICU4XCodePointSetDataResult { | ||
ICU4XCodePointSetData* data; | ||
bool success; | ||
} ICU4XCodePointSetDataResult; | ||
|
||
void ICU4XCodePointSetDataResult_destroy(ICU4XCodePointSetDataResult* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
a.out | ||
a.out.dSYM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.