Re: Always setting UTF-8 flag - am I bad?
[email protected] (Erland Sommarskog)
| Newsgroups | perl.unicode |
|---|---|
| Organization | Erland Sommarskog |
| Message-ID | <[email protected]> |
Jean-Michel Hiver ([email protected]) writes: > Erland Sommarskog wrote: >>I working with an XS module that passes queries to MS SQL Server and >>returns data back using SQLOLEDB. MS SQL Server stores Unicode data >>as UTF-16. Also, all metadata is UTF-16. >> >>Currently when I get Unicode data back from SQL Server, I convert it to >>UTF-8, stash it in an SV, and then set the UTF-8 flag, without checking >>whether this is really necessary. >> > Personally I try to use Encode as much as possible which does The Right > Thing for me. > > $string = Encode::decode ('utf-16', $octets); is pretty safe. > > Regarding to speed, Encode seems pretty fast to me - but YMMV I guess. Alright, I failed to say that this is an XS module, so I convert with WideCharToMultiByte, a Windows routine(*), put the result in an SV, and then say SvUTF8_on. (*) SQLOLEDB is available on Windows only, so portability is not an issue. -- Erland Sommarskog, Stockholm, [email protected]