gwnavruntime/kernel/SF_UTF8Util.h Source File

SF_UTF8Util.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 /**************************************************************************
8 
9 PublicHeader: None
10 Filename : KY_UTF8Util.h
11 Content : UTF8 Unicode character encoding/decoding support
12 Created : June 27, 2005
13 Authors :
14 
15 **************************************************************************/
16 
17 #ifndef INC_KY_Kernel_UTF8Util_H
18 #define INC_KY_Kernel_UTF8Util_H
19 
21 
22 namespace Kaim {
23 
24 // ***** UTF8 Support utility classes
25 
26 namespace UTF8Util
27 {
28 
29  // *** UTF8 string length and indexing.
30 
31  // Determines the length of UTF8 string in characters.
32  // If source length is specified (in bytes), null 0 character is counted properly.
33  SPInt KY_STDCALL GetLength(const char* putf8str, SPInt length = -1);
34 
35  // Gets a decoded UTF8 character at index; you can access up to the index returned
36  // by GetLength. 0 will be returned for out of bounds access.
37  UInt32 KY_STDCALL GetCharAt(SPInt index, const char* putf8str, SPInt length = -1);
38 
39  // Converts UTF8 character index into byte offset.
40  // -1 is returned if index was out of bounds.
41  SPInt KY_STDCALL GetByteIndex(SPInt index, const char* putf8str, SPInt length = -1);
42 
43 
44  // *** 16-bit Unicode string Encoding/Decoding routines.
45 
46  // Determines the number of bytes necessary to encode a string.
47  // Does not count the terminating 0 (null) character.
48  SPInt KY_STDCALL GetEncodeStringSize(const wchar_t* pchar, SPInt length = -1);
49 
50  // Encodes a unicode (UCS-2 only) string into a buffer. The size of buffer must be at
51  // least GetEncodeStringSize() + 1.
52  void KY_STDCALL EncodeString(char *pbuff, const wchar_t* pchar, SPInt length = -1);
53 
54  // Decode UTF8 into a wchar_t buffer. Must have GetLength()+1 characters available.
55  // Characters over 0xFFFF are replaced with 0xFFFD.
56  // Returns the length of resulting string (number of characters)
57  UPInt KY_STDCALL DecodeString(wchar_t *pbuff, const char* putf8str, SPInt bytesLen = -1);
58 
59 
60  // *** Individual character Encoding/Decoding.
61 
62  // Determined the number of bytes necessary to encode a UCS character.
63  int KY_STDCALL GetEncodeCharSize(UInt32 ucsCharacter);
64 
65  // Encodes the given UCS character into the given UTF-8 buffer.
66  // Writes the data starting at buffer[offset], and
67  // increments offset by the number of bytes written.
68  // May write up to 6 bytes, so make sure there's room in the buffer
69  void KY_STDCALL EncodeChar(char* pbuffer, SPInt* poffset, UInt32 ucsCharacter);
70 
71  // Return the next Unicode character in the UTF-8 encoded buffer.
72  // Invalid UTF-8 sequences produce a U+FFFD character as output.
73  // Advances *utf8_buffer past the character returned. Pointer advance
74  // occurs even if the terminating 0 character is hit, since that allows
75  // strings with middle '\0' characters to be supported.
76  UInt32 KY_STDCALL DecodeNextChar_Advance0(const char** putf8Buffer);
77 
78  // Safer version of DecodeNextChar, which doesn't advance pointer if
79  // null character is hit.
80  inline UInt32 DecodeNextChar(const char** putf8Buffer)
81  {
82  UInt32 ch = DecodeNextChar_Advance0(putf8Buffer);
83  if (ch == 0)
84  (*putf8Buffer)--;
85  return ch;
86  }
87 };
88 
89 } // Scaleform
90 
91 #endif
92 
Definition: gamekitcrowddispersion.h:20