Program Listing for File Utf8.h

Program Listing for File Utf8.h#

Return to documentation for file (src/frontend/SageIII/Utf8.h)

#ifndef SAGE3_UTF8__H
#define SAGE3_UTF8__H

/*
 * Functions used to convert from Unicode to Utf8 and vice-versa
 *
 */

#include <exception>
#include "rosedll.h"
using namespace std;

class ROSE_DLL_API Utf8 {
private:
    static int getUnicodeValue(const char *bytes, int size);


public:
    class BadUnicodeException : public exception {
        virtual const char* what() const throw() {
            return "Invalid Unicode character encountered";
        }
    };

    //
    // Instance of BadUnicodeException use to communicate problems.
    //
    static BadUnicodeException bad_unicode_exception;

    class BadUtf8CodeException : public exception {
        virtual const char* what() const throw() {
            return "Invalid Utf8 sequence encountered";
        }
    };

    //
    // Instance of BadUtf8CodeException use to communicate problems.
    //
    static BadUtf8CodeException bad_utf8_code_exception;

    static int getCharSize(int val);

    static int getUnicodeValue(const char *bytes);

    static string getUtf8String(int value);

    static string getPrintableJavaUnicodeCharacter(int value);

    static string getPrintableJavaUnicodeString(const char *str);
};

#endif