UTF refactor to eliminate duplicated code outside of PL

This commit is contained in:
elasota
2021-04-27 09:54:01 -04:00
parent 07df94fb00
commit 2cd4e4f178
19 changed files with 311 additions and 389 deletions

View File

@@ -5,8 +5,7 @@
#include "IGpClipboardContents.h" #include "IGpClipboardContents.h"
#include "UTF16.h" #include "GpUnicode.h"
#include "UTF8.h"
#include <assert.h> #include <assert.h>
#include <vector> #include <vector>

View File

@@ -8,6 +8,7 @@
#include "GpRingBuffer.h" #include "GpRingBuffer.h"
#include "GpInputDriver_SDL_Gamepad.h" #include "GpInputDriver_SDL_Gamepad.h"
#include "GpSDL.h" #include "GpSDL.h"
#include "GpUnicode.h"
#include "IGpCursor.h" #include "IGpCursor.h"
#include "IGpDisplayDriverSurface.h" #include "IGpDisplayDriverSurface.h"
#include "IGpLogDriver.h" #include "IGpLogDriver.h"
@@ -52,68 +53,6 @@ struct GpDisplayDriver_SDL_GL2_Prefs
bool m_isFullScreen; bool m_isFullScreen;
}; };
namespace DeleteMe
{
bool DecodeCodePoint(const uint8_t *characters, size_t availableCharacters, size_t &outCharactersDigested, uint32_t &outCodePoint)
{
if (availableCharacters <= 0)
return false;
if ((characters[0] & 0x80) == 0x00)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
size_t sz = 0;
uint32_t codePoint = 0;
uint32_t minCodePoint = 0;
if ((characters[0] & 0xe0) == 0xc0)
{
sz = 2;
minCodePoint = 0x80;
codePoint = (characters[0] & 0x1f);
}
else if ((characters[0] & 0xf0) == 0xe0)
{
sz = 3;
minCodePoint = 0x800;
codePoint = (characters[0] & 0x0f);
}
else if ((characters[0] & 0xf8) == 0xf0)
{
sz = 4;
minCodePoint = 0x10000;
codePoint = (characters[0] & 0x07);
}
else
return false;
if (availableCharacters < sz)
return false;
for (size_t auxByte = 1; auxByte < sz; auxByte++)
{
if ((characters[auxByte] & 0xc0) != 0x80)
return false;
codePoint = (codePoint << 6) | (characters[auxByte] & 0x3f);
}
if (codePoint < minCodePoint || codePoint > 0x10ffff)
return false;
if (codePoint >= 0xd800 && codePoint <= 0xdfff)
return false;
outCodePoint = codePoint;
outCharactersDigested = sz;
return true;
}
}
namespace GpBinarizedShaders namespace GpBinarizedShaders
{ {
extern const char *g_drawQuadV_GL2; extern const char *g_drawQuadV_GL2;
@@ -2041,7 +1980,7 @@ void GpDisplayDriver_SDL_GL2::TranslateSDLMessage(const SDL_Event *msg, IGpVOSEv
{ {
uint32_t codePoint; uint32_t codePoint;
size_t numDigested; size_t numDigested;
DeleteMe::DecodeCodePoint(reinterpret_cast<const uint8_t*>(teEvt->text) + parseOffset, lenUTF8 - parseOffset, numDigested, codePoint); GpUnicode::UTF8::Decode(reinterpret_cast<const uint8_t*>(teEvt->text) + parseOffset, lenUTF8 - parseOffset, numDigested, codePoint);
parseOffset += numDigested; parseOffset += numDigested;

View File

@@ -108,7 +108,6 @@ add_library(PortabilityLayer STATIC
PortabilityLayer/SimpleGraphic.cpp PortabilityLayer/SimpleGraphic.cpp
PortabilityLayer/TextPlacer.cpp PortabilityLayer/TextPlacer.cpp
PortabilityLayer/UTF8.cpp PortabilityLayer/UTF8.cpp
PortabilityLayer/UTF16.cpp
PortabilityLayer/WindowDef.cpp PortabilityLayer/WindowDef.cpp
PortabilityLayer/WindowManager.cpp PortabilityLayer/WindowManager.cpp
PortabilityLayer/WorkerThread.cpp PortabilityLayer/WorkerThread.cpp

165
GpCommon/GpUnicode.h Normal file
View File

@@ -0,0 +1,165 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
namespace GpUnicode
{
namespace UTF8
{
static const unsigned int kMaxEncodedBytes = 4;
inline bool Decode(const uint8_t *characters, size_t availableCharacters, size_t &outCharactersDigested, uint32_t &outCodePoint)
{
if (availableCharacters <= 0)
return false;
if ((characters[0] & 0x80) == 0x00)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
size_t sz = 0;
uint32_t codePoint = 0;
uint32_t minCodePoint = 0;
if ((characters[0] & 0xe0) == 0xc0)
{
sz = 2;
minCodePoint = 0x80;
codePoint = (characters[0] & 0x1f);
}
else if ((characters[0] & 0xf0) == 0xe0)
{
sz = 3;
minCodePoint = 0x800;
codePoint = (characters[0] & 0x0f);
}
else if ((characters[0] & 0xf8) == 0xf0)
{
sz = 4;
minCodePoint = 0x10000;
codePoint = (characters[0] & 0x07);
}
else
return false;
if (availableCharacters < sz)
return false;
for (size_t auxByte = 1; auxByte < sz; auxByte++)
{
if ((characters[auxByte] & 0xc0) != 0x80)
return false;
codePoint = (codePoint << 6) | (characters[auxByte] & 0x3f);
}
if (codePoint < minCodePoint || codePoint > 0x10ffff)
return false;
if (codePoint >= 0xd800 && codePoint <= 0xdfff)
return false;
outCodePoint = codePoint;
outCharactersDigested = sz;
return true;
}
inline void Encode(uint8_t *characters, size_t &outCharactersEmitted, uint32_t codePoint)
{
codePoint &= 0x1fffff;
uint8_t signalBits = 0;
size_t numBytes = 0;
if (codePoint < 0x0080)
{
numBytes = 1;
signalBits = 0;
}
else if (codePoint < 0x0800)
{
numBytes = 2;
signalBits = 0xc0;
}
else if (codePoint < 0x10000)
{
numBytes = 3;
signalBits = 0xe0;
}
else
{
numBytes = 4;
signalBits = 0xf0;
}
characters[0] = static_cast<uint8_t>((codePoint >> (6 * (numBytes - 1))) | signalBits);
for (size_t i = 1; i < numBytes; i++)
{
const uint32_t isolate = ((codePoint >> (6 * (numBytes - 1 - i))) & 0x3f) | 0x80;
characters[i] = static_cast<uint8_t>(isolate);
}
outCharactersEmitted = numBytes;
}
}
namespace UTF16
{
inline bool Decode(const uint16_t *characters, size_t availableCharacters, size_t &outCharactersDigested, uint32_t &outCodePoint)
{
if (availableCharacters <= 0)
return false;
if ((characters[0] & 0xff80) == 0x00)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
if (characters[0] <= 0xd7ff || characters[0] >= 0xe000)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
// Surrogate pair
if (characters[0] >= 0xdc00 || availableCharacters < 2)
return false;
if (characters[1] < 0xdc00 || characters[1] >= 0xe000)
return false;
uint16_t highBits = (characters[0] & 0x3ff);
uint16_t lowBits = (characters[1] & 0x3ff);
outCharactersDigested = 2;
outCodePoint = (highBits << 10) + lowBits + 0x10000;
return true;
}
inline void Encode(uint16_t *characters, size_t &outCharactersEmitted, uint32_t codePoint)
{
if (codePoint <= 0xd7ff || codePoint >= 0xe000)
{
outCharactersEmitted = 1;
characters[0] = static_cast<uint16_t>(codePoint);
return;
}
uint32_t codePointBits = (codePoint - 0x10000) & 0xfffff;
uint16_t lowBits = (codePointBits & 0x3ff);
uint16_t highBits = ((codePointBits >> 10) & 0x3ff);
outCharactersEmitted = 2;
characters[0] = (0xd800 + highBits);
characters[1] = (0xdc00 + lowBits);
}
}
}

View File

@@ -2,7 +2,7 @@
#include "PLCore.h" #include "PLCore.h"
#include "PLBigEndian.h" #include "PLBigEndian.h"
#include "MacRomanConversion.h" #include "MacRomanConversion.h"
#include "UTF8.h" #include "GpUnicode.h"
#include "WindowsUnicodeToolShim.h" #include "WindowsUnicodeToolShim.h"
#include <vector> #include <vector>
@@ -1124,7 +1124,7 @@ void PatchVisitor::VisitLPStr(uint8_t &length, uint8_t *chars, int capacity)
{ {
uint32_t codePoint = 0; uint32_t codePoint = 0;
size_t charsDigested = 0; size_t charsDigested = 0;
if (!PortabilityLayer::UTF8Processor::DecodeCodePoint(replacementUTF8, rLen, charsDigested, codePoint)) if (!GpUnicode::UTF8::Decode(replacementUTF8, rLen, charsDigested, codePoint))
break; break;
rLen -= charsDigested; rLen -= charsDigested;
@@ -1382,9 +1382,9 @@ bool PatchVisitor::DecodeQuotedString(const std::string &scopeStr, size_t startP
} }
const uint16_t unicodeCodePoint = (nibbles[0] << 12) + (nibbles[1] << 8) + (nibbles[2] << 4) + nibbles[3]; const uint16_t unicodeCodePoint = (nibbles[0] << 12) + (nibbles[1] << 8) + (nibbles[2] << 4) + nibbles[3];
uint8_t encoded[PortabilityLayer::UTF8Processor::kMaxEncodedBytes]; uint8_t encoded[GpUnicode::UTF8::kMaxEncodedBytes];
size_t emitted = 0; size_t emitted = 0;
PortabilityLayer::UTF8Processor::EncodeCodePoint(encoded, emitted, unicodeCodePoint); GpUnicode::UTF8::Encode(encoded, emitted, unicodeCodePoint);
for (size_t ei = 0; ei < emitted; ei++) for (size_t ei = 0; ei < emitted; ei++)
decoded.push_back(static_cast<char>(encoded[ei])); decoded.push_back(static_cast<char>(encoded[ei]));

View File

@@ -46,7 +46,7 @@
#include "PLTimeTaggedVOSEvent.h" #include "PLTimeTaggedVOSEvent.h"
#include "PLWidgets.h" #include "PLWidgets.h"
#include "UTF8.h" #include "GpUnicode.h"
#include <assert.h> #include <assert.h>
#include <algorithm> #include <algorithm>
@@ -691,12 +691,12 @@ PLClipboardContentsText *PLClipboardContentsText::CreateFromMacRomanStr(const ui
for (size_t i = 0; i < length; i++) for (size_t i = 0; i < length; i++)
{ {
uint8_t utf8Bytes[PortabilityLayer::UTF8Processor::kMaxEncodedBytes]; uint8_t utf8Bytes[GpUnicode::UTF8::kMaxEncodedBytes];
uint16_t codePoint = MacRoman::ToUnicode(chars[i]); uint16_t codePoint = MacRoman::ToUnicode(chars[i]);
size_t numBytesEmitted = 0; size_t numBytesEmitted = 0;
PortabilityLayer::UTF8Processor::EncodeCodePoint(utf8Bytes, numBytesEmitted, codePoint); GpUnicode::UTF8::Encode(utf8Bytes, numBytesEmitted, codePoint);
numUTF8Bytes += numBytesEmitted; numUTF8Bytes += numBytesEmitted;
} }
@@ -715,7 +715,7 @@ PLClipboardContentsText *PLClipboardContentsText::CreateFromMacRomanStr(const ui
uint16_t codePoint = MacRoman::ToUnicode(chars[i]); uint16_t codePoint = MacRoman::ToUnicode(chars[i]);
size_t numBytesEmitted = 0; size_t numBytesEmitted = 0;
PortabilityLayer::UTF8Processor::EncodeCodePoint(utf8Bytes + numUTF8Bytes, numBytesEmitted, codePoint); GpUnicode::UTF8::Encode(utf8Bytes + numUTF8Bytes, numBytesEmitted, codePoint);
numUTF8Bytes += numBytesEmitted; numUTF8Bytes += numBytesEmitted;
} }

View File

@@ -12,7 +12,7 @@
#include "ResolveCachingColor.h" #include "ResolveCachingColor.h"
#include "Rect2i.h" #include "Rect2i.h"
#include "TextPlacer.h" #include "TextPlacer.h"
#include "UTF8.h" #include "GpUnicode.h"
#include "PLDrivers.h" #include "PLDrivers.h"
#include "PLKeyEncoding.h" #include "PLKeyEncoding.h"
@@ -721,7 +721,7 @@ namespace PortabilityLayer
{ {
uint32_t codePoint = 0; uint32_t codePoint = 0;
size_t numDigested = 0; size_t numDigested = 0;
if (!UTF8Processor::DecodeCodePoint(utf8Bytes + i, utf8Size - i, numDigested, codePoint)) if (!GpUnicode::UTF8::Decode(utf8Bytes + i, utf8Size - i, numDigested, codePoint))
{ {
clipboardContents->Destroy(); clipboardContents->Destroy();
return; return;
@@ -745,7 +745,7 @@ namespace PortabilityLayer
{ {
uint32_t codePoint = 0; uint32_t codePoint = 0;
size_t numDigested = 0; size_t numDigested = 0;
if (!UTF8Processor::DecodeCodePoint(utf8Bytes + i, utf8Size - i, numDigested, codePoint)) if (!GpUnicode::UTF8::Decode(utf8Bytes + i, utf8Size - i, numDigested, codePoint))
{ {
clipboardContents->Destroy(); clipboardContents->Destroy();
return; return;

View File

@@ -157,7 +157,6 @@
<ClInclude Include="ResolveCachingColor.h" /> <ClInclude Include="ResolveCachingColor.h" />
<ClInclude Include="WorkerThread.h" /> <ClInclude Include="WorkerThread.h" />
<ClInclude Include="TextPlacer.h" /> <ClInclude Include="TextPlacer.h" />
<ClInclude Include="UTF16.h" />
<ClInclude Include="UTF8.h" /> <ClInclude Include="UTF8.h" />
<ClInclude Include="ZipFileProxy.h" /> <ClInclude Include="ZipFileProxy.h" />
<ClInclude Include="SimpleImage.h" /> <ClInclude Include="SimpleImage.h" />
@@ -302,7 +301,6 @@
<ClCompile Include="SimpleGraphic.cpp" /> <ClCompile Include="SimpleGraphic.cpp" />
<ClCompile Include="PLHandle.cpp" /> <ClCompile Include="PLHandle.cpp" />
<ClCompile Include="TextPlacer.cpp" /> <ClCompile Include="TextPlacer.cpp" />
<ClCompile Include="UTF16.cpp" />
<ClCompile Include="UTF8.cpp" /> <ClCompile Include="UTF8.cpp" />
<ClCompile Include="WindowDef.cpp" /> <ClCompile Include="WindowDef.cpp" />
<ClCompile Include="WindowManager.cpp" /> <ClCompile Include="WindowManager.cpp" />

View File

@@ -399,9 +399,6 @@
<ClInclude Include="AppEventHandler.h"> <ClInclude Include="AppEventHandler.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="UTF16.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLButtonWidget.h"> <ClInclude Include="PLButtonWidget.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@@ -671,9 +668,6 @@
<ClCompile Include="TextPlacer.cpp"> <ClCompile Include="TextPlacer.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="UTF16.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLButtonWidget.cpp"> <ClCompile Include="PLButtonWidget.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>

View File

@@ -78,7 +78,6 @@
#include "SimpleGraphic.cpp" #include "SimpleGraphic.cpp"
#include "TextPlacer.cpp" #include "TextPlacer.cpp"
#include "UTF8.cpp" #include "UTF8.cpp"
#include "UTF16.cpp"
#include "WindowDef.cpp" #include "WindowDef.cpp"
#include "WindowManager.cpp" #include "WindowManager.cpp"
#include "WorkerThread.cpp" #include "WorkerThread.cpp"

View File

@@ -1,57 +0,0 @@
#include "UTF16.h"
namespace PortabilityLayer
{
bool UTF16Processor::DecodeCodePoint(const uint16_t *characters, size_t availableCharacters, size_t &outCharactersDigested, uint32_t &outCodePoint)
{
if (availableCharacters <= 0)
return false;
if ((characters[0] & 0xff80) == 0x00)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
if (characters[0] <= 0xd7ff || characters[0] >= 0xe000)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
// Surrogate pair
if (characters[0] >= 0xdc00 || availableCharacters < 2)
return false;
if (characters[1] < 0xdc00 || characters[1] >= 0xe000)
return false;
uint16_t highBits = (characters[0] & 0x3ff);
uint16_t lowBits = (characters[1] & 0x3ff);
outCharactersDigested = 2;
outCodePoint = (highBits << 10) + lowBits + 0x10000;
return true;
}
void UTF16Processor::EncodeCodePoint(uint16_t *characters, size_t &outCharactersEmitted, uint32_t codePoint)
{
if (codePoint <= 0xd7ff || codePoint >= 0xe000)
{
outCharactersEmitted = 1;
characters[0] = static_cast<uint16_t>(codePoint);
return;
}
uint32_t codePointBits = (codePoint - 0x10000) & 0xfffff;
uint16_t lowBits = (codePointBits & 0x3ff);
uint16_t highBits = ((codePointBits >> 10) & 0x3ff);
outCharactersEmitted = 2;
characters[0] = (0xd800 + highBits);
characters[1] = (0xdc00 + lowBits);
}
}

View File

@@ -1,14 +0,0 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
namespace PortabilityLayer
{
class UTF16Processor
{
public:
static bool DecodeCodePoint(const uint16_t *characters, size_t availableCharacters, size_t &outCharactersDigested, uint32_t &outCodePoint);
static void EncodeCodePoint(uint16_t *characters, size_t &outCharactersEmitted, uint32_t codePoint);
};
}

View File

@@ -1,105 +1,9 @@
#include "UTF8.h" #include "UTF8.h"
#include "GpUnicode.h"
#include "MacRomanConversion.h" #include "MacRomanConversion.h"
namespace PortabilityLayer namespace PortabilityLayer
{ {
bool UTF8Processor::DecodeCodePoint(const uint8_t *characters, size_t availableCharacters, size_t &outCharactersDigested, uint32_t &outCodePoint)
{
if (availableCharacters <= 0)
return false;
if ((characters[0] & 0x80) == 0x00)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
size_t sz = 0;
uint32_t codePoint = 0;
uint32_t minCodePoint = 0;
if ((characters[0] & 0xe0) == 0xc0)
{
sz = 2;
minCodePoint = 0x80;
codePoint = (characters[0] & 0x1f);
}
else if ((characters[0] & 0xf0) == 0xe0)
{
sz = 3;
minCodePoint = 0x800;
codePoint = (characters[0] & 0x0f);
}
else if ((characters[0] & 0xf8) == 0xf0)
{
sz = 4;
minCodePoint = 0x10000;
codePoint = (characters[0] & 0x07);
}
else
return false;
if (availableCharacters < sz)
return false;
for (size_t auxByte = 1; auxByte < sz; auxByte++)
{
if ((characters[auxByte] & 0xc0) != 0x80)
return false;
codePoint = (codePoint << 6) | (characters[auxByte] & 0x3f);
}
if (codePoint < minCodePoint || codePoint > 0x10ffff)
return false;
if (codePoint >= 0xd800 && codePoint <= 0xdfff)
return false;
outCodePoint = codePoint;
outCharactersDigested = sz;
return true;
}
void UTF8Processor::EncodeCodePoint(uint8_t *characters, size_t &outCharactersEmitted, uint32_t codePoint)
{
codePoint &= 0x1fffff;
uint8_t signalBits = 0;
size_t numBytes = 0;
if (codePoint < 0x0080)
{
numBytes = 1;
signalBits = 0;
}
else if (codePoint < 0x0800)
{
numBytes = 2;
signalBits = 0xc0;
}
else if (codePoint < 0x10000)
{
numBytes = 3;
signalBits = 0xe0;
}
else
{
numBytes = 4;
signalBits = 0xf0;
}
characters[0] = static_cast<uint8_t>((codePoint >> (6 * (numBytes - 1))) | signalBits);
for (size_t i = 1; i < numBytes; i++)
{
const uint32_t isolate = ((codePoint >> (6 * (numBytes - 1 - i))) & 0x3f) | 0x80;
characters[i] = static_cast<uint8_t>(isolate);
}
outCharactersEmitted = numBytes;
}
bool UTF8Processor::DecodeToMacRomanPascalStr(const uint8_t *inChars, size_t inSize, uint8_t *outChars, size_t maxOutSize, size_t &outSizeRef) bool UTF8Processor::DecodeToMacRomanPascalStr(const uint8_t *inChars, size_t inSize, uint8_t *outChars, size_t maxOutSize, size_t &outSizeRef)
{ {
size_t outSize = 0; size_t outSize = 0;
@@ -107,7 +11,7 @@ namespace PortabilityLayer
{ {
size_t digestedChars = 0; size_t digestedChars = 0;
uint32_t codePoint = 0; uint32_t codePoint = 0;
if (!DecodeCodePoint(inChars, inSize, digestedChars, codePoint)) if (!GpUnicode::UTF8::Decode(inChars, inSize, digestedChars, codePoint))
return false; return false;
inChars += digestedChars; inChars += digestedChars;
@@ -122,10 +26,10 @@ namespace PortabilityLayer
{ {
for (uint16_t c = 0x80; c <= 0xff; c++) for (uint16_t c = 0x80; c <= 0xff; c++)
{ {
uint16_t decodedCP = MacRoman::ToUnicode(c); uint16_t decodedCP = MacRoman::ToUnicode(static_cast<uint8_t>(c));
if (decodedCP == codePoint) if (decodedCP == codePoint)
{ {
macRomanChar = c; macRomanChar = static_cast<uint8_t>(c);
break; break;
} }
} }

View File

@@ -8,11 +8,6 @@ namespace PortabilityLayer
class UTF8Processor class UTF8Processor
{ {
public: public:
static bool DecodeCodePoint(const uint8_t *characters, size_t availableCharacters, size_t &outCharactersDigested, uint32_t &outCodePoint);
static void EncodeCodePoint(uint8_t *characters, size_t &outCharactersEmitted, uint32_t codePoint);
static bool DecodeToMacRomanPascalStr(const uint8_t *inChars, size_t inSize, uint8_t *outChars, size_t maxOutSize, size_t &outSize); static bool DecodeToMacRomanPascalStr(const uint8_t *inChars, size_t inSize, uint8_t *outChars, size_t maxOutSize, size_t &outSize);
static const unsigned int kMaxEncodedBytes = 4;
}; };
} }

View File

@@ -1,7 +1,6 @@
#include <string> #include <string>
#include "UTF8.h" #include "GpUnicode.h"
#include "UTF16.h"
#include <Windows.h> #include <Windows.h>
#include <vector> #include <vector>
@@ -20,13 +19,13 @@ static std::string ConvertWStringToUTF8(const wchar_t *str)
size_t charsDigested = 0; size_t charsDigested = 0;
uint32_t codePoint = 0; uint32_t codePoint = 0;
uint8_t asUTF8[4]; uint8_t asUTF8[4];
if (!PortabilityLayer::UTF16Processor::DecodeCodePoint(reinterpret_cast<const uint16_t*>(str) + i, strLength - i, charsDigested, codePoint)) if (!GpUnicode::UTF16::Decode(reinterpret_cast<const uint16_t*>(str) + i, strLength - i, charsDigested, codePoint))
return ""; return "";
i += charsDigested; i += charsDigested;
size_t bytesEmitted = 0; size_t bytesEmitted = 0;
PortabilityLayer::UTF8Processor::EncodeCodePoint(asUTF8, bytesEmitted, codePoint); GpUnicode::UTF8::Encode(asUTF8, bytesEmitted, codePoint);
result.append(reinterpret_cast<const char*>(asUTF8), bytesEmitted); result.append(reinterpret_cast<const char*>(asUTF8), bytesEmitted);
} }
@@ -45,13 +44,13 @@ static std::wstring ConvertUTF8ToWString(const char *str)
size_t charsDigested = 0; size_t charsDigested = 0;
uint32_t codePoint = 0; uint32_t codePoint = 0;
uint16_t asUTF16[4]; uint16_t asUTF16[4];
if (!PortabilityLayer::UTF8Processor::DecodeCodePoint(reinterpret_cast<const uint8_t*>(str) + i, strLength - i, charsDigested, codePoint)) if (!GpUnicode::UTF8::Decode(reinterpret_cast<const uint8_t*>(str) + i, strLength - i, charsDigested, codePoint))
return L""; return L"";
i += charsDigested; i += charsDigested;
size_t codePointsEmitted = 0; size_t codePointsEmitted = 0;
PortabilityLayer::UTF16Processor::EncodeCodePoint(asUTF16, codePointsEmitted, codePoint); GpUnicode::UTF16::Encode(asUTF16, codePointsEmitted, codePoint);
result.append(reinterpret_cast<const wchar_t*>(asUTF16), codePointsEmitted); result.append(reinterpret_cast<const wchar_t*>(asUTF16), codePointsEmitted);
} }

View File

@@ -41,6 +41,7 @@
<Import Project="..\PortabilityLayer.props" /> <Import Project="..\PortabilityLayer.props" />
<Import Project="..\Common.props" /> <Import Project="..\Common.props" />
<Import Project="..\Debug.props" /> <Import Project="..\Debug.props" />
<Import Project="..\GpCommon.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -48,6 +49,7 @@
<Import Project="..\PortabilityLayer.props" /> <Import Project="..\PortabilityLayer.props" />
<Import Project="..\Common.props" /> <Import Project="..\Common.props" />
<Import Project="..\Release.props" /> <Import Project="..\Release.props" />
<Import Project="..\GpCommon.props" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup /> <PropertyGroup />

View File

@@ -14,6 +14,7 @@
#include "UTF8.h" #include "UTF8.h"
#include "ZipFile.h" #include "ZipFile.h"
#include "WaveFormat.h" #include "WaveFormat.h"
#include "GpUnicode.h"
#include "zlib.h" #include "zlib.h"
@@ -116,7 +117,7 @@ void AppendUTF8(std::vector<uint8_t> &array, uint32_t codePoint)
uint8_t bytes[5]; uint8_t bytes[5];
size_t sz; size_t sz;
PortabilityLayer::UTF8Processor::EncodeCodePoint(bytes, sz, codePoint); GpUnicode::UTF8::Encode(bytes, sz, codePoint);
for (size_t i = 0; i < sz; i++) for (size_t i = 0; i < sz; i++)
array.push_back(bytes[i]); array.push_back(bytes[i]);
} }

View File

@@ -1,7 +1,7 @@
#include "StringCommon.h" #include "StringCommon.h"
#include "MacRomanConversion.h" #include "MacRomanConversion.h"
#include "UTF8.h" #include "GpUnicode.h"
void StringCommon::ConvertMacRomanFileName(std::vector<uint8_t> &utf8FileName, const uint8_t *macRomanName, size_t macRomanLength) void StringCommon::ConvertMacRomanFileName(std::vector<uint8_t> &utf8FileName, const uint8_t *macRomanName, size_t macRomanLength)
{ {
@@ -9,7 +9,7 @@ void StringCommon::ConvertMacRomanFileName(std::vector<uint8_t> &utf8FileName, c
{ {
uint8_t bytes[8]; uint8_t bytes[8];
size_t bytesEmitted; size_t bytesEmitted;
PortabilityLayer::UTF8Processor::EncodeCodePoint(bytes, bytesEmitted, MacRoman::ToUnicode(macRomanName[i])); GpUnicode::UTF8::Encode(bytes, bytesEmitted, MacRoman::ToUnicode(macRomanName[i]));
for (size_t bi = 0; bi < bytesEmitted; bi++) for (size_t bi = 0; bi < bytesEmitted; bi++)
utf8FileName.push_back(bytes[bi]); utf8FileName.push_back(bytes[bi]);

View File

@@ -7,8 +7,7 @@
#include "CompactProParser.h" #include "CompactProParser.h"
#include "CFileStream.h" #include "CFileStream.h"
#include "UTF8.h" #include "GpUnicode.h"
#include "UTF16.h"
#include "ArchiveDescription.h" #include "ArchiveDescription.h"
#include "IDecompressor.h" #include "IDecompressor.h"