OpenBarnyard
 
Loading...
Searching...
No Matches
Platform_Win.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "Toshi/Platform.h"
3#include "Toshi/TString8.h"
4#include "Toshi/TString16.h"
5#include "Toshi/T2String.h"
7
8#include <Windows.h>
9
10//-----------------------------------------------------------------------------
11// Enables memory debugging.
12// Note: Should be the last include!
13//-----------------------------------------------------------------------------
14#include "Core/TMemoryDebugOn.h"
15
17
18// $Barnyard: FUNCTION 006bb8a0
19void ThreadSleep( TUINT dwMilliseconds )
20{
21 Sleep( dwMilliseconds );
22}
23
24void FixPathSlashes( TString8& a_rPath )
25{
26 for ( TINT i = 0; i < a_rPath.Length(); i++ )
27 {
28 if ( a_rPath[ i ] == '/' )
29 a_rPath[ i ] = '\\';
30 }
31}
32
34{
35 for ( TINT i = 0; i < a_rPath.Length(); i++ )
36 {
37 if ( a_rPath[ i ] == '\\' )
38 a_rPath[ i ] = '/';
39 }
40}
41
42TString8 Platform_UnicodeToUTF8( const TWCHAR* a_wszUnicodeString )
43{
44 TINT iStrLen;
45 if ( a_wszUnicodeString && ( iStrLen = T2String16::Length( a_wszUnicodeString ) ) )
46 {
47 TINT sizeRequired = WideCharToMultiByte( CP_UTF8, 0, a_wszUnicodeString, -1, NULL, 0, NULL, NULL );
48
49 if ( sizeRequired > 0 )
50 {
51 T2DynamicVector<TCHAR> utf8String;
52 utf8String.SetSize( sizeRequired );
53
54 TINT bytesConverted = WideCharToMultiByte( CP_UTF8, 0, a_wszUnicodeString, -1, &utf8String[ 0 ], sizeRequired, NULL, NULL );
55
56 if ( bytesConverted != 0 )
57 return &utf8String[ 0 ];
58 }
59 }
60
61 return "";
62}
63
64TString16 Platform_UTF8ToUnicode( const TCHAR* a_pchUTF8String )
65{
66 if ( a_pchUTF8String && ( T2String8::Length( a_pchUTF8String ) ) )
67 {
68 TINT sizeRequired = MultiByteToWideChar( CP_UTF8, 0, a_pchUTF8String, -1, NULL, 0 );
69
70 if ( sizeRequired > 0 )
71 {
72 T2DynamicVector<TWCHAR> utf16String;
73 utf16String.SetSize( sizeRequired );
74
75 TINT bytesConverted = MultiByteToWideChar( CP_UTF8, 0, a_pchUTF8String, -1, &utf16String[ 0 ], sizeRequired );
76
77 if ( bytesConverted != 0 )
78 return &utf16String[ 0 ];
79 }
80 }
81
82 return L"";
83}
84
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
TString16 Platform_UTF8ToUnicode(const TCHAR *a_pchUTF8String)
void ThreadSleep(TUINT dwMilliseconds)
TString8 Platform_UnicodeToUTF8(const TWCHAR *a_wszUnicodeString)
void FixPathSlashes(TString8 &a_rPath)
void FixPathSlashesBack(TString8 &a_rPath)
Char string implementation for the Toshi engine.
wchar_t TWCHAR
Definition Typedefs.h:21
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
int TINT
Definition Typedefs.h:7
Dynamic vector container for the Toshi engine.
static TSIZE Length(const TWCHAR *str)
static TSIZE Length(const TCHAR *str)
TINT Length() const
Definition TString8.h:93
void SetSize(TINT a_iNewSize)