Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Fast way to add null after each char
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 38 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Brad  
View profile  
 More options Sep 5 2010, 12:54 pm
Newsgroups: comp.lang.c++
From: Brad <byte8b...@gmail.com>
Date: Sun, 5 Sep 2010 09:54:28 -0700 (PDT)
Local: Sun, Sep 5 2010 12:54 pm
Subject: Fast way to add null after each char
std::string s = "easy";

std::string unicode_string;

std::string::const_iterator it,

for(it = s.begin(); it != s.end(); ++it)
{
        unicode_string.push_back(*it);
        unicode_string.push_back('\0');

}

The above for loop would make unicode_string look like this:

"e null a null s null y null"

Is there a faster way to do this... in place maybe?

Thanks for any tips,

Brad


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco S. Carta  
View profile  
 More options Sep 5 2010, 1:05 pm
Newsgroups: comp.lang.c++
From: "Francesco S. Carta" <entul...@gmail.com>
Date: Sun, 05 Sep 2010 19:05:30 +0200
Local: Sun, Sep 5 2010 1:05 pm
Subject: Re: Fast way to add null after each char
Brad <byte8b...@gmail.com>, on 05/09/2010 09:54:28, wrote:

> std::string s = "easy";

> std::string unicode_string;

> std::string::const_iterator it,

> for(it = s.begin(); it != s.end(); ++it)
> {
>    unicode_string.push_back(*it);
>    unicode_string.push_back('\0');
> }

> The above for loop would make unicode_string look like this:

> "e null a null s null y null"

Nay, it will make it look like "e\0a\0s\0y\0"... by the way, why do you
need to do such a thing?

> Is there a faster way to do this... in place maybe?

Faster, I don't know (measure it), in place, yes: use the
std::string::insert() method.

--
  FSC - http://userscripts.org/scripts/show/59948
  http://fscode.altervista.org - http://sardinias.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alf P. Steinbach /Usenet  
View profile  
 More options Sep 5 2010, 1:13 pm
Newsgroups: comp.lang.c++
From: "Alf P. Steinbach /Usenet" <alf.p.steinbach+use...@gmail.com>
Date: Sun, 05 Sep 2010 19:13:44 +0200
Local: Sun, Sep 5 2010 1:13 pm
Subject: Re: Fast way to add null after each char
* Brad, on 05.09.2010 18:54:

Depends what you want.

It /seems/ that you're assuming a little-endian architecture, and that the
intent is to treat unicode_string as UTF-16 encoded (via some low level cast),
and that you're assuming that the original character encoding is Latin-1 or a
subset.

That's an awful lot of assumptions.

Look in the standard library for mbcstowcs or something like that, in the C
library, or 'widen'-functions in the C++ library.

Under what seems to be your assumption of Latin-1 encoding of the 'char' string,
and an additional assumption of 16-bit 'wchar_t', you can however do

<code>
#include <iostream>
#include <string>
#include <limits.h>
using namespace std;

#define STATIC_ASSERT( x ) typedef char shouldBeTrue[(x)? 1 : -1]

STATIC_ASSERT( CHAR_BIT == 8 );
STATIC_ASSERT( sizeof( wchar_t ) == 2 );

int main()
{
     string const    s   = "Hello";
     wstring const   u( s.begin(), s.end() );

     wcout << u << L"\n";

}

</code>

But I don't recommend that; use the widening functions, C or C++.

Cheers & hth.,

- Alf

--
blog at <url: http://alfps.wordpress.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SG  
View profile  
 More options Sep 5 2010, 1:17 pm
Newsgroups: comp.lang.c++
From: SG <s.gesem...@gmail.com>
Date: Sun, 5 Sep 2010 10:17:37 -0700 (PDT)
Local: Sun, Sep 5 2010 1:17 pm
Subject: Re: Fast way to add null after each char
On 5 Sep., 19:05, "Francesco S. Carta" wrote:

> in place, yes: use the
> std::string::insert() method.

Or better yet, resize() to final size, assign the non-null characters
in a backwards loop and set a couple of chars to zero:

   void sillify(string & io)
   {
      size_t len1 = io.size();
      io.resize(len1*2,'\0');
      for (size_t k=len1; k-->1;)
         io[k*2] = io[k];
      for (size_t k=1; k<len1; k+=2)
         io[k] = '\0';
   }

Cheers!
SG


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco S. Carta  
View profile  
 More options Sep 5 2010, 1:27 pm
