ovr_sdk

view LibOVR/Src/Kernel/OVR_UTF8Util.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line source
1 /************************************************************************************
3 PublicHeader: OVR_Kernel.h
4 Filename : OVR_UTF8Util.h
5 Content : UTF8 Unicode character encoding/decoding support
6 Created : September 19, 2012
7 Notes :
9 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
11 Licensed under the Oculus VR Rift SDK License Version 3.2 (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.
16 You may obtain a copy of the License at
18 http://www.oculusvr.com/licenses/LICENSE-3.2
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.
26 ************************************************************************************/
28 #ifndef OVR_UTF8Util_h
29 #define OVR_UTF8Util_h
31 #include "OVR_Types.h"
33 namespace OVR { namespace UTF8Util {
35 //-----------------------------------------------------------------------------------
37 // *** UTF8 string length and indexing.
39 // Determines the length of UTF8 string in characters.
40 // If source length is specified (in bytes), null 0 character is counted properly.
41 intptr_t OVR_STDCALL GetLength(const char* putf8str, intptr_t length = -1);
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_t OVR_STDCALL GetCharAt(intptr_t index, const char* putf8str, intptr_t length = -1);
47 // Converts UTF8 character index into byte offset.
48 // -1 is returned if index was out of bounds.
49 intptr_t OVR_STDCALL GetByteIndex(intptr_t index, const char* putf8str, intptr_t length = -1);
52 // *** 16-bit Unicode string Encoding/Decoding routines.
54 // Determines the number of bytes necessary to encode a string.
55 // Does not count the terminating 0 (null) character.
56 intptr_t OVR_STDCALL GetEncodeStringSize(const wchar_t* pchar, intptr_t length = -1);
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, intptr_t length = -1);
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 size_t OVR_STDCALL DecodeString(wchar_t *pbuff, const char* putf8str, intptr_t bytesLen = -1);
68 // *** Individual character Encoding/Decoding.
70 // Determined the number of bytes necessary to encode a UCS character.
71 int OVR_STDCALL GetEncodeCharSize(uint32_t ucsCharacter);
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, intptr_t* poffset, uint32_t ucsCharacter);
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_t OVR_STDCALL DecodeNextChar_Advance0(const char** putf8Buffer);
86 // Safer version of DecodeNextChar, which doesn't advance pointer if
87 // null character is hit.
88 inline uint32_t DecodeNextChar(const char** putf8Buffer)
89 {
90 uint32_t ch = DecodeNextChar_Advance0(putf8Buffer);
91 if (ch == 0)
92 (*putf8Buffer)--;
93 return ch;
94 }
97 }} // OVR::UTF8Util
99 #endif