Christian Brabandt  wrote:

> Hi Bram!
>
> On Do, 28 Jul 2011, Bram Moolenaar wrote:
>
>>
>> Christian Brabandt wrote:
>>
>> > Hi Bram,
>> >
>> > attached patch fixes this issue from the todo list:
>> >
>> > ,----
>> > | Recognize and ignore BOM in error file. (Aleksey Baibarin)
>> > `----
>>
>> The patch was empty...
>
> I wonder how that happened.
> Anyway here is the patch again.
>
> regards
> Christian


Hi Christian

Looking at the patch, I see...

+       /* it should be safe to use the len variable */
+       len = STRLEN(IObuff);
+       if (check_bomb
+           && STRLEN(IObuff) >= 3
+           && enc_utf8
+           && IObuff[0] == 0xef
+           && IObuff[1] == 0xbb
+           && IObuff[2] == 0xbf)
+       /* remove utf-8 byte order mark from file */
+       {
+           mch_memmove(IObuff, IObuff+3, len - 3);
+           IObuff[len-3] = NUL;
+           check_bomb = FALSE;
+       }


It's calling STRLEN(IOBuff) twice.
The check for STRLEN(IObuff) >= 3 is not
needed anyway since checking for the 3 bytes
0xef, 0xbb, 0xbf will guarantee that STRLEN(IObuff) >= 3.

Also, you can call STRMOVE() instead of mch_memove()
which will also avoid having to do IObuff[len - 3] = NUL;
since STRMOVE() will copy the end of string.

So to sum up, I would write it like this (not tested):

+       if (check_bomb
+           && enc_utf8
+           && IObuff[0] == 0xef
+           && IObuff[1] == 0xbb
+           && IObuff[2] == 0xbf)
+       /* remove utf-8 byte order mark from file */
+       {
+           STRMOVE(IObuff, IObuff+3);
+           check_bomb = FALSE;
+       }

Regards
-- Dominique

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui