473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

UnicodeString to std::string or char*

Is there an easy to convert from UnicodeString to string or char *?

Nov 5 '07 #1
3 11579
On Nov 5, 1:37 pm, Travis <travis.bow...@gmail.comwrote:
Is there an easy to convert from UnicodeString to string or char *?
You mean ICU UnicodeString? You'll need to convert it to UTF-8. See
the ICU converters: http://icu-project.org/userguide/cod...onverters.html

Nov 5 '07 #2
On Nov 5, 2:55 pm, Tristan Wibberley <maihem-...@maihem.orgwrote:
On Mon, 2007-11-05 at 11:04 -0800, Nemanja Trifunovic wrote:
On Nov 5, 1:37 pm, Travis <travis.bow...@gmail.comwrote:
Is there an easy to convert from UnicodeString to string or char *?
You mean ICU UnicodeString? You'll need to convert it to UTF-8. See
the ICU converters:http://icu-project.org/userguide/cod...onverters.html

Rather than simply UTF-8, you'd be better off converting it to the
character encoding of std::string::value_type WRT the std::codecvt facet
of the current global locale (if you expect to do any string processing
or stream it to a std::ostream) or to the std::codecvt facet of the
locale you're going to output the string to if you're going to use some
binary I/O API.
But how you can be sure that all the characters from the UnicodeString
fit into char encoding of the current global locale?

Nov 5 '07 #3

On Mon, 2007-11-05 at 12:41 -0800, Nemanja Trifunovic wrote:
On Nov 5, 2:55 pm, Tristan Wibberley <maihem-...@maihem.orgwrote:
On Mon, 2007-11-05 at 11:04 -0800, Nemanja Trifunovic wrote:
On Nov 5, 1:37 pm, Travis <travis.bow...@gmail.comwrote:
Is there an easy to convert from UnicodeString to string or char *?
You mean ICU UnicodeString? You'll need to convert it to UTF-8. See
the ICU converters:http://icu-project.org/userguide/cod...onverters.html
Rather than simply UTF-8, you'd be better off converting it to the
character encoding of std::string::value_type WRT the std::codecvt facet
of the current global locale (if you expect to do any string processing
or stream it to a std::ostream) or to the std::codecvt facet of the
locale you're going to output the string to if you're going to use some
binary I/O API.

But how you can be sure that all the characters from the UnicodeString
fit into char encoding of the current global locale?
You can set the global locale to have a UTF-8 char codecvt facet, or you
can decline to use any string processing functions unless you can pass a
locale/codecvt facet that tells it that the string is UTF-8 and decline to
stream the string through a std::ostream (although you can .imbue() the stream
with an appropriate locale).

Although, if you are just going to throw the data out to a file via binary I/O
or if you will have custom UTF-8 processing functions then you can do it safely.

I'm kind of just trying to warn against throwing character sets and encodings
around just because it seems like they fit better in a particular data type
(UTF-16 can be put into a std::string too).

--
Tristan Wibberley

Any opinion expressed is mine (or else I'm playing devils advocate for
the sake of a good argument). My employer had nothing to do with this
communication.

Nov 6 '07 #4

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

Similar topics

19
by: Espen Ruud Schultz | last post by:
Lets say I have a char pointer and an std::string. Is it possible to get a pointer to the std::string's "content" so that the char pointer can point to the same text? And vice versa; can I give...
24
by: Julie | last post by:
I'm re-evaluating the way that I convert from a std::string to char *. (Requirement: the source is a std::string, the usable contents are char *) Here is what I've come up with: #include...
16
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
6
by: Khuong Dinh Pham | last post by:
How do i read the contents of a xml file and output it to a std::string. Thx in advance
8
by: Jason Heyes | last post by:
If s is a std::string, does &s refer to the contiguous block of characters representing s?
37
by: jortizclaver | last post by:
Hi, I'm about to develop a new framework for my corporative applications and my first decision point is what kind of strings to use: std::string or classical C char*. Performance in my system...
10
by: sposes | last post by:
Im very much a newbie but perhaps somehone can help me. Ive been searching for a way to convert a std::string to a unsigned char* The situation is I have a function that wants a unsigned char*...
6
by: SteelSide | last post by:
Ive searched and searched,but havent been able to get it to work. ----------------- #include <iostream> using namespace std; std::string tempHostNameStr = "s1e2.hidden.thingy.org"; char...
13
by: arnuld | last post by:
/* C++ Primer 4/e * section 3.2 - String Standard Library * exercise 3.10 * STATEMENT * write a programme to strip the punctation from the string. */ #include <iostream> #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.