Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ada-url/idna
C++ library implementing the to_ascii and to_unicode functions from the Unicode Technical Standard.
https://github.com/ada-url/idna
idna idna-converter unicode
Last synced: about 7 hours ago
JSON representation
C++ library implementing the to_ascii and to_unicode functions from the Unicode Technical Standard.
- Host: GitHub
- URL: https://github.com/ada-url/idna
- Owner: ada-url
- License: apache-2.0
- Created: 2023-02-04T00:03:26.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-15T04:05:32.000Z (10 months ago)
- Last Synced: 2024-02-17T07:33:54.721Z (9 months ago)
- Topics: idna, idna-converter, unicode
- Language: C++
- Homepage:
- Size: 381 KB
- Stars: 35
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Unicode IDNA
![OpenSSF Scorecard Badge](https://api.securityscorecards.dev/projects/github.com/ada-url/idna/badge)
[![VS17-CI](https://github.com/ada-url/idna/actions/workflows/vs.yml/badge.svg)](https://github.com/ada-url/idna/actions/workflows/vs.yml)
[![Alpine Linux](https://github.com/ada-url/idna/actions/workflows/alpine.yml/badge.svg)](https://github.com/ada-url/idna/actions/workflows/alpine.yml)
[![Alpine Linux](https://github.com/ada-url/idna/actions/workflows/alpine.yml/badge.svg)](https://github.com/ada-url/idna/actions/workflows/alpine.yml)The ada-url/ada library is a C++ library implementing the `to_ascii` and `to_unicode` functions from the [Unicode Technical Standard](https://www.unicode.org/reports/tr46/#ToUnicode) supporting a wide range of systems. It is suitable for URL parsing.
Our IDNA library is used by the Node.js runtime and by [ClickHouse](https://github.com/ClickHouse/ClickHouse/pull/58454).
According to our benchmarks, it can be faster than ICU.
## Requirements
- A recent C++ compiler supporting C++20. We test GCC 12 or better, LLVM 12 or better and Microsoft Visual Studio 2022.
## Usage
```cpp
std::string_view input = u8"meßagefactory.ca";// non-empty UTF-8 string, must be percent decoded
std::string idna_ascii = ada::idna::to_ascii(input);
if(idna_ascii.empty()) {
// There was an error.
}
std::cout << idna_ascii << std::endl;
// outputs 'xn--meagefactory-m9a.ca' if the input is u8"meßagefactory.ca"
```## Benchmarks
You may build a benchmarking tool with the library as follows under macOS and Linux:
```bash
cmake -D ADA_IDNA_BENCHMARKS=ON -B build
cmake --build build
./build/benchmarks/to_ascii
```The commands for users of Visual Studio are slightly different.
Sample result (LLVM 14, Apple M1 Max processor):
```
---------------------------------------------------------------------
Benchmark Time CPU Iterations UserCounters...
---------------------------------------------------------------------
Ada 1504 ns 1504 ns 440984 speed=48.5371M/s time/byte=20.6028ns time/domain=250.667ns url/s=3.98935M/s
Icu 1898 ns 1897 ns 369967 speed=38.4721M/s time/byte=25.9928ns time/url=316.246ns url/s=3.16209M/s
```## License
This code is made available under the Apache License 2.0 as well as the MIT license.
Our tests include third-party code and data. The benchmarking code includes third-party code: it is provided for research purposes only and not part of the library.