Coder Social home page Coder Social logo

petiteutf8's Introduction

petiteutf8

Small, simple and header only C++17 UTF-8 library.

Usage

Download PetiteUtf8.hpp, place it in your project and you are ready to go:

#include <PetiteUtf8.hpp>

#include <cassert>
#include <fstream>
#include <iostream>
#include <string>

int main()
{
    std::string const greeting{ u8"hello, 世界" };
    assert( greeting.length() == 13 ); // wrong length

    std::u16string const & decodedGreeting{ petiteutf8::utf8::decode( greeting ) };
    assert( decodedGreeting.length() == 9 ); // correct length
    assert( greeting == petiteutf8::utf8::encode( decodedGreeting ) );

    std::u32string const & widerGreeting{ petiteutf8::utf8::decode< char32_t >( greeting ) };
    assert( widerGreeting.length() == 9 );
    assert( greeting == petiteutf8::utf8::encode< char32_t >( widerGreeting ) );

    std::string const & narrowGreeting{ petiteutf8::utf8::decode< char >( greeting ) }; // data loss for 世 and 界
    assert( narrowGreeting.length() == 9 );
    assert( greeting != petiteutf8::utf8::encode< char >( narrowGreeting ) ); // consequence of data loss

    return 0;
}

Running tests

$ git clone https://github.com/hermanzdosilovic/petiteutf8.git
$ cd petiteutf8
$ git submodule init
$ git submodule update
$ mkdir build
$ cd build
$ cmake ..
$ make
$ ./PetiteUtf8Test

Test dependencies

Tested with

  • GCC 8.1.0

petiteutf8's People

Contributors

hermanzdosilovic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

skyformat99

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.