473,786 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unicode std::string

Hi,

Is there a unicode equivalent to std::string?
Jul 23 '05 #1
9 22564
vsgdp wrote:
Hi,

Is there a unicode equivalent to std::string?


std::wstring?
Jul 23 '05 #2
red floyd wrote:
vsgdp wrote:
Is there a unicode equivalent to std::string?


std::wstring?


for UTF-16, not for UTF-8.

Jul 23 '05 #3
Panjandrum wrote:
red floyd wrote:
vsgdp wrote:
Is there a unicode equivalent to std::string?


std::wstrin g?

for UTF-16, not for UTF-8.

hence the question mark.
Jul 23 '05 #4
Panjandrum wrote:
red floyd wrote:
vsgdp wrote:
> Is there a unicode equivalent to std::string?


std::wstring?


for UTF-16, not for UTF-8.


So you say unicode is only UTF-8? And std::string is always UTF-16?

Jul 23 '05 #5
Rolf Magnus wrote:
Panjandrum wrote:
red floyd wrote:
vsgdp wrote:
> Is there a unicode equivalent to std::string?

std::wstring?


for UTF-16, not for UTF-8.


So you say unicode is only UTF-8? And std::string is always UTF-16?


std::wstring and std::string are both not appropriate for
variable-length character encodings like UTF-8.

Jul 23 '05 #6
Panjandrum wrote:
Rolf Magnus wrote:
Panjandrum wrote:
> red floyd wrote:
>> vsgdp wrote:
>> > Is there a unicode equivalent to std::string?
>>
>> std::wstring?
>
> for UTF-16, not for UTF-8.


So you say unicode is only UTF-8? And std::string is always UTF-16?


std::wstring and std::string are both not appropriate for
variable-length character encodings like UTF-8.


Yes, but there are unicode encodings that don't need variable-length
characters.

Jul 23 '05 #7
Panjandrum wrote:
Rolf Magnus wrote:
Panjandrum wrote:
red floyd wrote:
vsgdp wrote:
> Is there a unicode equivalent to std::string?

std::wstring?

for UTF-16, not for UTF-8.

std::wstring does not specify any encoding type or any character set.

The most common implementations of std::wstring use Unicode
character set, and either UCS-4, UCS-2 or UTF-16 encoding.
But this is not a requirement.
std::wstring and std::string are both not appropriate for
variable-length character encodings like UTF-8.


std::string is appropriate for UTF-8.

But you must remember that functions like size() and find() will
apply to the encoded bytes, not to the decoded version.

If that was your issue, then you could also say that std::wstring
is not appropriate for any Unicode encoding, because of combining
characters (ie. the string length won't match the number of
display characters).

Of course the correct answer is that you should engage your
brain when manipulating Unicode strings, and be aware of
these issues. Many applications do indeed use std::string for
UTF-8 processing.

Jul 23 '05 #8
Old Wolf wrote:
Panjandrum wrote:
std::wstring and std::string are both not appropriate for
variable-length character encodings like UTF-8.
std::string is appropriate for UTF-8.

But you must remember that functions like size() and find() will
apply to the encoded bytes, not to the decoded version.


You mean std::string is appropriate, "just" most member functions don't
work?
If that was your issue, then you could also say that std::wstring
is not appropriate for any Unicode encoding, because of combining
characters (ie. the string length won't match the number of
display characters).
You use normalized UTF-16.
Of course the correct answer is that you should engage your
brain when manipulating Unicode strings, and be aware of
these issues. Many applications do indeed use std::string for
UTF-8 processing.


Disburden the brain by using sufficient tools for the task.

Jul 23 '05 #9


Panjandrum schreef:
Old Wolf wrote:
Panjandrum wrote:
std::wstring and std::string are both not appropriate for
variable-length character encodings like UTF-8.


std::string is appropriate for UTF-8.

But you must remember that functions like size() and find() will
apply to the encoded bytes, not to the decoded version.


You mean std::string is appropriate, "just" most member functions don't
work?


"don't work" is nonsense. They work, but the results are not what you
would like.
If that was your issue, then you could also say that std::wstring
is not appropriate for any Unicode encoding, because of combining
characters (ie. the string length won't match the number of
display characters).


You use normalized UTF-16.


Since Unicode 4, Unicode characters can no longer be encoded in 16
bits. Even with normalization you need 20 bits, or pairs of 16 bits.
However, there are implementations in which wchar_t is 32 bits.
(Note: wchar_t doesn't haave to be Unicode)

Regards,
Michiel Salters

Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5495
by: nico | last post by:
In my python scripts, I use a lot of accented characters as I work in french. In order to do this, I put the line # -*- coding: UTF-8 -*- at the beginning of the script file. Then, when I need to store accented characters in a string, I used to prefix the literal string with 'u', like this: mystring = u"prénom" But if I understand well, prefixing a unicode string literal with 'u'
3
3903
by: Shrii | last post by:
1.I read a unicode file by using codec 2.I want to pass that string to exec() statement 3.But one of my character (U+0950) in that string is not showing properly in the output got by that exec() statement could anyone help me to get proper output. ? somesh
2
10319
by: aurora | last post by:
I have some unicode string with some characters encode using python notation like '\n' for LF. I need to convert that to the actual LF character. There is a 'unicode_escape' codec that seems to suit my purpose. >>> encoded = u'A\\nA' >>> decoded = encoded.decode('unicode_escape') >>> print len(decoded) 3 Note that both encoded and decoded are unicode string. I'm trying to use
5
2501
by: wanghz | last post by:
Hello, everyone. I have a problem when I'm processing unicode strings. Is it possible to get the 8bit-string representation of any unicode string? Suppose I get a unicode string: a = u'\xc8\xce\xcf\xcd\xc6\xeb'; then, by a.encode('latin-1'); I can get the 8bit-string representation of it, that is, the physical
7
7628
by: pattreeya | last post by:
Hello, how can I get the number of byte of the string in python? with "len(string)", it doesn't work to get the size of the string in bytes if I have the unicode string but just the length. (it only works fine for ascii/latin1) In data structure, I have to store unicode string for many languages and must know exactly how big of my string which is stored so I can read back later. Many thanks for any suggestion.
8
20750
by: Preben Randhol | last post by:
Hi If I use len() on a string containing unicode letters I get the number of bytes the string uses. This means that len() can report size 6 when the unicode string only contains 3 characters (that one would write by hand or see on the screen). Is there a way to calculate in characters and not in bytes to represent the characters. The reason for asking is that PyGTK needs number of characters to set the width of Entry widgets to a...
1
8383
by: willie | last post by:
>willie wrote: wrote:
0
2608
by: mimi | last post by:
#include <fstream> #include "stdio.h" int main() { // std::wofstream strm2("test.txt"); // strm2 << L"ÎÒ°®±±¾©Ìì°²ÃÅ"; FILE *hFile = fopen("test.txt", "wb+"); wchar_t *buffer = L"ÎÒ°®±±¾©Ìì°²ÃÅ";
0
562
by: Jean-Paul Calderone | last post by:
On Mon, 5 May 2008 16:05:08 +0200, Simon Posnjak <sposnjak@gmail.comwrote: You need to provide some more information about `some_module.some_thing´. How is it implemented? What Python type does it expect? If it doesn't take a unicode string and it doesn't take a byte string, I don't know what kind of string it does take. Jean-Paul
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.