Plasma Engine  2.0
Loading...
Searching...
No Matches
UnicodeUtils.h
1#pragma once
2
3#ifndef PL_INCLUDING_BASICS_H
4# error "Please don't include UnicodeUtils.h directly, but instead include Foundation/Basics.h"
5#endif
6
7#include <Foundation/ThirdParty/utf8/utf8.h>
8
10class PL_FOUNDATION_DLL plUnicodeUtils
11{
12public:
14 template <typename T>
15 static constexpr T* GetMaxStringEnd();
16
17public:
19 static constexpr plUInt16 Utf16BomLE = 0xfeff;
20
22 static constexpr plUInt16 Utf16BomBE = 0xfffe;
23
25 static bool IsASCII(plUInt32 uiChar); // [tested]
26
28 static bool IsUtf8StartByte(char iByte); // [tested]
29
31 static bool IsUtf8ContinuationByte(char iByte); // [tested]
32
34 static plUInt32 GetUtf8SequenceLength(char iFirstByte); // [tested]
35
37 static plUInt32 ConvertUtf8ToUtf32(const char* pFirstChar); // [tested]
38
40 static plUInt32 GetSizeForCharacterInUtf8(plUInt32 uiCharacter); // [tested]
41
46 static plResult MoveToNextUtf8(const char*& ref_szUtf8, plUInt32 uiNumCharacters = 1); // [tested]
47
52 static plResult MoveToNextUtf8(const char*& ref_szUtf8, const char* szUtf8End, plUInt32 uiNumCharacters = 1); // [tested]
53
58 static plResult MoveToPriorUtf8(const char*& ref_szUtf8, const char* szUtf8Start, plUInt32 uiNumCharacters = 1); // [tested]
59
61 static bool IsValidUtf8(const char* szString, const char* szStringEnd = GetMaxStringEnd<char>());
62
66 static bool SkipUtf8Bom(const char*& ref_szUtf8); // [tested]
67
72 static bool SkipUtf16BomLE(const plUInt16*& ref_pUtf16); // [tested]
73
78 static bool SkipUtf16BomBE(const plUInt16*& ref_pUtf16); // [tested]
79
81 template <typename ByteIterator>
82 static plUInt32 DecodeUtf8ToUtf32(ByteIterator& ref_szUtf8Iterator); // [tested]
83
85 template <typename UInt16Iterator>
86 static bool IsUtf16Surrogate(UInt16Iterator& ref_szUtf16Iterator); // [tested]
87
89 template <typename UInt16Iterator>
90 static plUInt32 DecodeUtf16ToUtf32(UInt16Iterator& ref_szUtf16Iterator); // [tested]
91
93 template <typename WCharIterator>
94 static plUInt32 DecodeWCharToUtf32(WCharIterator& ref_szWCharIterator); // [tested]
95
97 template <typename ByteIterator>
98 static void EncodeUtf32ToUtf8(plUInt32 uiUtf32, ByteIterator& ref_szUtf8Output); // [tested]
99
101 template <typename UInt16Iterator>
102 static void EncodeUtf32ToUtf16(plUInt32 uiUtf32, UInt16Iterator& ref_szUtf16Output); // [tested]
103
105 template <typename WCharIterator>
106 static void EncodeUtf32ToWChar(plUInt32 uiUtf32, WCharIterator& ref_szWCharOutput); // [tested]
107
109 template <typename IntType, typename Container>
111 {
112 using InsertionType = IntType;
113
114 PL_ALWAYS_INLINE UtfInserter(Container* pContainer) { m_pContainer = pContainer; }
115 PL_ALWAYS_INLINE void operator++() {}
116 PL_ALWAYS_INLINE UtfInserter& operator++(int) { return *this; }
117 PL_ALWAYS_INLINE void operator=(IntType rhs) { m_pContainer->PushBack(rhs); }
118 PL_ALWAYS_INLINE UtfInserter& operator*() { return *this; }
119
120 Container* m_pContainer;
121 };
122
129 template <typename Container>
130 static bool RepairNonUtf8Text(const char* pStartData, const char* pEndData, Container& out_result);
131};
132
133#include <Foundation/Strings/Implementation/UnicodeUtils_inl.h>
Helper functions to work with Unicode.
Definition UnicodeUtils.h:11
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
[internal] Small helper class to append bytes to some arbitrary container. Used for Utf8 string build...
Definition UnicodeUtils.h:111