ovr_sdk

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/Kernel/OVR_UTF8Util.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,99 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +PublicHeader:   OVR_Kernel.h
     1.7 +Filename    :   OVR_UTF8Util.h
     1.8 +Content     :   UTF8 Unicode character encoding/decoding support
     1.9 +Created     :   September 19, 2012
    1.10 +Notes       : 
    1.11 +
    1.12 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.13 +
    1.14 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.15 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.16 +which is provided at the time of installation or download, or which 
    1.17 +otherwise accompanies this software in either electronic or hard copy form.
    1.18 +
    1.19 +You may obtain a copy of the License at
    1.20 +
    1.21 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.22 +
    1.23 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.24 +distributed under the License is distributed on an "AS IS" BASIS,
    1.25 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.26 +See the License for the specific language governing permissions and
    1.27 +limitations under the License.
    1.28 +
    1.29 +************************************************************************************/
    1.30 +
    1.31 +#ifndef OVR_UTF8Util_h
    1.32 +#define OVR_UTF8Util_h
    1.33 +
    1.34 +#include "OVR_Types.h"
    1.35 +
    1.36 +namespace OVR { namespace UTF8Util {
    1.37 +
    1.38 +//-----------------------------------------------------------------------------------
    1.39 +
    1.40 +// *** UTF8 string length and indexing.
    1.41 +
    1.42 +// Determines the length of UTF8 string in characters.
    1.43 +// If source length is specified (in bytes), null 0 character is counted properly.
    1.44 +intptr_t OVR_STDCALL GetLength(const char* putf8str, intptr_t length = -1);
    1.45 +
    1.46 +// Gets a decoded UTF8 character at index; you can access up to the index returned
    1.47 +// by GetLength. 0 will be returned for out of bounds access.
    1.48 +uint32_t OVR_STDCALL GetCharAt(intptr_t index, const char* putf8str, intptr_t length = -1);
    1.49 +
    1.50 +// Converts UTF8 character index into byte offset.
    1.51 +// -1 is returned if index was out of bounds.
    1.52 +intptr_t OVR_STDCALL GetByteIndex(intptr_t index, const char* putf8str, intptr_t length = -1);
    1.53 +
    1.54 +
    1.55 +// *** 16-bit Unicode string Encoding/Decoding routines.
    1.56 +
    1.57 +// Determines the number of bytes necessary to encode a string.
    1.58 +// Does not count the terminating 0 (null) character.
    1.59 +intptr_t OVR_STDCALL GetEncodeStringSize(const wchar_t* pchar, intptr_t length = -1);
    1.60 +
    1.61 +// Encodes a unicode (UCS-2 only) string into a buffer. The size of buffer must be at
    1.62 +// least GetEncodeStringSize() + 1.
    1.63 +void     OVR_STDCALL EncodeString(char *pbuff, const wchar_t* pchar, intptr_t length = -1);
    1.64 +
    1.65 +// Decode UTF8 into a wchar_t buffer. Must have GetLength()+1 characters available.
    1.66 +// Characters over 0xFFFF are replaced with 0xFFFD.
    1.67 +// Returns the length of resulting string (number of characters)
    1.68 +size_t   OVR_STDCALL DecodeString(wchar_t *pbuff, const char* putf8str, intptr_t bytesLen = -1);
    1.69 +
    1.70 +
    1.71 +// *** Individual character Encoding/Decoding.
    1.72 +
    1.73 +// Determined the number of bytes necessary to encode a UCS character.
    1.74 +int      OVR_STDCALL GetEncodeCharSize(uint32_t ucsCharacter);
    1.75 +
    1.76 +// Encodes the given UCS character into the given UTF-8 buffer.
    1.77 +// Writes the data starting at buffer[offset], and 
    1.78 +// increments offset by the number of bytes written.
    1.79 +// May write up to 6 bytes, so make sure there's room in the buffer
    1.80 +void     OVR_STDCALL EncodeChar(char* pbuffer, intptr_t* poffset, uint32_t ucsCharacter);
    1.81 +
    1.82 +// Return the next Unicode character in the UTF-8 encoded buffer.
    1.83 +// Invalid UTF-8 sequences produce a U+FFFD character as output.
    1.84 +// Advances *utf8_buffer past the character returned. Pointer advance
    1.85 +// occurs even if the terminating 0 character is hit, since that allows
    1.86 +// strings with middle '\0' characters to be supported.
    1.87 +uint32_t OVR_STDCALL DecodeNextChar_Advance0(const char** putf8Buffer);
    1.88 +
    1.89 +// Safer version of DecodeNextChar, which doesn't advance pointer if
    1.90 +// null character is hit.
    1.91 +inline uint32_t DecodeNextChar(const char** putf8Buffer)
    1.92 +{
    1.93 +    uint32_t ch = DecodeNextChar_Advance0(putf8Buffer);
    1.94 +    if (ch == 0)
    1.95 +        (*putf8Buffer)--;
    1.96 +    return ch;
    1.97 +}
    1.98 +
    1.99 +
   1.100 +}} // OVR::UTF8Util
   1.101 +
   1.102 +#endif