@@ -95,9 +95,9 @@ void Parser::Initialize_Tokenizer()
9595 shared_ptr<IStream> rfile;
9696 UCS2String actualFileName;
9797
98- pre_init_tokenizer ();
98+ pre_init_tokenizer ();
9999
100- rfile = Locate_File (sceneData->inputFile .c_str (),POV_File_Text_POV,actualFileName,true );
100+ rfile = Locate_File (sceneData->inputFile .c_str (), POV_File_Text_POV, actualFileName, true );
101101 if (rfile == nullptr )
102102 Error (" Cannot open input file." );
103103
@@ -106,7 +106,7 @@ void Parser::Initialize_Tokenizer()
106106
107107 mHavePendingRawToken = false ;
108108
109- Got_EOF = false ;
109+ Got_EOF = false ;
110110
111111 /* Init conditional stack. */
112112
@@ -118,17 +118,33 @@ void Parser::Initialize_Tokenizer()
118118 Max_Trace_Level = MAX_TRACE_LEVEL_DEFAULT;
119119 Had_Max_Trace_Level = false ;
120120
121- // / @todo Re-enable UTF-8 signature BOM handling.
122- #if 0
123- /* ignore any leading characters if they have character codes above 127, this
124- takes care of UTF-8 files with encoding info at the beginning of the file */
125- for(c = Echo_getc(); c > 127; c = Echo_getc())
126- sceneData->stringEncoding = kStringEncoding_UTF8; // switch to UTF-8 automatically [trf]
127- Echo_ungetc(c);
128- #endif
121+ CheckFileSignature ();
129122}
130123
131124
125+ // ******************************************************************************
126+
127+
128+ void Parser::CheckFileSignature ()
129+ {
130+ RawToken signature;
131+ if (GetRawToken (signature, false ))
132+ {
133+ if (signature.expressionId == SIGNATURE_FUNCT_TOKEN)
134+ {
135+ // Found a signature. Switch to the corresponding encoding automatically.
136+ // /@todo Still need to work on the mechanism to handle string encoding.
137+ switch (signature.id )
138+ {
139+ case UTF8_SIGNATURE_TOKEN: /* sceneData->stringEncoding = kStringEncoding_UTF8; */ break ;
140+ default : POV_PARSER_ASSERT (false ); break ;
141+ }
142+ }
143+ else
144+ UngetRawToken (signature);
145+ }
146+ }
147+
132148
133149/* ****************************************************************************
134150*
@@ -3512,6 +3528,8 @@ void Parser::IncludeHeader(const UCS2String& formalFileName)
35123528 mToken .is_array_elem = false ;
35133529 mToken .is_mixed_array_elem = false ;
35143530 mToken .is_dictionary_elem = false ;
3531+
3532+ CheckFileSignature ();
35153533}
35163534
35173535}
0 commit comments