Newsgroups: comp.lang.c++
From: "Francesco S. Carta" <entul...@gmail.com>
Date: Sun, 05 Sep 2010 19:27:51 +0200
Local: Sun, Sep 5 2010 1:27 pm
Subject: Re: Fast way to add null after each char
SG <s.gesem...@gmail.com>, on 05/09/2010 10:17:37, wrote:

Define "better".

     void smartify(string& s) {
         for(int i = 1, e = s.size()*2; i < e; i+=2) {
             s.insert(i, 1, '\0');
         }
     }

--
  FSC - http://userscripts.org/scripts/show/59948
  http://fscode.altervista.org - http://sardinias.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marc  
View profile  
 More options Sep 5 2010, 1:54 pm
Newsgroups: comp.lang.c++
From: Marc <marc.gli...@gmail.com>
Date: Sun, 5 Sep 2010 10:54:46 -0700 (PDT)
Local: Sun, Sep 5 2010 1:54 pm
Subject: Re: Fast way to add null after each char
On 5 sep, 19:27, "Francesco S. Carta" <entul...@gmail.com> wrote:

Faster. SG's code has linear complexity and yours is quadratic.
Readability is something else...

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco S. Carta  
View profile  
 More options Sep 5 2010, 2:04 pm
Newsgroups: comp.lang.c++
From: "Francesco S. Carta" <entul...@gmail.com>
Date: Sun, 05 Sep 2010 20:04:18 +0200
Local: Sun, Sep 5 2010 2:04 pm
Subject: Re: Fast way to add null after each char
Marc <marc.gli...@gmail.com>, on 05/09/2010 10:54:46, wrote:

Exactly. So neither is better than the other unless we associate
"better" to "more readable" or to "faster" ;-)

--
  FSC - http://userscripts.org/scripts/show/59948
  http://fscode.altervista.org - http://sardinias.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco S. Carta  
View profile  
 More options Sep 5 2010, 2:32 pm
Newsgroups: comp.lang.c++
From: "Francesco S. Carta" <entul...@gmail.com>
Date: Sun, 05 Sep 2010 20:32:30 +0200
Local: Sun, Sep 5 2010 2:32 pm
Subject: Re: Fast way to add null after each char
Francesco S. Carta <entul...@gmail.com>, on 05/09/2010 20:04:18, wrote:

Just for the records, a better solution, in my opinion, is to build an
appropriately sized new string and copying the original chars at the
appropriate positions - a compromise between readability and speed,
somewhat:

     void foo(string& s) {
         string r(s.size()*2, '\0');
         for(int i = 0, e = s.size(); i < e; ++i) {
             r[i*2] = s[i];
         }
         s.swap(r);
     }

ASSUMING that the OP really wants exactly this - WRT Alf P. Steinbach's
notes in the other post.

--
  FSC - http://userscripts.org/scripts/show/59948
  http://fscode.altervista.org - http://sardinias.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SG  
View profile  
 More options Sep 5 2010, 2:53 pm
Newsgroups: comp.lang.c++
From: SG <s.gesem...@gmail.com>
Date: Sun, 5 Sep 2010 11:53:58 -0700 (PDT)
Local: Sun, Sep 5 2010 2:53 pm
Subject: Re: Fast way to add null after each char
On 5 Sep., 20:04, Francesco S. Carta wrote:

> Marc wrote:
> > On 5 sep, 19:27, Francesco S. Carta wrote:
> >> Define "better".
> > Faster. [...]
> Exactly. So neither is better than the other unless we associate
> "better" to "more readable" or to "faster" ;-)

See the original post:

  "...Is there a faster way to do this..."

Cheers!
SG


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juha Nieminen  
View profile  
 More options Sep 5 2010, 3:14 pm
Newsgroups: comp.lang.c++
From: Juha Nieminen <nos...@thanks.invalid>
Date: 05 Sep 2010 19:14:13 GMT
Local: Sun, Sep 5 2010 3:14 pm
Subject: Re: Fast way to add null after each char
Alf P. Steinbach /Usenet <alf.p.steinbach+use...@gmail.com> wrote:

  No, he isn't. He is making the string UTF16LE, not assuming that the
architecture is little-endian.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alf P. Steinbach /Usenet  
View profile  
 More options Sep 5 2010, 3:25 pm
Newsgroups: comp.lang.c++
From: "Alf P. Steinbach /Usenet" <alf.p.steinbach+use...@gmail.com>
Date: Sun, 05 Sep 2010 21:25:41 +0200
Local: Sun, Sep 5 2010 3:25 pm
Subject: Re: Fast way to add null after each char
* Juha Nieminen, on 05.09.2010 21:14:

Perhaps, but it would be (I think even more) unusual.

