Re: ustring byte index vs character index (API 2.4)



Thanks a lot!

If found another way, peharps even more "hackish":
		for (int i = 0; i < str.bytes(); ++i)
		{
			...............

			while ((str.raw()[i] & 0xC0) == 0x80)
				++i;
		}

I think I'll use you solution, since it looks less hardcoded. :o)
yann

On 15/06/12 16:33, Kjell Ahlstedt wrote:
I think something like the following code will do the job, but it seems
a bit contrived. It uses the fact that Glib::ustring::iterator steps
through characters, but the underlying std::string::iterator only knows
about bytes.

Glib::ustring str = ..............;
const std::string::const_iterator std_begin = str.begin().base();
for (Glib::ustring::const_iterator iter = str.begin(); iter !=
str.end(); ++iter)
{
   const int byte_index = iter.base() - std_begin;
   ..................
}

Kjell

2012-06-15 10:20, Yann Leydier skrev:
Hi,

I hope this is the right place to ask, I have a problem with
Pangomm::GliphString::index_to_x(). One argument of the method is a
byte index in a ustring, and I need to call the method on each character.

However there seems to be no way of knowning where characters begin in
a ustring's byte field.

ustring::bytes() returns the number of bytes wheras ustring::size()
returns the number of characters, but I found no way of stepping
through characters using their byte index. Is there some kind of
"next_character(size_t position)" method or is this a flaw in Pangomm
integration ?

Thanks,
yann




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]