1 #ifndef __UnicodeConversions_h__
2 #define __UnicodeConversions_h__
3 
4 // =================================================================================================
5 // Copyright 2004 Adobe Systems Incorporated
6 // All Rights Reserved.
7 //
8 // NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the terms
9 // of the Adobe license agreement accompanying it.
10 // =================================================================================================
11 
12 #include <string>
13 
14 // =================================================================================================
15 
16 typedef XMP_Uns8  UTF8Unit;
17 typedef XMP_Uns16 UTF16Unit;
18 typedef XMP_Uns32 UTF32Unit;
19 
20 // -------------------------------------------------------------------------------------------------
21 
22 // ! The UTF16 and UTF32 counts are in storage units, not bytes! CodePoint values are always native.
23 
24 // *** MIght be better to return a status than throw an exception for errors?
25 
26 typedef void (*CodePoint_to_UTF16_Proc) ( const UTF32Unit cpIn, UTF16Unit * utf16Out, const size_t utf16Len, size_t * utf16Written );
27 
28 typedef void (*CodePoint_from_UTF16_Proc) ( const UTF16Unit * utf16In, const size_t utf16Len, UTF32Unit * cpOut, size_t * utf16Read );
29 
30 typedef void (*UTF8_to_UTF16_Proc)  ( const UTF8Unit *  utf8In,    const size_t utf8Len,
31 				                      UTF16Unit *       utf16Out,  const size_t utf16Len,
32 				                      size_t *          utf8Read,  size_t *     utf16Written );
33 
34 typedef void (*UTF8_to_UTF32_Proc)  ( const UTF8Unit *  utf8In,    const size_t utf8Len,
35 				                      UTF32Unit *       utf32Out,  const size_t utf32Len,
36 				                      size_t *          utf8Read,  size_t *     utf32Written );
37 
38 typedef void (*UTF16_to_UTF8_Proc)  ( const UTF16Unit * utf16In,   const size_t utf16Len,
39 				                      UTF8Unit *        utf8Out,   const size_t utf8Len,
40 				                      size_t *          utf16Read, size_t *     utf8Written );
41 
42 typedef void (*UTF32_to_UTF8_Proc)  ( const UTF32Unit * utf32In,   const size_t utf32Len,
43 				                      UTF8Unit *        utf8Out,   const size_t utf8Len,
44 				                      size_t *          utf32Read, size_t *     utf8Written );
45 
46 typedef void (*UTF16_to_UTF32_Proc) ( const UTF16Unit * utf16In,   const size_t utf16Len,
47 				                      UTF32Unit *       utf32Out,  const size_t utf32Len,
48 				                      size_t *          utf16Read, size_t *     utf32Written );
49 
50 typedef void (*UTF32_to_UTF16_Proc) ( const UTF32Unit * utf32In,   const size_t utf32Len,
51 				                      UTF16Unit *       utf16Out,  const size_t utf16Len,
52 				                      size_t *          utf32Read, size_t *     utf16Written );
53 
54 // -------------------------------------------------------------------------------------------------
55 
56 extern void CodePoint_to_UTF8 ( const UTF32Unit cpIn, UTF8Unit *  utf8Out,  const size_t utf8Len,  size_t * utf8Written );
57 
58 extern void CodePoint_from_UTF8 ( const UTF8Unit *  utf8In,  const size_t utf8Len,  UTF32Unit * cpOut, size_t * utf8Read );
59 
60 extern CodePoint_to_UTF16_Proc CodePoint_to_UTF16BE;
61 extern CodePoint_to_UTF16_Proc CodePoint_to_UTF16LE;
62 
63 extern CodePoint_from_UTF16_Proc CodePoint_from_UTF16BE;
64 extern CodePoint_from_UTF16_Proc CodePoint_from_UTF16LE;
65 
66 extern UTF8_to_UTF16_Proc  UTF8_to_UTF16BE;
67 extern UTF8_to_UTF16_Proc  UTF8_to_UTF16LE;
68 
69 extern UTF8_to_UTF32_Proc  UTF8_to_UTF32BE;
70 extern UTF8_to_UTF32_Proc  UTF8_to_UTF32LE;
71 
72 extern UTF16_to_UTF8_Proc  UTF16BE_to_UTF8;
73 extern UTF16_to_UTF8_Proc  UTF16LE_to_UTF8;
74 
75 extern UTF32_to_UTF8_Proc  UTF32BE_to_UTF8;
76 extern UTF32_to_UTF8_Proc  UTF32LE_to_UTF8;
77 
78 extern UTF8_to_UTF16_Proc  UTF8_to_UTF16Native;
79 extern UTF8_to_UTF32_Proc  UTF8_to_UTF32Native;
80 
81 extern UTF16_to_UTF8_Proc  UTF16Native_to_UTF8;
82 extern UTF32_to_UTF8_Proc  UTF32Native_to_UTF8;
83 
84 extern UTF16_to_UTF32_Proc UTF16BE_to_UTF32BE;
85 extern UTF16_to_UTF32_Proc UTF16BE_to_UTF32LE;
86 
87 extern UTF16_to_UTF32_Proc UTF16LE_to_UTF32BE;
88 extern UTF16_to_UTF32_Proc UTF16LE_to_UTF32LE;
89 
90 extern UTF32_to_UTF16_Proc UTF32BE_to_UTF16BE;
91 extern UTF32_to_UTF16_Proc UTF32BE_to_UTF16LE;
92 
93 extern UTF32_to_UTF16_Proc UTF32LE_to_UTF16BE;
94 extern UTF32_to_UTF16_Proc UTF32LE_to_UTF16LE;
95 
96 extern void SwapUTF16 ( const UTF16Unit * utf16In, UTF16Unit * utf16Out, const size_t utf16Len );
97 extern void SwapUTF32 ( const UTF32Unit * utf32In, UTF32Unit * utf32Out, const size_t utf32Len );
98 
99 extern void ToUTF16 ( const UTF8Unit * utf8In, size_t utf8Len, std::string * utf16Str, bool bigEndian );
100 extern void ToUTF32 ( const UTF8Unit * utf8In, size_t utf8Len, std::string * utf32Str, bool bigEndian );
101 
102 extern void FromUTF16 ( const UTF16Unit * utf16In, size_t utf16Len, std::string * utf8Str, bool bigEndian );
103 extern void FromUTF32 ( const UTF32Unit * utf32In, size_t utf32Len, std::string * utf8Str, bool bigEndian );
104 
105 extern void ToUTF16Native ( const UTF8Unit * utf8In, size_t utf8Len, std::string * utf16Str );
106 extern void ToUTF32Native ( const UTF8Unit * utf8In, size_t utf8Len, std::string * utf32Str );
107 
108 extern void FromUTF16Native ( const UTF16Unit * utf16In, size_t utf16Len, std::string * utf8Str );
109 extern void FromUTF32Native ( const UTF32Unit * utf32In, size_t utf32Len, std::string * utf8Str );
110 
111 extern void InitializeUnicodeConversions();
112 
113 // =================================================================================================
114 
115 #endif	// __UnicodeConversions_h__
116