C++
Header-only C++17. No dependencies, UTF-8 std::string output.
Install
A C++17 compiler (GCC, Clang or MSVC). Download the release, or use CMake. GitHub releases
curl -L https://github.com/ediphasLabs/bnspellnum/releases/download/cpp-v0.1.0/bnspellnum-cpp-0.1.0.tar.gz | tar xzQuick start
#include <bnspellnum/bnspellnum.hpp>
namespace bn = bnspellnum;
bn::words(1250000); // বারো লাখ পঞ্চাশ হাজার
bn::words(200, bn::Style::formal); // দুইশত
bn::words("18446744073709551616"); // any size via the string overload
bn::currency("1250.50", /*cheque=*/true); // এক হাজার দুইশো পঞ্চাশ টাকা পঞ্চাশ পয়সা মাত্র
bn::ordinal(2, /*short_form=*/true); // ২য়
bn::year(1971); // উনিশশো একাত্তর
bn::date(16, 12, 1971); // ষোলোই ডিসেম্বর উনিশশো একাত্তর
bn::date(28, 11, std::nullopt, bn::DateStyle::short_form); // ২৮শে নভেম্বর
bn::to_bn_digits("2026"); // ২০২৬API
| Signature | Returns |
|---|---|
words(Int | std::string_view n, Style style = colloquial, Style negative_style = formal) | std::string |
ordinal(Int | std::string_view n, bool short_form = false) | std::string |
year(Int | std::string_view n, YearMode mode = automatic) | std::string |
date(long long day, long long month, std::optional<long long> year = {}, DateStyle style = spoken) (also string_view overload) | std::string |
currency(Int | std::string_view amount, bool cheque = false, Style style = colloquial) | std::string |
to_bn_digits(Int | std::string_view), to_en_digits(std::string_view) | std::string |
bnspellnum::VERSION, bnspellnum::SPEC_VERSION | const char* |
Input types
Int is any integral type except bool and character types. Strings are UTF-8 and may use Bangla digits. The headers are pure ASCII (Bangla text is stored as octal escapes), so the source encoding of your project doesn't matter. On Windows, set the console to UTF-8 (chcp 65001) before printing.
Errors
try {
bn::date(30, 2);
} catch (const bn::out_of_range_error& e) { // derives from bn::error, a std::invalid_argument
std::cerr << e.what() << '\n';
}CMake
include(FetchContent)
FetchContent_Declare(bnspellnum
GIT_REPOSITORY https://github.com/ediphasLabs/bnspellnum.git
GIT_TAG cpp-v0.1.0
SOURCE_SUBDIR packages/cpp)
FetchContent_MakeAvailable(bnspellnum)
target_link_libraries(your_app PRIVATE bnspellnum::bnspellnum)Or copy include/bnspellnum/ from the release tarball into your include path. No build step is needed.
More
- Reference: options, examples, input rules and spelling shared by every package.
- Source on GitHub, and the specification it implements (spec 1.0.0).