[webkit-help] How can I write content of a TextRun to a file

n179911 n179911 at gmail.com
Sun Jan 17 15:22:31 PST 2010


Thanks. And I get compilation error in
String characters = run.characters().substring(from, to - from);

I think it is because 'run.characters()' returns a UChar* which does
not has a method called 'substring'

WebKit/WebCore/MyTest.cpp:92: error: request for member ‘substring’ in
‘((const WebCore::TextRun*)run)->WebCore::TextRun::characters()’,
which is of non-class type ‘const UChar*’

On Sun, Jan 17, 2010 at 12:23 PM, Julien Chaffraix
<julien.chaffraix at gmail.com> wrote:
> Hi,
>
>> I have a TextRun object and I would like to write the characters
>> between 'from' and 'to'
>> writeToFile(const TextRun& run,  int from, int to)
>>
>> Can you please tell me how can I do that?
>> I get a UChar* from run.characters() But how can I write it to a file?
>
> You can convert it to some encoding that you can dump as char* such as
> latin1 or utf8:
>
> String characters = run.characters().substring(from, to - from);
> CString charactersUTF8 = characters.utf8(); // Or .latin1().
> std::cout << charactersUTF8.data() << std::endl; // Print the results
> but you can use a stream to a file or fwrite as it as char*.
>
> If you want to avoid encoding conversion or the overhead of creating a
> String and a CString, you will have to look at  the ICU documentation
> (though you could use the same magic as in
> http://source.icu-project.org/repos/icu/icu/trunk/source/samples/ustring/ustring.cpp
> to dump your UChar*).
>
> Regards,
> Julien
>


More information about the webkit-help mailing list