Cheers,

- Alf

--
blog at <url: http://alfps.wordpress.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco S. Carta  
View profile  
 More options Sep 5 2010, 4:00 pm
Newsgroups: comp.lang.c++
From: "Francesco S. Carta" <entul...@gmail.com>
Date: Sun, 05 Sep 2010 22:00:17 +0200
Local: Sun, Sep 5 2010 4:00 pm
Subject: Re: Fast way to add null after each char
SG <s.gesem...@gmail.com>, on 05/09/2010 11:53:58, wrote:

> On 5 Sep., 20:04, Francesco S. Carta wrote:
>> Marc wrote:
>>> On 5 sep, 19:27, Francesco S. Carta wrote:
>>>> Define "better".
>>> Faster. [...]
>> Exactly. So neither is better than the other unless we associate
>> "better" to "more readable" or to "faster" ;-)

> See the original post:

>    "...Is there a faster way to do this..."

Of course, I was just playing at nitpicking after your overzealous snip
- see my further post ;-)

--
  FSC - http://userscripts.org/scripts/show/59948
  http://fscode.altervista.org - http://sardinias.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Geoff  
View profile  
 More options Sep 5 2010, 4:02 pm
Newsgroups: comp.lang.c++
From: Geoff <ge...@invalid.invalid>
Date: Sun, 05 Sep 2010 13:02:11 -0700
Local: Sun, Sep 5 2010 4:02 pm
Subject: Re: Fast way to add null after each char

Are you really trying to insert null after each character or are you looking for
a way to convert std::string into std::wstring?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Geoff  
View profile  
 More options Sep 5 2010, 4:26 pm
Newsgroups: comp.lang.c++
From: Geoff <ge...@invalid.invalid>
Date: Sun, 05 Sep 2010 13:26:15 -0700
Local: Sun, Sep 5 2010 4:26 pm
Subject: Re: Fast way to add null after each char

Forgot to attach the code.

#include <string>

int main()
{
    std::string s = "easy";
    std::wstring unicode_string;

    unicode_string.assign(s.begin(),s.end());
    return 0;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tni  
View profile  
 More options Sep 6 2010, 4:37 am
Newsgroups: comp.lang.c++
From: tni <t...@example.invalid>
Date: Mon, 06 Sep 2010 10:37:08 +0200
Local: Mon, Sep 6 2010 4:37 am
Subject: Re: Fast way to add null after each char
On 2010-09-05 20:04, Francesco S. Carta wrote:

>> Faster. SG's code has linear complexity and yours is quadratic.
>> Readability is something else...

> Exactly. So neither is better than the other unless we associate
> "better" to "more readable" or to "faster" ;-)

Unnecessary quadratic code is a bug (unless you have guarantees on the
input size).

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco S. Carta  
View profile  
 More options Sep 6 2010, 4:56 am
Newsgroups: comp.lang.c++
From: "Francesco S. Carta" <entul...@gmail.com>
Date: Mon, 06 Sep 2010 10:56:37 +0200
Local: Mon, Sep 6 2010 4:56 am
Subject: Re: Fast way to add null after each char
tni <t...@example.invalid>, on 06/09/2010 10:37:08, wrote:

> On 2010-09-05 20:04, Francesco S. Carta wrote:

>>> Faster. SG's code has linear complexity and yours is quadratic.
>>> Readability is something else...

>> Exactly. So neither is better than the other unless we associate
>> "better" to "more readable" or to "faster" ;-)

> Unnecessary quadratic code is a bug (unless you have guarantees on the
> input size).

That was a deliberately slow implementation - see all the other posts.

--
  FSC - http://userscripts.org/scripts/show/59948
  http://fscode.altervista.org - http://sardinias.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tni  
View profile  
 More options Sep 6 2010, 5:38 am
Newsgroups: comp.lang.c++
From: tni <t...@example.invalid>
Date: Mon, 06 Sep 2010 11:38:54 +0200
Local: Mon, Sep 6 2010 5:38 am
Subject: Re: Fast way to add null after each char
On 2010-09-06 10:56, Francesco S. Carta wrote:

> tni <t...@example.invalid>, on 06/09/2010 10:37:08, wrote:

>> On 2010-09-05 20:04, Francesco S. Carta wrote:

>>>> Faster. SG's code has linear complexity and yours is quadratic.
>>>> Readability is something else...

>>> Exactly. So neither is better than the other unless we associate
>>> "better" to "more readable" or to "faster" ;-)

>> Unnecessary quadratic code is a bug (unless you have guarantees on the
>> input size).

