MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / isValidUTF8BOM

Function isValidUTF8BOM

Engine/source/core/strings/unicode.cpp:612–654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

610}
611
612bool isValidUTF8BOM( U8 bom[4] )
613{
614 // Is it a BOM?
615 if( bom[0] == 0 )
616 {
617 // Could be UTF32BE
618 if( bom[1] == 0 && bom[2] == 0xFE && bom[3] == 0xFF )
619 {
620 Con::warnf( "Encountered a UTF32 BE BOM in this file; Torque does NOT support this file encoding. Use UTF8!" );
621 return false;
622 }
623
624 return false;
625 }
626 else if( bom[0] == 0xFF )
627 {
628 // It's little endian, either UTF16 or UTF32
629 if( bom[1] == 0xFE )
630 {
631 if( bom[2] == 0 && bom[3] == 0 )
632 Con::warnf( "Encountered a UTF32 LE BOM in this file; Torque does NOT support this file encoding. Use UTF8!" );
633 else
634 Con::warnf( "Encountered a UTF16 LE BOM in this file; Torque does NOT support this file encoding. Use UTF8!" );
635 }
636
637 return false;
638 }
639 else if( bom[0] == 0xFE && bom[1] == 0xFF )
640 {
641 Con::warnf( "Encountered a UTF16 BE BOM in this file; Torque does NOT support this file encoding. Use UTF8!" );
642 return false;
643 }
644 else if( bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF )
645 {
646 // Can enable this if you want -pw
647 //Con::printf("Encountered a UTF8 BOM. Torque supports this.");
648 return true;
649 }
650
651 // Don't print out an error message here, because it will try this with
652 // every script. -pw
653 return false;
654}

Callers 1

chompUTF8BOMFunction · 0.85

Calls 1

warnfFunction · 0.50

Tested by

no test coverage detected