Code Monkey home page Code Monkey logo

utf8convatlstl's Introduction

Utf8ConvAtlStl

C++ helper functions to convert between Unicode UTF-8 and UTF-16

Giovanni Dicanio

This C++ project contains a reusable header-only module implementing conversion code between UTF-8 (std::string) and UTF-16 (CStringW).

It makes sense to use ATL CStringW in portions of C++ code at the Windows ATL/MFC level for UTF-16 text; on the other hand, STL std::string makes sense e.g. in cross-platform C++ code, storing UTF-8 text.

This reusable header-only module (Utf8Conv.h) provides convenient conversion functions between these two Unicode encodings.

Conversion errors are signaled throwing instances of a custom exception class.

For more details, please read my MSDN Magazine article:

C++ - Unicode Encoding Conversions with STL Strings and Win32 APIs

The code presented here is based on that article, but uses CStringW instead of std::wstring for UTF-16 strings at the Windows platform level.

In addition, it's also possible to pass input source strings using an STL-style [start, finish) range; this is useful for converting portions, or views, of source strings.

This project contains also a unit-test (Utf8ConvTest.cpp) for the reusable Unicode conversion module.

Code developed using Visual Studio 2015.
Compiles cleanly at /W4 in both 32-bit builds and 64-bit builds.

Note for Older VC++ Compilers
If you are using Visual Studio 2010, which doesn't support the C++11 constexpr keyword, you can still include this C++ code in your projects, simply substituting every instance of constexpr with const; this code will work just fine.

utf8convatlstl's People

Contributors

giovannidicanio avatar

Watchers

 avatar  avatar

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.