oculus1

diff libovr/Src/Kernel/OVR_UTF8Util.h @ 3:b069a5c27388

added a couple more stuff, fixed all the LibOVR line endings
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 15 Sep 2013 04:10:05 +0300
parents e2f9e4603129
children
line diff
     1.1 --- a/libovr/Src/Kernel/OVR_UTF8Util.h	Sat Sep 14 17:51:03 2013 +0300
     1.2 +++ b/libovr/Src/Kernel/OVR_UTF8Util.h	Sun Sep 15 04:10:05 2013 +0300
     1.3 @@ -1,1 +1,88 @@
     1.4 -/************************************************************************************
     1.5 
     1.6 PublicHeader:   OVR.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 2012 Oculus VR, Inc. All Rights reserved.
    1.13 
    1.14 Use of this software is subject to the terms of the Oculus license
    1.15 agreement provided at the time of installation or download, or which
    1.16 otherwise accompanies this software in either electronic or hard copy form.
    1.17 
    1.18 ************************************************************************************/
    1.19 
    1.20 #ifndef OVR_UTF8Util_h
    1.21 #define OVR_UTF8Util_h
    1.22 
    1.23 #include "OVR_Types.h"
    1.24 
    1.25 namespace OVR { namespace UTF8Util {
    1.26 
    1.27 //-----------------------------------------------------------------------------------
    1.28 
    1.29 // *** UTF8 string length and indexing.
    1.30 
    1.31 // Determines the length of UTF8 string in characters.
    1.32 // If source length is specified (in bytes), null 0 character is counted properly.
    1.33 SPInt    OVR_STDCALL GetLength(const char* putf8str, SPInt length = -1);
    1.34 
    1.35 // Gets a decoded UTF8 character at index; you can access up to the index returned
    1.36 // by GetLength. 0 will be returned for out of bounds access.
    1.37 UInt32   OVR_STDCALL GetCharAt(SPInt index, const char* putf8str, SPInt length = -1);
    1.38 
    1.39 // Converts UTF8 character index into byte offset.
    1.40 // -1 is returned if index was out of bounds.
    1.41 SPInt    OVR_STDCALL GetByteIndex(SPInt index, const char* putf8str, SPInt length = -1);
    1.42 
    1.43 
    1.44 // *** 16-bit Unicode string Encoding/Decoding routines.
    1.45 
    1.46 // Determines the number of bytes necessary to encode a string.
    1.47 // Does not count the terminating 0 (null) character.
    1.48 SPInt    OVR_STDCALL GetEncodeStringSize(const wchar_t* pchar, SPInt length = -1);
    1.49 
    1.50 // Encodes a unicode (UCS-2 only) string into a buffer. The size of buffer must be at
    1.51 // least GetEncodeStringSize() + 1.
    1.52 void     OVR_STDCALL EncodeString(char *pbuff, const wchar_t* pchar, SPInt length = -1);
    1.53 
    1.54 // Decode UTF8 into a wchar_t buffer. Must have GetLength()+1 characters available.
    1.55 // Characters over 0xFFFF are replaced with 0xFFFD.
    1.56 // Returns the length of resulting string (number of characters)
    1.57 UPInt    OVR_STDCALL DecodeString(wchar_t *pbuff, const char* putf8str, SPInt bytesLen = -1);
    1.58 
    1.59 
    1.60 // *** Individual character Encoding/Decoding.
    1.61 
    1.62 // Determined the number of bytes necessary to encode a UCS character.
    1.63 int      OVR_STDCALL GetEncodeCharSize(UInt32 ucsCharacter);
    1.64 
    1.65 // Encodes the given UCS character into the given UTF-8 buffer.
    1.66 // Writes the data starting at buffer[offset], and 
    1.67 // increments offset by the number of bytes written.
    1.68 // May write up to 6 bytes, so make sure there's room in the buffer
    1.69 void     OVR_STDCALL EncodeChar(char* pbuffer, SPInt* poffset, UInt32 ucsCharacter);
    1.70 
    1.71 // Return the next Unicode character in the UTF-8 encoded buffer.
    1.72 // Invalid UTF-8 sequences produce a U+FFFD character as output.
    1.73 // Advances *utf8_buffer past the character returned. Pointer advance
    1.74 // occurs even if the terminating 0 character is hit, since that allows
    1.75 // strings with middle '\0' characters to be supported.
    1.76 UInt32   OVR_STDCALL DecodeNextChar_Advance0(const char** putf8Buffer);
    1.77 
    1.78 // Safer version of DecodeNextChar, which doesn't advance pointer if
    1.79 // null character is hit.
    1.80 inline UInt32 DecodeNextChar(const char** putf8Buffer)
    1.81 {
    1.82     UInt32 ch = DecodeNextChar_Advance0(putf8Buffer);
    1.83     if (ch == 0)
    1.84         (*putf8Buffer)--;
    1.85     return ch;
    1.86 }
    1.87 
    1.88 
    1.89 }} // OVR::UTF8Util
    1.90 
    1.91 #endif
    1.92 \ No newline at end of file
    1.93 +/************************************************************************************
    1.94 +
    1.95 +PublicHeader:   OVR.h
    1.96 +Filename    :   OVR_UTF8Util.h
    1.97 +Content     :   UTF8 Unicode character encoding/decoding support
    1.98 +Created     :   September 19, 2012
    1.99 +Notes       : 
   1.100 +
   1.101 +Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
   1.102 +
   1.103 +Use of this software is subject to the terms of the Oculus license
   1.104 +agreement provided at the time of installation or download, or which
   1.105 +otherwise accompanies this software in either electronic or hard copy form.
   1.106 +
   1.107 +************************************************************************************/
   1.108 +
   1.109 +#ifndef OVR_UTF8Util_h
   1.110 +#define OVR_UTF8Util_h
   1.111 +
   1.112 +#include "OVR_Types.h"
   1.113 +
   1.114 +namespace OVR { namespace UTF8Util {
   1.115 +
   1.116 +//-----------------------------------------------------------------------------------
   1.117 +
   1.118 +// *** UTF8 string length and indexing.
   1.119 +
   1.120 +// Determines the length of UTF8 string in characters.
   1.121 +// If source length is specified (in bytes), null 0 character is counted properly.
   1.122 +SPInt    OVR_STDCALL GetLength(const char* putf8str, SPInt length = -1);
   1.123 +
   1.124 +// Gets a decoded UTF8 character at index; you can access up to the index returned
   1.125 +// by GetLength. 0 will be returned for out of bounds access.
   1.126 +UInt32   OVR_STDCALL GetCharAt(SPInt index, const char* putf8str, SPInt length = -1);
   1.127 +
   1.128 +// Converts UTF8 character index into byte offset.
   1.129 +// -1 is returned if index was out of bounds.
   1.130 +SPInt    OVR_STDCALL GetByteIndex(SPInt index, const char* putf8str, SPInt length = -1);
   1.131 +
   1.132 +
   1.133 +// *** 16-bit Unicode string Encoding/Decoding routines.
   1.134 +
   1.135 +// Determines the number of bytes necessary to encode a string.
   1.136 +// Does not count the terminating 0 (null) character.
   1.137 +SPInt    OVR_STDCALL GetEncodeStringSize(const wchar_t* pchar, SPInt length = -1);
   1.138 +
   1.139 +// Encodes a unicode (UCS-2 only) string into a buffer. The size of buffer must be at
   1.140 +// least GetEncodeStringSize() + 1.
   1.141 +void     OVR_STDCALL EncodeString(char *pbuff, const wchar_t* pchar, SPInt length = -1);
   1.142 +
   1.143 +// Decode UTF8 into a wchar_t buffer. Must have GetLength()+1 characters available.
   1.144 +// Characters over 0xFFFF are replaced with 0xFFFD.
   1.145 +// Returns the length of resulting string (number of characters)
   1.146 +UPInt    OVR_STDCALL DecodeString(wchar_t *pbuff, const char* putf8str, SPInt bytesLen = -1);
   1.147 +
   1.148 +
   1.149 +// *** Individual character Encoding/Decoding.
   1.150 +
   1.151 +// Determined the number of bytes necessary to encode a UCS character.
   1.152 +int      OVR_STDCALL GetEncodeCharSize(UInt32 ucsCharacter);
   1.153 +
   1.154 +// Encodes the given UCS character into the given UTF-8 buffer.
   1.155 +// Writes the data starting at buffer[offset], and 
   1.156 +// increments offset by the number of bytes written.
   1.157 +// May write up to 6 bytes, so make sure there's room in the buffer
   1.158 +void     OVR_STDCALL EncodeChar(char* pbuffer, SPInt* poffset, UInt32 ucsCharacter);
   1.159 +
   1.160 +// Return the next Unicode character in the UTF-8 encoded buffer.
   1.161 +// Invalid UTF-8 sequences produce a U+FFFD character as output.
   1.162 +// Advances *utf8_buffer past the character returned. Pointer advance
   1.163 +// occurs even if the terminating 0 character is hit, since that allows
   1.164 +// strings with middle '\0' characters to be supported.
   1.165 +UInt32   OVR_STDCALL DecodeNextChar_Advance0(const char** putf8Buffer);
   1.166 +
   1.167 +// Safer version of DecodeNextChar, which doesn't advance pointer if
   1.168 +// null character is hit.
   1.169 +inline UInt32 DecodeNextChar(const char** putf8Buffer)
   1.170 +{
   1.171 +    UInt32 ch = DecodeNextChar_Advance0(putf8Buffer);
   1.172 +    if (ch == 0)
   1.173 +        (*putf8Buffer)--;
   1.174 +    return ch;
   1.175 +}
   1.176 +
   1.177 +
   1.178 +}} // OVR::UTF8Util
   1.179 +
   1.180 +#endif