From -3772169048382300166
X-Google-Language: ENGLISH,ASCII
Path: g2news2.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: Mathias Gaunard <loufoque@gmail.com>
Newsgroups: comp.std.c++
Subject: Re: C++0x string conversions, etc.
Date: Fri, 28 Aug 2009 11:09:47 CST
Organization: http://groups.google.com
Lines: 31
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <c0d2765e-fd8f-4d5a-a705-fae3ecdee660@c2g2000yqi.googlegroups.com>
References: <7.0.0.16.2.20090826221507.040f5928@aristeia.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
Content-Type: text/plain; charset=ISO-8859-1
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Thu, 27 Aug 2009 21:41:01 -0700 (PDT)
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news2.google.com comp.std.c++:1322

On 28 ao�t, 00:45, Scott Meyers <smey...@aristeia.com> wrote:

> - If I have a pointer p of type char16_t* that points to a string encoded
>    using UTF-16 (a multibyte format) and I say ++p, does p move forward a
>    single (multibyte) character or a fixed number of machine bytes?  In
>    other words, can a compiler generate a fixed increment for the value of p
>    (as it would be able to do with a char* pointer), or must the value of
>    the increment be determined at runtime based on the character p points
>    to?

UTF-16 is a encoding for the Unicode character set that encodes a code
point as one or two 16-bit code units.
Pointers to char16_t don't behave any differently than pointers to
anything else.
If you increment a pointer to a T, the memory address held in the
pointer is increased by sizeof(T) bytes.

So that means that if you increment a pointer to a char16_t, you are
now at the next UTF-16 code unit, not necessarily at the next code
point.
If you want smart iteration of UTF-8 or UTF-16 ranges, you need a
conversion facility defined in terms of range adapters, not codecvt
facets.


-- 
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



