Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_UTF8Util.h
Go to the documentation of this file.
1 /************************************************************************************
2 
3 PublicHeader: OVR.h
4 Filename : OVR_UTF8Util.h
5 Content : UTF8 Unicode character encoding/decoding support
6 Created : September 19, 2012
7 Notes :
8 
9 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
10 
11 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
12 you may not use the Oculus VR Rift SDK except in compliance with the License,
13 which is provided at the time of installation or download, or which
14 otherwise accompanies this software in either electronic or hard copy form.
15 
16 You may obtain a copy of the License at
17 
18 http://www.oculusvr.com/licenses/LICENSE-3.1
19 
20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
25 
26 ************************************************************************************/
27 
28 #ifndef OVR_UTF8Util_h
29 #define OVR_UTF8Util_h
30 
31 #include "OVR_Types.h"
32 
33 namespace OVR { namespace UTF8Util {
34 
35 //-----------------------------------------------------------------------------------
36 
37 // *** UTF8 string length and indexing.
38 
39 // Determines the length of UTF8 string in characters.
40 // If source length is specified (in bytes), null 0 character is counted properly.
41 SPInt OVR_STDCALL GetLength(const char* putf8str, SPInt length = -1);
42 
43 // Gets a decoded UTF8 character at index; you can access up to the index returned
44 // by GetLength. 0 will be returned for out of bounds access.
45 UInt32 OVR_STDCALL GetCharAt(SPInt index, const char* putf8str, SPInt length = -1);
46 
47 // Converts UTF8 character index into byte offset.
48 // -1 is returned if index was out of bounds.
49 SPInt OVR_STDCALL GetByteIndex(SPInt index, const char* putf8str, SPInt length = -1);
50 
51 
52 // *** 16-bit Unicode string Encoding/Decoding routines.
53 
54 // Determines the number of bytes necessary to encode a string.
55 // Does not count the terminating 0 (null) character.
56 SPInt OVR_STDCALL GetEncodeStringSize(const wchar_t* pchar, SPInt length = -1);
57 
58 // Encodes a unicode (UCS-2 only) string into a buffer. The size of buffer must be at
59 // least GetEncodeStringSize() + 1.
60 void OVR_STDCALL EncodeString(char *pbuff, const wchar_t* pchar, SPInt length = -1);
61 
62 // Decode UTF8 into a wchar_t buffer. Must have GetLength()+1 characters available.
63 // Characters over 0xFFFF are replaced with 0xFFFD.
64 // Returns the length of resulting string (number of characters)
65 UPInt OVR_STDCALL DecodeString(wchar_t *pbuff, const char* putf8str, SPInt bytesLen = -1);
66 
67 
68 // *** Individual character Encoding/Decoding.
69 
70 // Determined the number of bytes necessary to encode a UCS character.
71 int OVR_STDCALL GetEncodeCharSize(UInt32 ucsCharacter);
72 
73 // Encodes the given UCS character into the given UTF-8 buffer.
74 // Writes the data starting at buffer[offset], and
75 // increments offset by the number of bytes written.
76 // May write up to 6 bytes, so make sure there's room in the buffer
77 void OVR_STDCALL EncodeChar(char* pbuffer, SPInt* poffset, UInt32 ucsCharacter);
78 
79 // Return the next Unicode character in the UTF-8 encoded buffer.
80 // Invalid UTF-8 sequences produce a U+FFFD character as output.
81 // Advances *utf8_buffer past the character returned. Pointer advance
82 // occurs even if the terminating 0 character is hit, since that allows
83 // strings with middle '\0' characters to be supported.
84 UInt32 OVR_STDCALL DecodeNextChar_Advance0(const char** putf8Buffer);
85 
86 // Safer version of DecodeNextChar, which doesn't advance pointer if
87 // null character is hit.
88 inline UInt32 DecodeNextChar(const char** putf8Buffer)
89 {
90  UInt32 ch = DecodeNextChar_Advance0(putf8Buffer);
91  if (ch == 0)
92  (*putf8Buffer)--;
93  return ch;
94 }
95 
96 
97 }} // OVR::UTF8Util
98 
99 #endif
UInt32 OVR_STDCALL GetCharAt(SPInt index, const char *putf8str, SPInt length)
int OVR_STDCALL GetEncodeCharSize(UInt32 ucs_character)
SPInt OVR_STDCALL GetLength(const char *buf, SPInt buflen)
UInt32 OVR_STDCALL DecodeNextChar_Advance0(const char **putf8Buffer)
UPInt OVR_STDCALL DecodeString(wchar_t *pbuff, const char *putf8str, SPInt bytesLen)
uint32_t UInt32
Definition: OVR_Types.h:253
void OVR_STDCALL EncodeChar(char *pbuffer, SPInt *pindex, UInt32 ucs_character)
size_t UPInt
Definition: OVR_Types.h:218
#define OVR_STDCALL
UInt32 DecodeNextChar(const char **putf8Buffer)
Definition: OVR_UTF8Util.h:88
SPInt OVR_STDCALL GetByteIndex(SPInt index, const char *putf8str, SPInt length)
ptrdiff_t SPInt
Definition: OVR_Types.h:219
void OVR_STDCALL EncodeString(char *pbuff, const wchar_t *pchar, SPInt length)
SPInt OVR_STDCALL GetEncodeStringSize(const wchar_t *pchar, SPInt length)
int char * index(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1))