mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-13 19:49:36 +00:00
Refactoring, clean up shutdown path
This commit is contained in:
@@ -2,69 +2,59 @@
|
||||
#include "MacRoman.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
Boolean EqualString(const PLPasStr &string1, const PLPasStr &string2, Boolean caseSensitive, Boolean diacriticSensitive)
|
||||
{
|
||||
const size_t len = string1.Length();
|
||||
if (len != string2.Length())
|
||||
return PL_FALSE;
|
||||
|
||||
const uint8_t *chars1 = string1.UChars();
|
||||
const uint8_t *chars2 = string2.UChars();
|
||||
|
||||
if (caseSensitive)
|
||||
namespace StrCmp
|
||||
{
|
||||
int Compare(const PLPasStr &string1, const PLPasStr &string2)
|
||||
{
|
||||
// Case sensitive
|
||||
if (diacriticSensitive)
|
||||
{
|
||||
// Diacritic sensitive
|
||||
return memcmp(chars1, chars2, len) ? PL_FALSE : PL_TRUE;
|
||||
}
|
||||
const uint8_t *chars1 = string1.UChars();
|
||||
const uint8_t *chars2 = string2.UChars();
|
||||
|
||||
const size_t len1 = string1.Length();
|
||||
const size_t len2 = string1.Length();
|
||||
|
||||
const size_t shorterLen = std::min(len1, len2);
|
||||
|
||||
int memcmpResult = memcmp(chars1, chars2, shorterLen);
|
||||
|
||||
if (memcmpResult != 0)
|
||||
return memcmpResult;
|
||||
|
||||
if (len1 < len2)
|
||||
return -1;
|
||||
else if (len2 < len1)
|
||||
return 1;
|
||||
else
|
||||
{
|
||||
// Diacritic insensitive
|
||||
for (size_t i = 0; i < len; i++)
|
||||
{
|
||||
const uint8_t c1 = chars1[i];
|
||||
const uint8_t c2 = chars2[i];
|
||||
|
||||
if (PortabilityLayer::MacRoman::g_stripDiacritic[c1] != PortabilityLayer::MacRoman::g_stripDiacritic[c2])
|
||||
return PL_FALSE;
|
||||
}
|
||||
|
||||
return PL_TRUE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
|
||||
int CompareCaseInsensitive(const PLPasStr &string1, const PLPasStr &string2)
|
||||
{
|
||||
// Case insensitive
|
||||
if (diacriticSensitive)
|
||||
const uint8_t *chars1 = string1.UChars();
|
||||
const uint8_t *chars2 = string2.UChars();
|
||||
|
||||
const size_t len1 = string1.Length();
|
||||
const size_t len2 = string1.Length();
|
||||
|
||||
const size_t shorterLen = std::min(len1, len2);
|
||||
|
||||
for (size_t i = 0; i < shorterLen; i++)
|
||||
{
|
||||
// Diacritic sensitive
|
||||
for (size_t i = 0; i < len; i++)
|
||||
{
|
||||
const uint8_t c1 = chars1[i];
|
||||
const uint8_t c2 = chars2[i];
|
||||
const uint8_t c1 = PortabilityLayer::MacRoman::g_toLower[chars1[i]];
|
||||
const uint8_t c2 = PortabilityLayer::MacRoman::g_toLower[chars2[i]];
|
||||
|
||||
if (PortabilityLayer::MacRoman::g_toLower[c1] != PortabilityLayer::MacRoman::g_toLower[c2])
|
||||
return PL_FALSE;
|
||||
}
|
||||
|
||||
return PL_TRUE;
|
||||
if (c1 < c2)
|
||||
return -1;
|
||||
if (c2 < c1)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (len1 < len2)
|
||||
return -1;
|
||||
else if (len2 < len1)
|
||||
return 1;
|
||||
else
|
||||
{
|
||||
// Diacritic insensitive
|
||||
for (size_t i = 0; i < len; i++)
|
||||
{
|
||||
const uint8_t c1 = PortabilityLayer::MacRoman::g_stripDiacritic[chars1[i]];
|
||||
const uint8_t c2 = PortabilityLayer::MacRoman::g_stripDiacritic[chars2[i]];
|
||||
|
||||
if (PortabilityLayer::MacRoman::g_toLower[c1] != PortabilityLayer::MacRoman::g_toLower[c2])
|
||||
return PL_FALSE;
|
||||
}
|
||||
|
||||
return PL_TRUE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
#pragma once
|
||||
#ifndef __PL_STRINGCOMPARE_H__
|
||||
#define __PL_STRINGCOMPARE_H__
|
||||
|
||||
#include "PLCore.h"
|
||||
#include "PLPasStr.h"
|
||||
|
||||
Boolean EqualString(const PLPasStr &string1, const PLPasStr &string2, Boolean caseSensitive, Boolean diacriticSensitive);
|
||||
|
||||
#endif
|
||||
|
||||
namespace StrCmp
|
||||
{
|
||||
int CompareCaseInsensitive(const PLPasStr &string1, const PLPasStr &string2);
|
||||
int Compare(const PLPasStr &string1, const PLPasStr &string2);
|
||||
|
||||
inline bool EqualCaseInsensitive(const PLPasStr &string1, const PLPasStr &string2)
|
||||
{
|
||||
return CompareCaseInsensitive(string1, string2) == 0;
|
||||
}
|
||||
|
||||
inline bool Equal(const PLPasStr &string1, const PLPasStr &string2)
|
||||
{
|
||||
return Compare(string1, string2) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,8 @@ namespace PortabilityLayer
|
||||
WindowImpl *m_windowStackBottom;
|
||||
|
||||
static WindowManagerImpl ms_instance;
|
||||
static Window ms_putInFront;
|
||||
|
||||
static uint8_t ms_putInFrontSentinel;
|
||||
};
|
||||
|
||||
WindowImpl::WindowImpl()
|
||||
@@ -335,7 +336,7 @@ namespace PortabilityLayer
|
||||
|
||||
Window *WindowManagerImpl::GetPutInFrontSentinel() const
|
||||
{
|
||||
return &ms_putInFront;
|
||||
return reinterpret_cast<Window*>(&ms_putInFrontSentinel);
|
||||
}
|
||||
|
||||
void WindowManagerImpl::RenderWindow(WindowImpl *window, IGpDisplayDriver *displayDriver)
|
||||
@@ -356,7 +357,7 @@ namespace PortabilityLayer
|
||||
}
|
||||
|
||||
WindowManagerImpl WindowManagerImpl::ms_instance;
|
||||
Window WindowManagerImpl::ms_putInFront;
|
||||
uint8_t WindowManagerImpl::ms_putInFrontSentinel;
|
||||
|
||||
WindowManager *WindowManager::GetInstance()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user