Git Product home page Git Product logo

utfconv's Introduction

UTF converter

Travis (.org) Coveralls github Cpp Standard Cpp Standard

Open-source library providing conversion between string, u16string, u32string and u8string. It is platform-independent and uses the Unicode UTF code as its basis.

This library distinguishes std::string and std::u8string under C++20, but still assumes the std::string objects contain UTF-8 values.

Synopsis

#include <utf/utf.hpp>

Apart from as_u8(string_view) and as_str8(u8string_view), all the functions decode each Unicode code point of the input (using uint32_t as the interlingua) and encode it in the output. If the decoding fails, an empty string is returned.

Conversion between string[_view] and u8string[_view] is done by simple re-interpretation of the contents.

Versions marked with "C++20" comment are only available, if the standard library defines __cpp_lib_char8_t.

utf::is_valid

bool utf::is_valid(std::u8string_view src);         // C++20
bool utf::is_valid(std::string_view src);
bool utf::is_valid(std::u16string_view src);

Tries to decode the string one character at a time and returns false as soon as decoding fails; otherwise, returns true. If the utf::is_valid returns false for any argument, then any is_xxx function will return an empty string for the same argument.

bool utf::is_valid(std::u32string_view src);

Returns true.

utf::as_u8

std::u8string utf::as_u8(std::u16string_view src);  // C++20
std::u8string utf::as_u8(std::u32string_view src);  // C++20
std::u8string utf::as_u8(std::string_view src);     // C++20

(C++20) Converts other UTF strings to std::u8string. The behavior is that of utf::as_str8, except for the type of the character used.

utf::as_str8

std::string utf::as_str8(std::u8string_view src);   // C++20
std::string utf::as_str8(std::u16string_view src);
std::string utf::as_str8(std::u32string_view src);

Converts other UTF strings to std::string encoded as UTF-8. If compiled as C++20, the behavior is that of utf::as_u8, except for the type of the character used.

utf::as_str8

std::u16string utf::as_u16(std::u8string_view src); // C++20
std::u16string utf::as_u16(std::string_view src);
std::u16string utf::as_u16(std::u32string_view src);

Converts other UTF strings to std::u16string.

utf::as_u32

std::u32string utf::as_u32(std::u8string_view src); // C++20
std::u32string utf::as_u32(std::string_view src);
std::u32string utf::as_u32(std::u16string_view src);

Converts other UTF strings to std::u32string.

#include <utf/version.hpp>

utf::version

constexpr semver::project_version utf::version;

Current version of the library to link against.

utf::get_version

semver::project_version utf::get_version();

Current version of loaded library (if used in dynamic linking) or the same value as utf::version (if used in static linking).

UTFCONV_NAME macro

#define UTFCONV_NAME "utfconv"

Name of the library

UTFCONV_VERSION macros

#define UTFCONV_VERSION_MAJOR
#define UTFCONV_VERSION_MINOR
#define UTFCONV_VERSION_PATCH
#define UTFCONV_VERSION_STABILITY

C macros representing the same information, as utf::version variable, that is UTFCONV_VERSION_MAJOR / MINOR / PATCH have the same values, as utf::version.get_major() / get_minor() / get_patch(). UTFCONV_VERSION_STABILITY contains the same string, that would be returned by utf::version.get_prerelease().to_string(), that is, either an empty string, or string starting with a hyphen for easy version strings concatenation.

utfconv's People

Contributors

mzdun avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

utfconv's Issues

Header path conflict

Hello, I am trying to use this lib managed by Conan, but when I include your lib header like this #include "utf/utf.hpp", it conflicts to a Boost lib header boost/nowide/utf/utf.hpp. Since the last parts of the paths are identical, it depending on which one can be found first by the compiler.

I know I can move the header to another path manually, but this makes it less convenient for compatible deployment.

Can you please change your include path to a more specific one, such as utfconv/utf.hpp or mbits/utfconv/utf.hpp or mbits/utfconv.hpp, to help to get rid of the conflict?

Thank you very much.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.