> That was a deliberately slow implementation - see all the other posts.

My point isn't that the implementation is a bit slower, it's wrong and
should never be used. There is no question whether one of the two is better.

Feed your quadratic implementation a 10MB string and it will literally
run for hours.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco S. Carta  
View profile  
 More options Sep 6 2010, 6:05 am
Newsgroups: comp.lang.c++
From: "Francesco S. Carta" <entul...@gmail.com>
Date: Mon, 06 Sep 2010 12:05:14 +0200
Local: Mon, Sep 6 2010 6:05 am
Subject: Re: Fast way to add null after each char
tni <t...@example.invalid>, on 06/09/2010 11:38:54, wrote:

You're right, of course, and finally somebody posted the correct,
explicit objection to the first response of mine, which was
over-zealously half-snipped by SG:

"Faster, I don't know (measure it), in place, yes: use the
std::string::insert() method."

My purpose was to push the OP to make all the tests and the reasonings.

But the OP disappeared and the group took circa ten posts to come down
to this, I won't post any bait like this anymore, just to save my time :-)

--
  FSC - http://userscripts.org/scripts/show/59948
  http://fscode.altervista.org - http://sardinias.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Goran Pusic  
View profile  
 More options Sep 6 2010, 6:15 am
Newsgroups: comp.lang.c++
From: Goran Pusic <gor...@cse-semaphore.com>
Date: Mon, 6 Sep 2010 03:15:21 -0700 (PDT)
Local: Mon, Sep 6 2010 6:15 am
Subject: Re: Fast way to add null after each char
On Sep 5, 6:54 pm, Brad <byte8b...@gmail.com> wrote:

+1 for Alf. Chances are that you are just looking for
MultiByteToWideChar (or libiconv, but that's less likely).

Guys, aren't you a bit misleading with iterators and big-O and
stuff? ;-)

Goran.

Goran.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco S. Carta  
View profile  
 More options Sep 6 2010, 6:38 am
Newsgroups: comp.lang.c++
From: "Francesco S. Carta" <entul...@gmail.com>
Date: Mon, 06 Sep 2010 12:38:06 +0200
Local: Mon, Sep 6 2010 6:38 am
Subject: Re: Fast way to add null after each char
Goran Pusic <gor...@cse-semaphore.com>, on 06/09/2010 03:15:21, wrote:

> Guys, aren't you a bit misleading with iterators and big-O and
> stuff? ;-)

My bad. I intentionally posted a wrong suggestion without clearly
marking it as such - I thought I was going to be castigated immediately,
but since the punishment didn't come at once, I kept it on to see what
was going to happen... now I realize that it wasn't all that fun for the
others, so I present my apologies to the group for the wasted time.

--
  FSC - http://userscripts.org/scripts/show/59948
  http://fscode.altervista.org - http://sardinias.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tni  
View profile  
 More options Sep 6 2010, 8:33 am
Newsgroups: comp.lang.c++
From: tni <t...@example.invalid>
Date: Mon, 06 Sep 2010 14:33:13 +0200
Local: Mon, Sep 6 2010 8:33 am
Subject: Re: Fast way to add null after each char
On 2010-09-06 12:38, Francesco S. Carta wrote:

> Goran Pusic <gor...@cse-semaphore.com>, on 06/09/2010 03:15:21, wrote:

>> Guys, aren't you a bit misleading with iterators and big-O and
>> stuff? ;-)

> My bad. I intentionally posted a wrong suggestion without clearly
> marking it as such - I thought I was going to be castigated immediately,
> but since the punishment didn't come at once, I kept it on to see what
> was going to happen... now I realize that it wasn't all that fun for the
> others, so I present my apologies to the group for the wasted time.

The sad thing is, I've seen quadratic stuff like that far too often in
production code. There certainly are more than enough (clueless) people
who wouldn't consider it a joke.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco S. Carta  
View profile  
 More options Sep 6 2010, 11:18 am
Newsgroups: comp.lang.c++
From: "Francesco S. Carta" <entul...@gmail.com>
Date: Mon, 06 Sep 2010 17:18:26 +0200
Local: Mon, Sep 6 2010 11:18 am
Subject: Re: Fast way to add null after each char
tni <t...@example.invalid>, on 06/09/2010 14:33:13, wrote:

> On 2010-09-06 12:38, Francesco S. Carta wrote:
>> Goran Pusic <gor...@cse-semaphore.com>, on 06/09/2010 03:15:21, wrote:

>>> Guys, aren't you a bit misleading with iterators and big-O and
>>> stuff? ;-)

