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.

Cheers,
chris


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> How is it supposed to be done and is this the desired behaviour?

Hmm, I don't think that's the desired behaviour, though I can confirm that 
WinXP does exactly what you describe, so...

Can you maybe post an STR for this, incuding your test example, so we don't 
forget?

In the meantime, you can probably walk along your string using fl_utf8fwd() or 
such to see where the "actual" character boundaries are.

Also, in the past, I have converted the entire string to UCS (i.e. 32-bit) 
characters, made my insertions/deletions, then converted back to UTF8. That 
might be appropriate for you here?

If so, fl_utf8towc() might be useful to you...



SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to