Skip to content

Commit 94dadac

Browse files
qaisjpccw808
authored andcommitted
Make UTF-8 BOM checks more clear
1 parent 0c6c6cb commit 94dadac

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

MTA10/mods/shared_logic/lua/CLuaMain.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,18 +2018,18 @@ bool CLuaMain::LoadScriptFromBuffer ( const char* cpInBuffer, unsigned int uiInS
20182018
bool bUTF8;
20192019

20202020
// UTF-8 BOM? Compare by checking the standard UTF-8 BOM
2021-
if ( IsUTF8BOM( cpBuffer, uiSize ) == false )
2022-
{
2023-
// Maybe not UTF-8, if we have a >80% heuristic detection confidence, assume it is
2024-
bUTF8 = ( GetUTF8Confidence ( (const unsigned char*)cpBuffer, uiSize ) >= 80 );
2025-
}
2026-
else
2021+
if ( IsUTF8BOM ( cpBuffer, uiSize ) )
20272022
{
20282023
// If there's a BOM, load ignoring the first 3 bytes
20292024
bUTF8 = true;
20302025
cpBuffer += 3;
20312026
uiSize -= 3;
20322027
}
2028+
else
2029+
{
2030+
// Maybe not UTF-8, if we have a >80% heuristic detection confidence, assume it is
2031+
bUTF8 = ( GetUTF8Confidence ( (const unsigned char*) cpBuffer, uiSize ) >= 80 );
2032+
}
20332033

20342034
// If compiled script, make sure correct chunkname is embedded
20352035
EmbedChunkName( strNiceFilename, &cpBuffer, &uiSize );

MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,18 @@ bool CLuaMain::LoadScriptFromBuffer ( const char* cpInBuffer, unsigned int uiInS
310310
bool bUTF8;
311311

312312
// UTF-8 BOM? Compare by checking the standard UTF-8 BOM
313-
if ( IsUTF8BOM( cpBuffer, uiSize ) == false )
314-
{
315-
// Maybe not UTF-8, if we have a >80% heuristic detection confidence, assume it is
316-
bUTF8 = ( GetUTF8Confidence ( (const unsigned char*)cpBuffer, uiSize ) >= 80 );
317-
}
318-
else
313+
if ( IsUTF8BOM( cpBuffer, uiSize ) )
319314
{
320315
// If there's a BOM, load ignoring the first 3 bytes
321316
bUTF8 = true;
322317
cpBuffer += 3;
323318
uiSize -= 3;
324319
}
320+
else
321+
{
322+
// Maybe not UTF-8, if we have a >80% heuristic detection confidence, assume it is
323+
bUTF8 = ( GetUTF8Confidence ( (const unsigned char*) cpBuffer, uiSize ) >= 80 );
324+
}
325325

326326
// If compiled script, make sure correct chunkname is embedded
327327
EmbedChunkName( strNiceFilename, &cpBuffer, &uiSize );

0 commit comments

Comments
 (0)