WcwidthWrapper is a C++ library that calculates the display width of Unicode characters, facilitating accurate rendering in console applications. It provides a native interface for determining the number of terminal cells a Unicode character occupies, supporting wide characters and surrogate pairs.
- Unicode Width Calculation: Determine the number of terminal cells a Unicode character occupies.
- Support for Surrogate Pairs: Accurately handle characters represented by surrogate pairs.
- Native C++ Interface: Seamlessly integrate with C++ applications without the need for external dependencies.
To integrate WcwidthWrapper into your project:
-
Clone the repository:
git clone https://github.com/BDisp/WcwidthWrapper.git
-
Include the header file in your project:
#include "NativeExports.h"
-
Link against the compiled library during the build process.
Here's a simple example demonstrating how to use WcwidthWrapper:
#include <iostream>
#include "NativeExports.h"
int main() {
wchar_t ch = L'あ'; // Example Unicode character
int width = GetWidth(ch, /* version */ 0);
std::wcout << L"Character width: " << width << std::endl;
return 0;
}This project is inspired by the Spectre.Console/wcwidth repository, a .NET library that calculates the width of Unicode characters. We extend our gratitude to the Spectre.Console team for their work, which served as a valuable reference in developing this C++ wrapper.
This project is licensed under the MIT License. See the LICENSE file for details.