Skip to content

Commit

Permalink
Make UTF-8 BOM checks more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
qaisjp authored and ccw808 committed Jan 12, 2016
1 parent 0c6c6cb commit 94dadac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions MTA10/mods/shared_logic/lua/CLuaMain.cpp
Expand Up @@ -2018,18 +2018,18 @@ bool CLuaMain::LoadScriptFromBuffer ( const char* cpInBuffer, unsigned int uiInS
bool bUTF8;

// UTF-8 BOM? Compare by checking the standard UTF-8 BOM
if ( IsUTF8BOM( cpBuffer, uiSize ) == false )
{
// Maybe not UTF-8, if we have a >80% heuristic detection confidence, assume it is
bUTF8 = ( GetUTF8Confidence ( (const unsigned char*)cpBuffer, uiSize ) >= 80 );
}
else
if ( IsUTF8BOM ( cpBuffer, uiSize ) )
{
// If there's a BOM, load ignoring the first 3 bytes
bUTF8 = true;
cpBuffer += 3;
uiSize -= 3;
}
else
{
// Maybe not UTF-8, if we have a >80% heuristic detection confidence, assume it is
bUTF8 = ( GetUTF8Confidence ( (const unsigned char*) cpBuffer, uiSize ) >= 80 );
}

// If compiled script, make sure correct chunkname is embedded
EmbedChunkName( strNiceFilename, &cpBuffer, &uiSize );
Expand Down
12 changes: 6 additions & 6 deletions MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp
Expand Up @@ -310,18 +310,18 @@ bool CLuaMain::LoadScriptFromBuffer ( const char* cpInBuffer, unsigned int uiInS
bool bUTF8;

// UTF-8 BOM? Compare by checking the standard UTF-8 BOM
if ( IsUTF8BOM( cpBuffer, uiSize ) == false )
{
// Maybe not UTF-8, if we have a >80% heuristic detection confidence, assume it is
bUTF8 = ( GetUTF8Confidence ( (const unsigned char*)cpBuffer, uiSize ) >= 80 );
}
else
if ( IsUTF8BOM( cpBuffer, uiSize ) )
{
// If there's a BOM, load ignoring the first 3 bytes
bUTF8 = true;
cpBuffer += 3;
uiSize -= 3;
}
else
{
// Maybe not UTF-8, if we have a >80% heuristic detection confidence, assume it is
bUTF8 = ( GetUTF8Confidence ( (const unsigned char*) cpBuffer, uiSize ) >= 80 );
}

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

0 comments on commit 94dadac

Please sign in to comment.