UnicodeConv.h

#pragma once
#ifndef UNICODE_CONV_H_
#define UNICODE_CONV_H_

/*
Unicode converter from https://github.com/benikabocha/unicode_conv

UTF8 -> UTF16
UTF8 -> UTF32
UTF16 -> UTF8
UTF16 -> UTF32
UTF32 -> UTF8
UTF32 -> UTF16
*/

#include "cxUtils.h"
#include <array>
#include <string>

namespace ceda
{
    cxUtils_API bool ConvChU8ToU16(const std::array<char, 4>& u8Ch, std::array<char16_t, 2>& u16Ch);
    cxUtils_API bool ConvChU8ToU32(const std::array<char, 4>& u8Ch, char32_t& u32Ch);

    cxUtils_API bool ConvChU16ToU8(const std::array<char16_t, 2>& u16Ch, std::array<char, 4>& u8Ch);
    cxUtils_API bool ConvChU16ToU32(const std::array<char16_t, 2>& u16Ch, char32_t& u32Ch);

    cxUtils_API bool ConvChU32ToU8(const char32_t u32Ch, std::array<char, 4>& u8Ch);
    cxUtils_API bool ConvChU32ToU16(const char32_t u32Ch, std::array<char16_t, 2>& u16Ch);

    cxUtils_API bool ConvU8ToU16(const std::string& u8Str, std::u16string& u16Str);
    cxUtils_API bool ConvU8ToU32(const std::string& u8Str, std::u32string& u32Str);

    cxUtils_API bool ConvU16ToU8(const std::u16string& u16Str, std::string& u8Str);
    cxUtils_API bool ConvU16ToU32(const std::u16string& u16Str, std::u32string& u32Str);

    cxUtils_API bool ConvU32ToU8(const std::u32string& u32Str, std::string& u8Str);
    cxUtils_API bool ConvU32ToU16(const std::u32string& u32Str, std::u16string& u16Str);

    inline bool Utf16FromUtf8(std::u16string& dst, const std::string& src) 
    { 
        return ConvU8ToU16(src,dst);
    }
    inline bool Utf8FromUtf16(std::string& dst, const std::u16string& src) 
    { 
        return ConvU16ToU8(src,dst);
    }

} // namespace ceda

#endif  // UNICODE_CONV_H_