<div dir="ltr"><div>Hi Jose,</div><div><br></div><div>I have a function that efficiently converts latin1 to utf-8 (it's part of my DICOM code):</div><div><br></div><div> std::string convertLatin1ToUTF8(const char *text)</div><div> {</div><div> // latin1, codepage is identity</div><div> const char *cp = text;</div><div> size_t m = l;</div><div> // compute the size of the UTF-8 string</div><div> for (size_t n = 0; n < l; n++)</div><div> {</div><div> m += static_cast<unsigned char>(*cp++) >> 7;</div><div> }</div><div> cp = text;</div><div> std::string s;</div><div> s.resize(m);</div><div> // encode as UTF-8</div><div> size_t i = 0;</div><div> while (i < m)</div><div> {</div><div> while (i < m && (*cp & 0x80) == 0)</div><div> {</div><div> s[i++] = *cp++;</div><div> }</div><div> if (i < m)</div><div> {</div><div> int code = static_cast<unsigned char>(*cp++);</div><div> s[i++] = (0xC0 | (code >> 6));</div><div> s[i++] = (0x80 | (code & 0x3F));</div><div> }</div><div> }</div><div> return s;</div><div> }</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 19, 2015 at 7:18 AM, Jose Barreto <span dir="ltr"><<a href="mailto:jose.de.paula@live.com" target="_blank">jose.de.paula@live.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you David,<br>
It works here.<br>
I'm leaving two methods in a file if someone needs to use too.<br>
A String ^ converts to char * and other formats for UTF-8.<br>
<br>
maniputação_String_VTK.txt<br>
<<a href="http://vtk.1045678.n5.nabble.com/file/n5733560/maniputa%C3%A7%C3%A3o_String_VTK.txt" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/file/n5733560/maniputa%C3%A7%C3%A3o_String_VTK.txt</a>><br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/vtkUnicodeString-from-utf8-not-a-valid-UTF-8-string-tp5733543p5733560.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/vtkUnicodeString-from-utf8-not-a-valid-UTF-8-string-tp5733543p5733560.html</a><br>
<div class="HOEnZb"><div class="h5">Sent from the VTK - Users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br></div></div>