https://github.com/b1tflyyyy/utf8-string-cpp
Implementation of wrapper over standard string to work with UTF-8 encoding
https://github.com/b1tflyyyy/utf8-string-cpp
cmake cpp cpp20 cross-platform encoding library linux mit mit-license string unicode utf-8 windows
Last synced: 12 months ago
JSON representation
Implementation of wrapper over standard string to work with UTF-8 encoding
- Host: GitHub
- URL: https://github.com/b1tflyyyy/utf8-string-cpp
- Owner: b1tflyyyy
- License: mit
- Created: 2024-03-18T11:48:03.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-25T18:24:18.000Z (about 2 years ago)
- Last Synced: 2024-03-25T21:27:01.957Z (about 2 years ago)
- Topics: cmake, cpp, cpp20, cross-platform, encoding, library, linux, mit, mit-license, string, unicode, utf-8, windows
- Language: C++
- Homepage:
- Size: 995 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## โ๏ธ UTF-8 String For C++ (utf8::ustring)
## ๐ Brief Description:
This is an implementation of the `UTF-8` encoding standard for `C++`, the implementation is based on the `std::basic_string` class, this gives us the advantage of `std::basic_string` class functions, as well as compatibility with some functions from the standard library.
## ๐ Code Style:
- `C++ AStyle` code style was used for this project.
## ๐ Technical Dependencies:
- `C++ 20`
- `CMake 3.14`
## ๐ Support Status On Systems:
- [X] Linux (verified on clang)
- [X] Windows (verified on gcc && clang)
## ๐ซ Library Features:
- Support for creating an object from: `std::string, std::string_view, const char*`
- Comparing an `utf8::ustring` with `utf8::ustring`, `const char*`, `std::string`, `std::string_view`
- Copy/Move (<- assignment also) constructor implemented
- O(1) Random Access
- Simple replacement of any character, e.g. a smaller character `(1 byte)` with a larger character `(2-3-4 bytes)`.
- Write/read to a file
## โก๏ธ Performance Test:
| String-Version | Test-Name | iteration count | time (for all iterations) |
|:--------------:|:-----------------------:|:---------------:|:-------------------------:|
| std::string | replace_char | 500'000 | ~0.57s |
| utf8::ustring | replace_char | 500'000 | ~0.60s |
## โ Replace Char O(1) ?
Yes and no, in the case where we replace a character with another `with the same size`, we have `O(1)`, in the other case we have `O(~N)`, where N is the length of the string.
But in any case we have `O(1) Random Access`.
## ๐ Code Samples:
```cpp
std::string str{ "hello world!" };
utf8::ustring ustr{ str };
ustr.replace_char("ะฟ", 0); // "ะฟello world!"
ustr == "hi !"; // false
ustr == str; // false
```
## โญ๏ธ Coming Soon:
- Docs.
### ยฉ 2024 Andrii (AKA b1tflyyyy). All rights reserved.