Oops, this should have been:

I now use

t.position(pos_to_offset(t.value(),2));

to convert UTF-8 character count to byte offset.

chris

> Thanks for your confirmation and feedback. I will file a STR, if nobody else 
> objects.
>
> In the meanwhile I had a look at the FLTK UTF-8 functions and found
> fl_utf8decode() useful for my problem and wrote this little
> helper function:
>
> static size_t pos_to_offset( const char *s_, size_t pos_ )
> {
>   size_t byte_offset = 0;
>   if ( s_ )
>     {
>       int len;
>       const char *end = s_ + strlen( s_ );
>       while ( pos_ && s_ < end )
>       {
>         fl_utf8decode( s_, end, &len );
>         byte_offset += len;
>         s_ += len;
>       }
>     }
>   return byte_offset;
> }
>
>
> I now use
>
> t.position(t.value(), pos_to_offset(2));
>
> to convert UTF-8 character count to byte offset.

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to