This project provides EncodingScheme of std.encoding based on ICU(International Components for Unicode).
If you are using dub, you can add a dependency by describing it as follows:
"dependencies": {
"icu4d": "~>70.1",
}
On Windows, the package includes binaries, so you can use it as is.
On Linux or MacOS, the ICU must be installed. Be sure to specify the version of the ICU.
apt install libicu-dev=70.1-2
If the required version is not provided by the package manager, you will need to build it from source code.
apt install -y git build-essential libicu-le-hb0 libicu-le-hb-dev
git clone -b release-70-1 --depth 1 --single-branch https://github.com/unicode-org/icu.git
cd icu/icu4c/source
./runConfigureICU Linux --disable-samples --disable-tests --with-data-packaging=library
make -j2
make install
For dynamic linking, use subconfigurations in addition to dependencies.
"dependencies": {
"icu4d": "~>70.1",
}
"subConfigurations": {
"icu4d": "dynamic"
}
icu4d
automatically initialize the dependent library bindbc.icu when register EncodingScheme.
Then, register the EncodingScheme to std.encoding:
import icu4d;
mixin registerICUScheme!"Shift_JIS";
void main()
{
auto textpart = "ごん、お前だったのか。いつも栗をくれたのは";
auto sjistext = textpart.encodeText!"Shift_JIS"();
auto utf16text = textpart.encodeText!"UTF-16LE"();
assert(sjistext.decodeText!"Shift_JIS"() == utf16text.decodeText!"UTF-16LE"());
}
For static linking, use subconfigurations in addition to dependencies.
"dependencies": {
"icu4d": "~>70.1",
}
"subConfigurations": {
"icu4d": "static"
}
Then, register the EncodingScheme to std.encoding:
import icu4d;
mixin registerICUScheme!"EUC-JP";
void main()
{
auto textpart = "青い煙が、まだ筒口から細く出ていました。";
auto eucjptext = textpart.encodeText!"EUC-JP"();
auto utf16text = textpart.encodeText!"UTF-16LE"();
assert(eucjptext.decodeText!"EUC-JP"() == utf16text.decodeText!"UTF-16LE"());
}
This project accepts Issue reports and PullRequests. The PullRequest must pass all tests in CI of GitHub Actions. First, make sure that your environment passes the test with the following commands.
rdmd scripts/runner.d -m=ut # or dub test
rdmd scripts/runner.d -m=it # or dub build / test / run for all ./testcases/* directories.
This library(icu4d) is provided by provided under the BSL-1.0, but the ICU(ICU4C) on which this library depends is provided under the ICU License.