Winter wrote:

> I use vim to read the file which is the  attachment of this mail.
> This file can be read in with the encoding "cp936", and thing goes well.
> When i read the file via “:e ++enc=sjis† ( with a wrong encoding ) ,
> the vim shows "conversion error", and the characters get messed.
> So , the conversion failed by this "sjis encoding“
> 
> However, when i use the internal function of vim "iconv" like this.
> ---------------code-----------------------
> let line1=readfile("cp936.txt",'b')[0]
> echo iconv(line1,"sjis","utf-8")
> ---------------------------------------------
> the result turned to be the "messed characters"
> 
> I think this case is much the same as i used the "e ++enc=sjis".
> SO , the fail should happened during the conversion.
> 
> 
> The doc about the "iconv" is like, below :
> iconv({expr}, {from}, {to}) *iconv()*
>           The result is a String, which is the text {expr} converted
>    from encoding {from} to encoding {to}.
>            When the conversion fails an empty string is returned.
> 
> According to the doc, i think the iconv should return the empty string.
> 
> So, how can i know the happening of wrong conversion for the "iconv" ?
> Or, is there some misunderstanding about iconv ?

Yongwei Wu reported a similar problem last week.  It appears that
iconv() tries conversion even when there are errors.  If you get an
error message when loading the file that should also happen with
iconv().

Although getting an empty string on an error is good to notice something
went wrong, other times you might want to get whatever could be
converted.  We could add an argument tells it to fail or do a "best
effort" conversion.  I'm not sure that will always be possible, we
depend on what the iconv library does.

-- 
If your company is not involved in something called "ISO 9000" you probably
have no idea what it is.  If your company _is_ involved in ISO 9000 then you
definitely have no idea what it is.
                                (Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui