Skip to content

Commit 5ebbaac

Browse files
committed
Make UTF-8 BOM checks more clear
1 parent 8dbe34b commit 5ebbaac

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
@@ -2014,18 +2014,18 @@ bool CLuaMain::LoadScriptFromBuffer ( const char* cpInBuffer, unsigned int uiInS
20142014
bool bUTF8;
20152015

20162016
// UTF-8 BOM? Compare by checking the standard UTF-8 BOM
2017-
if ( IsUTF8BOM( cpBuffer, uiSize ) == false )
2018-
{
2019-
// Maybe not UTF-8, if we have a >80% heuristic detection confidence, assume it is
2020-
bUTF8 = ( GetUTF8Confidence ( (const unsigned char*)cpBuffer, uiSize ) >= 80 );
2021-
}
2022-
else
2017+
if ( IsUTF8BOM ( cpBuffer, uiSize ) )
20232018
{
20242019
// If there's a BOM, load ignoring the first 3 bytes
20252020
bUTF8 = true;
20262021
cpBuffer += 3;
20272022
uiSize -= 3;
20282023
}
2024+
else
2025+
{
2026+
// Maybe not UTF-8, if we have a >80% heuristic detection confidence, assume it is
2027+
bUTF8 = ( GetUTF8Confidence ( (const unsigned char*) cpBuffer, uiSize ) >= 80 );
2028+
}
20292029

20302030
// If compiled script, make sure correct chunkname is embedded
20312031
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)