mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 14:53:52 +00:00
Add unpacktool
This commit is contained in:
@@ -231,6 +231,7 @@
|
||||
<ClInclude Include="PLUnalignedPtr.h" />
|
||||
<ClInclude Include="PLWidgets.h" />
|
||||
<ClInclude Include="TextPlacer.h" />
|
||||
<ClInclude Include="UTF16.h" />
|
||||
<ClInclude Include="UTF8.h" />
|
||||
<ClInclude Include="ZipFileProxy.h" />
|
||||
<ClInclude Include="SimpleImage.h" />
|
||||
@@ -388,6 +389,7 @@
|
||||
<ClCompile Include="SimpleGraphic.cpp" />
|
||||
<ClCompile Include="PLHandle.cpp" />
|
||||
<ClCompile Include="TextPlacer.cpp" />
|
||||
<ClCompile Include="UTF16.cpp" />
|
||||
<ClCompile Include="UTF8.cpp" />
|
||||
<ClCompile Include="WindowDef.cpp" />
|
||||
<ClCompile Include="WindowManager.cpp" />
|
||||
|
@@ -486,6 +486,9 @@
|
||||
<ClInclude Include="AppEventHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="UTF16.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CFileStream.cpp">
|
||||
@@ -764,5 +767,8 @@
|
||||
<ClCompile Include="AppEventHandler.cpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="UTF16.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
57
PortabilityLayer/UTF16.cpp
Normal file
57
PortabilityLayer/UTF16.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#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);
|
||||
}
|
||||
}
|
13
PortabilityLayer/UTF16.h
Normal file
13
PortabilityLayer/UTF16.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.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);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user