[cfe-dev] CLang and UTF BOM characters
John Tytgat
John.Tytgat at aaug.net
Sat Oct 16 08:29:47 PDT 2010
In message <AANLkTikSBG4iizY_RuSoBodkR+wgoN4ihDxDCv7FnBkz at mail.gmail.com>
Ruben Van Boxem <vanboxem.ruben at gmail.com> wrote:
> inline void processBOM( std::ifstream &stream )
> >
> > {
> >
> > const unsigned char BOM[] = { 0xef, 0xbb, 0xbf };
> >
> > char first3chars[3];
> >
> > if( !stream.read( first3chars, 3 ) )
> >
> > throw std::runtime_error( "Unexpected end of file" );
> >
> >
> >
> if( strcmp(reinterpret_cast<const char*>(BOM), first3chars) )
> >
> > stream.seekg( 0, std::ios::beg ); // reset to beginning of file
> >
> > }
strcmp() will read 4 bytes when the first 3 are matching. The 4th byte in
first3chars is not defined. memcmp(,,3) ?
John.
--
John Tytgat, in his comfy chair at home
John.Tytgat at aaug.net
More information about the cfe-dev
mailing list