>> My bad. I intentionally posted a wrong suggestion without clearly
>> marking it as such - I thought I was going to be castigated immediately,
>> but since the punishment didn't come at once, I kept it on to see what
>> was going to happen... now I realize that it wasn't all that fun for the
>> others, so I present my apologies to the group for the wasted time.

> The sad thing is, I've seen quadratic stuff like that far too often in
> production code. There certainly are more than enough (clueless) people
> who wouldn't consider it a joke.

Indeed. And since it seems that most of those programmers has no idea of
what the O() notation is, simply saying that an algorithm has linear or
quadratic complexity is not enough to make the point clear.

Unfortunately it needs more words (and practical examples as the one you
posted in the other branch) and a big fat "quadratic is BAD" sign three
meters on each side, but it's worth the effort.

--
  FSC - http://userscripts.org/scripts/show/59948
  http://fscode.altervista.org - http://sardinias.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad  
View profile  
 More options Sep 7 2010, 8:45 am
Newsgroups: comp.lang.c++
From: Brad <byte8b...@gmail.com>
Date: Tue, 7 Sep 2010 05:45:44 -0700 (PDT)
Local: Tues, Sep 7 2010 8:45 am
Subject: Re: Fast way to add null after each char
On Sep 6, 6:05 am, "Francesco S. Carta" <entul...@gmail.com> wrote:

Busy weekend. Thanks for the replies (all of you).

Why do such a thing?

Over simplified, but here is why: A Microsoft NT hash is a string
(encoded as I described (utf-16le)) with MD4 then applied. In short,
that produces an NT hash. So if I wanted to create an NT hash for the
word "easy" and I had a std::string the process would look something
like this:

std::string NTHash = MD4(utf-16le_encode(std::string));

My initial post confused the issue by using the term "unicode" in a
variable name (although this is a form of unicode (utf-16le)
encoding). And no, by default wstring doesn't magically do this.

--------------------------------------

insert works fine for in place. Faster than my for loop? Does not seem
so. I'm not sure it needs to be any faster. I was just wondering.
Maybe my approach is slow. Obviously, the encoding is an additional
step to perform (plain MD4 on std::string is faster than encode
std::string then MD4... but not a whole lot). BTW, these strings would
never be 10 megs ;)

That's about it. Thanks again.

Brad


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francesco S. Carta  
View profile  
 More options Sep 7 2010, 2:23 pm
Newsgroups: comp.lang.c++
From: "Francesco S. Carta" <entul...@gmail.com>
Date: Tue, 07 Sep 2010 20:23:31 +0200
Local: Tues, Sep 7 2010 2:23 pm
Subject: Re: Fast way to add null after each char
Brad <byte8b...@gmail.com>, on 07/09/2010 05:45:44, wrote:

You're welcome.

Your initial implementation is not slow, it's pretty fine, my only
(serious) suggestion about it is to use something like the second
implementation I presented, which takes advantage of std::string::swap()
to avoid an unneeded additional copy from the working string to the
original one and optimizes the allocation by creating an
appropriately-sized string beforehand.

Completely forget the insert() method for containers such as std::vector
and std::string - because it leads to very bad performances - but
remember it for containers like std::list - where it is good.

--
  FSC - http://userscripts.org/scripts/show/59948
  http://fscode.altervista.org - http://sardinias.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alf P. Steinbach /Usenet  
View profile  
 More options Sep 7 2010, 2:52 pm
Newsgroups: comp.lang.c++
From: "Alf P. Steinbach /Usenet" <alf.p.steinbach+use...@gmail.com>
Date: Tue, 07 Sep 2010 20:52:19 +0200
Local: Tues, Sep 7 2010 2:52 pm
Subject: Re: Fast way to add null after each char
* Brad, on 07.09.2010 14:45:

OK, with more information more can be said.

First, in Windows, conversion to wstring like

   string  s = "blah blah";
   wstring u( s.begin(), s.end() )

produces exactly the byte sequence that you're laboriously creating.

You're right that no magic is involved. However, no magic is necessary.

That said, second, Windows ANSI Western is a superset, not a subset, of Latin 1,
and so this zero-insertion procedure does not in general produce UTF-16.

E.g., if s contains a '€' Euro sign you won't get proper UTF-16. If you need
proper UTF-16 you should use one of the conversion functions available in the
standard library, or alternatively in the Windows API.

Third, I've already given this advice and it gets tiresome repeating it.

Cheers & hth.,

- Alf

--
blog at <url: http://alfps.wordpress.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 38   Newer >
« Back to Discussions « Newer topic     Older topic »