ROSE 0.11.145.317
Utf8.h
1#ifndef SAGE3_UTF8__H
2#define SAGE3_UTF8__H
3
4/*
5 * Functions used to convert from Unicode to Utf8 and vice-versa
6 *
7 */
8
9#include <exception>
10#include "rosedll.h"
11
12class ROSE_DLL_API Utf8 {
13private:
19 static int getUnicodeValue(const char *bytes, int size);
20
21
22public:
26 class BadUnicodeException : public std::exception {
27 virtual const char* what() const throw() {
28 return "Invalid Unicode character encountered";
29 }
30 };
31
32 //
33 // Instance of BadUnicodeException use to communicate problems.
34 //
35 static BadUnicodeException bad_unicode_exception;
36
40 class BadUtf8CodeException : public std::exception {
41 virtual const char* what() const throw() {
42 return "Invalid Utf8 sequence encountered";
43 }
44 };
45
46 //
47 // Instance of BadUtf8CodeException use to communicate problems.
48 //
49 static BadUtf8CodeException bad_utf8_code_exception;
50
55 static int getCharSize(int val);
56
61 static int getUnicodeValue(const char *bytes);
62
66 static std::string getUtf8String(int value);
67
72 static std::string getPrintableJavaUnicodeCharacter(int value);
73
77 static std::string getPrintableJavaUnicodeString(const char *str);
78};
79
80#endif
Class thrown when a Unicode character is encountered.
Definition Utf8.h:26
Class thrown when a bad Utf8 sequence is encountered.
Definition Utf8.h:40
Definition Utf8.h:12
static std::string getPrintableJavaUnicodeString(const char *str)
Construct a printable unicode string for Java from a given Utf8 string of characters.
static int getUnicodeValue(const char *bytes)
Compute the code value of a Unicode character encoded in UTF8 format in the array of characters "byte...
static std::string getUtf8String(int value)
Convert a unicode character into its Utf8 representation.
static std::string getPrintableJavaUnicodeCharacter(int value)
Convert the Unicode "value" into a printable Unicode character.
static int getCharSize(int val)
Compute the number of bytes that was required to store a UTF8 character sequence that starts with the...