http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* Discount Wholesale Armani Jeans Christian Audigier Jeans ED Hardy Jeans (www.
vipchinatrade.com) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/62cb14b1f5535017?hl=en
* Paypal payment Cheap Wholesale Sneakers Air Force One, Air Max LTD, Max TN,
Nike Shox etc (www.vipchinatrade.com) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/5fcfd51f11a7328a?hl=en
* Safe to use substr? - 7 messages, 5 authors
http://groups.google.com/group/comp.lang.c++/t/cece8bdad80abdbe?hl=en
* C++0x regex supported by gcc? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/a5e3fb25be9236a9?hl=en
* Escape a string to bytes - 9 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/0ed981f009a7ba73?hl=en
* Again substrings and so on - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/736557e5175db0ba?hl=en
* isspace - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/89ca303518428e34?hl=en
==============================================================================
TOPIC: Discount Wholesale Armani Jeans Christian Audigier Jeans ED Hardy Jeans
(www.vipchinatrade.com)
http://groups.google.com/group/comp.lang.c++/t/62cb14b1f5535017?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 31 2010 8:03 am
From: wendy
Cheap Wholesale Shox NZ <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox OZ <www.vipchinatrade.com> free shipping
Cheap Wholesale Shox R2 <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox R3 <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox R3+R4 <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox R4 <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox R5 <www.vipchinatrade.com> free shipping
Cheap Wholesale Shox Reverie lover
Cheap Wholesale Shox RZ <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox TL <www.vipchinatrade.com> free shipping
Cheap Wholesale Shox Torch <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox TZ <www.vipchinatrade.com> paypal payment
Cheap Wholesale Nike Air Max 87 <www.vipchinatrade.com> free shipping
Cheap Wholesale Nike Air Max 89 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 90 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 91 <www.vipchinatrade.com> free shipping
Cheap Wholesale Nike Air Max 92 Man <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 93 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 95 <www.vipchinatrade.com> free shipping
Cheap Wholesale Nike Air Max 97 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 180 Man <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 2006 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 2009 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max Clssic BW <www.vipchinatrade.com> free
shipping
Cheap Wholesale Nike Air Max LTD <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max Skyline <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max STAB <www.vipchinatrade.com> free
shipping
Cheap Wholesale Nike Air Max Tailwind <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max TN <www.vipchinatrade.com> paypal
payment
Air Force one <www.vipchinatrade.com> paypal payment
Cheap Wholesale Air Force One Man <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force One Women <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force One M&W <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force one 25 Man <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force One 25 Women <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force One Kid <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force one Mid Man <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force one Mid Women <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force one Hight Women <www.vipchinatrade.com>
paypal payment
==============================================================================
TOPIC: Paypal payment Cheap Wholesale Sneakers Air Force One, Air Max LTD, Max
TN, Nike Shox etc (www.vipchinatrade.com)
http://groups.google.com/group/comp.lang.c++/t/5fcfd51f11a7328a?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 31 2010 8:05 am
From: yoyo
Cheap Wholesale Shox NZ <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox OZ <www.vipchinatrade.com> free shipping
Cheap Wholesale Shox R2 <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox R3 <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox R3+R4 <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox R4 <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox R5 <www.vipchinatrade.com> free shipping
Cheap Wholesale Shox Reverie lover
Cheap Wholesale Shox RZ <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox TL <www.vipchinatrade.com> free shipping
Cheap Wholesale Shox Torch <www.vipchinatrade.com> paypal payment
Cheap Wholesale Shox TZ <www.vipchinatrade.com> paypal payment
Cheap Wholesale Nike Air Max 87 <www.vipchinatrade.com> free shipping
Cheap Wholesale Nike Air Max 89 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 90 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 91 <www.vipchinatrade.com> free shipping
Cheap Wholesale Nike Air Max 92 Man <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 93 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 95 <www.vipchinatrade.com> free shipping
Cheap Wholesale Nike Air Max 97 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 180 Man <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 2006 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max 2009 <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max Clssic BW <www.vipchinatrade.com> free
shipping
Cheap Wholesale Nike Air Max LTD <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max Skyline <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max STAB <www.vipchinatrade.com> free
shipping
Cheap Wholesale Nike Air Max Tailwind <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Nike Air Max TN <www.vipchinatrade.com> paypal
payment
Air Force one <www.vipchinatrade.com> paypal payment
Cheap Wholesale Air Force One Man <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force One Women <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force One M&W <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force one 25 Man <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force One 25 Women <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force One Kid <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force one Mid Man <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force one Mid Women <www.vipchinatrade.com> paypal
payment
Cheap Wholesale Air Force one Hight Women <www.vipchinatrade.com>
paypal payment
==============================================================================
TOPIC: Safe to use substr?
http://groups.google.com/group/comp.lang.c++/t/cece8bdad80abdbe?hl=en
==============================================================================
== 1 of 7 ==
Date: Sun, Jan 31 2010 8:58 am
From: Immortal Nephi
On Jan 31, 2:47 am, Robert Fendt <rob...@fendt.net> wrote:
> And thus spake Immortal Nephi <Immortal_Ne...@hotmail.com>
> Sat, 30 Jan 2010 18:49:34 -0800 (PST):
>
> > I want to know that size_type returns –1 (minus one) is safe before I
> > extract one string into two substrings. First example is safe and
> > second example is not sure.
>
> > const basic_string <char>::size_type npos = -1;
>
> Why don't you just use std::string (which is a typedef of std::basic_string<char>)? It is more readable. Secondly, consider using string::npos instead of redefining it yourself. IIRC, the exact definition of npos is implementation-defined, thus it is dangerous to assume too much about it. It _is_ in fact defined as (size_t)-1 on almost all systems, but strictly speaking that depends on implementation and processor architecture.
>
> > begin_index returns 0 and end_index returns 5. substr is safe.
>
> Let's just say, it does what you expected it to do.
>
> > Second example:
>
> > begin_index = data.find_first_not_of( " ", end_index );
> > end_index = data.find_first_of( " ", begin_index );
> > token2 = data.substr( begin_index, end_index - begin_index );
> > length_index = token2.length();
>
> > begin_index returns 6 and end_index returns –1. Is substr safe for
> > token2 because end_index returns –1 indicates space character is not
> > found.
>
> Yes. The standard specifies that its parameters are of type string::size_type, thus (at least in case of basic_string<char> and basic_string<wchar_t>) they are definitely unsigned. So in fact you are passing a _very_ large number as second parameter. My standard library docs state that if the second parameter points beyond the string, the end of the string is assumed instead (in fact, the default value for the second parameter is string::npos).
find_first_not of() function and find_first_of() function always
return unsigned integer like size_type. The size _type gives you the
information if unsigned integer is valid or not valid.
The minimum size_type is 0 and maximum size_type is 0xFFFFFFFE (on 32
bit machine). Both integer values provide you the information how
many elements do string have. The 0xFFFFFFFF or –1 indicates that
data in the string is not found or is not valid.
Let's discuss substr() function. The substr() function's first
parameter must always have minimum size_type and maximum size_type.
If 0xFFFFFFFF or –1 is detected, then exception will be thrown.
The second parameter always has default 0xFFFFFFFF or –1 if you do
not assign second parameter.
For example
string data( "Hello World!" );
string token = data.substr( 0 );
The data has 11 elements in length. Notice that second parameter in
substr() function is not assigned. The default is –1. How do substr
() function know to count 11 elements correctly? It should always
count all 256 values of character set including '\0'.
If you insert '\0' between Hello and World ( "Hello \0World!" ), then
it will count 12 elements including '\0'. The string object is not
like C string. It does not check null terminator and it always check
number of elements in size with size() function or length() function.
end_token = 5;
begin_token = data.find_first_not_of( " ", end_token + 1 );
end_token = data.find_first_of( " ", begin_token );
string token = data.substr( begin_token, end_token - begin_token );
length_token = token.length();
find_first_of() function returns –1 indicates space is not found.
substr() function cannot guarantee to assume to be 11. Possibly, it
will go beyond 11 elements boundary until it detects '\0' and returns
the wrong end_token value.
I think that my example code above is not a good solution. I will
use iterator loop to test each element instead.
== 2 of 7 ==
Date: Sun, Jan 31 2010 1:19 pm
From: LR
Immortal Nephi wrote:
> find_first_not of() function and find_first_of() function always
> return unsigned integer like size_type. The size _type gives you the
> information if unsigned integer is valid or not valid.
> The minimum size_type is 0 and maximum size_type is 0xFFFFFFFE (on 32
> bit machine). Both integer values provide you the information how
> many elements do string have. The 0xFFFFFFFF or –1 indicates that
> data in the string is not found or is not valid.
> Let's discuss substr() function. The substr() function's first
> parameter must always have minimum size_type and maximum size_type.
I think you mean the argument pos must be between 0 and size().
const std::string s ("Hello World");
const std::string t = s.substr(); // pos == 0
const std::string u = s.substr(0);
const std::string v = s.substr(s.size());
> If 0xFFFFFFFF or –1 is detected, then exception will be thrown.
> The second parameter always has default 0xFFFFFFFF or –1 if you do
> not assign second parameter.
>
> For example
>
> string data( "Hello World!" );
> string token = data.substr( 0 );
>
> The data has 11 elements in length. Notice that second parameter in
> substr() function is not assigned. The default is –1. How do substr
> () function know to count 11 elements correctly?
std::string keeps track of the length or size of the string. It doesn't
use zero termination the way C strings do.
Also, note that a std::string cannot grow to be larger than
std::string::max_size(). In the implementation I use this is
std::numeric_limits<std::string::size_type>::max()-1.
>It should always
> count all 256 values of character set including '\0'.
It will. Try this:
const std::string s =
std::string("Hello") + '\0' + std::string("World");
std::cout << s << std::endl;
std::cout << s.size() << std::endl;
> If you insert '\0' between Hello and World ( "Hello \0World!" ), then
> it will count 12 elements including '\0'. The string object is not
> like C string. It does not check null terminator and it always check
> number of elements in size with size() function or length() function.
>
> end_token = 5;
> begin_token = data.find_first_not_of( " ", end_token + 1 );
You're not looking for the '\0'.
> end_token = data.find_first_of( " ", begin_token );
Same.
>
> string token = data.substr( begin_token, end_token - begin_token );
> length_token = token.length();
I think this will work:
const std::string
data = std::string("Hello ") + '\0' + std::string("World");
const std::string look_for = std::string(" ")+'\0';
const std::string::size_type first = data.find_first_of(look_for);
const std::string::size_type
begin_token = data.find_first_not_of(look_for, first+1);
const std::string::size_type
end_token = data.find_first_of(look_for, begin_token);
const std::string
token = data.substr(begin_token, end_token-begin_token);
const std::string::size_type length_token = token.length();
LR
== 3 of 7 ==
Date: Sun, Jan 31 2010 1:57 pm
From: James Kanze
On 31 Jan, 16:58, Immortal Nephi <Immortal_Ne...@hotmail.com> wrote:
> On Jan 31, 2:47 am, Robert Fendt <rob...@fendt.net> wrote:
> > And thus spake Immortal Nephi <Immortal_Ne...@hotmail.com>
> > Sat, 30 Jan 2010 18:49:34 -0800 (PST):
[...]
> > > Second example:
> > > begin_index = data.find_first_not_of( " ", end_index );
> > > end_index = data.find_first_of( " ", begin_index );
> > > token2 = data.substr( begin_index, end_index - begin_index );
> > > length_index = token2.length();
>
> > > begin_index returns 6 and end_index returns -1. Is substr
> > > safe for token2 because end_index returns -1 indicates
> > > space character is not found.
> > Yes. The standard specifies that its parameters are of type
> > string::size_type, thus (at least in case of
> > basic_string<char> and basic_string<wchar_t>) they are
> > definitely unsigned. So in fact you are passing a _very_
> > large number as second parameter. My standard library docs
> > state that if the second parameter points beyond the string,
> > the end of the string is assumed instead (in fact, the
> > default value for the second parameter is string::npos).
> find_first_not of() function and find_first_of() function
> always return unsigned integer like size_type. The size_type
> gives you the information if unsigned integer is valid or not
> valid.
I'm afraid I don't understand that last sentence. A type can't
give you any information.
> The minimum size_type is 0 and maximum size_type is 0xFFFFFFFE
> (on 32 bit machine). Both integer values provide you the
> information how many elements do string have.
What do you mean by "both" here? A zero value designates the
first character of the string, or indicates that the length of
the string is 0. The maximum value is used as a sentinal:
std::string::size will never return it. The only functions
which do return it are those which look for something, and they
use it as a special value, to indicate that they didn't find
what they were looking for.
> The 0xFFFFFFFF or -1 indicates that data in the string is not
> found or is not valid.
(Just a nit, but 0xFFFFFFFF is *not* -1. They're two different
values.)
> Let's discuss substr() function. The substr() function's
> first parameter must always have minimum size_type and maximum
> size_type.
The first argument must be in the range [0...s.size()], where s
is the string you're concerned with. It specifies the index of
the first character in the substring you want.
> If 0xFFFFFFFF or -1 is detected, then exception will be
> thrown.
(Again, -1 cannot be detected, because it cannot be represented
on the type of the argument.)
> The second parameter always has default 0xFFFFFFFF or -1 if
> you do not assign second parameter.
> For example
> string data( "Hello World!" );
> string token = data.substr( 0 );
> The data has 11 elements in length. Notice that second
> parameter in substr() function is not assigned. The default
> is -1.
The default is std::string::npos, not -1.
> How do substr () function know to count 11 elements
> correctly?
It's a member function. It knows the length of the string.
(How do you think std::string::size works?)
> It should always count all 256 values of character set
> including '\0'.
It doesn't count anything.
> If you insert '\0' between Hello and World ( "Hello \0World!"
> ), then it will count 12 elements including '\0'. The string
> object is not like C string. It does not check null
> terminator and it always check number of elements in size with
> size() function or length() function.
> end_token = 5;
> begin_token = data.find_first_not_of( " ", end_token + 1 );
> end_token = data.find_first_of( " ", begin_token );
> string token = data.substr( begin_token, end_token - begin_token );
> length_token = token.length();
> find_first_of() function returns -1 indicates space is not found.
It returns std::string::npos (which is *not* -1) to indicate
that it didn't find any character in the list given.
> substr() function cannot guarantee to assume to be 11.
> Possibly, it will go beyond 11 elements boundary until it
> detects '\0' and returns the wrong end_token value.
Why on earth would it do a thing like that? An std::string
knows its length, and unless the standard specifically states
otherwise, it uses this length. No member function ever looks
for '\0'.
> I think that my example code above is not a good solution. I
> will use iterator loop to test each element instead.
I think you still have a lot to learn about the standard
library. (And also expressing yourself clearly---which is a
prerequisite to good programming. I don't know how much of this
is due to English not being your native language, however.)
--
James Kanze
== 4 of 7 ==
Date: Sun, Jan 31 2010 2:00 pm
From: James Kanze
On 31 Jan, 21:19, LR <lr...@superlink.net> wrote:
> Immortal Nephi wrote:
[...]
> I think this will work:
> const std::string
> data = std::string("Hello ") + '\0' + std::string("World");
An even simpler solution might be:
std::string const data( "Hello \0World", 12 );
--
James Kanze
== 5 of 7 ==
Date: Sun, Jan 31 2010 2:14 pm
From: "Leigh Johnston"
>
>> If 0xFFFFFFFF or -1 is detected, then exception will be
>> thrown.
>
> (Again, -1 cannot be detected, because it cannot be represented
> on the type of the argument.)
>
assert(static_cast<unsigned int>(-1) == -1);
:)
/Leigh
== 6 of 7 ==
Date: Sun, Jan 31 2010 4:52 pm
From: Öö Tiib
On Feb 1, 12:14 am, "Leigh Johnston" <le...@i42.co.uk> wrote:
> >> If 0xFFFFFFFF or -1 is detected, then exception will be
> >> thrown.
>
> > (Again, -1 cannot be detected, because it cannot be represented
> > on the type of the argument.)
>
> assert(static_cast<unsigned int>(-1) == -1);
>
> :)
>
> /Leigh
Anyway you get diagnostic warnings for it from most compilers. If
'static_cast<unsigned int>(-1)' is needed then '~0U' is perhaps
shortest form that makes all compilers happy with it.
== 7 of 7 ==
Date: Sun, Jan 31 2010 5:35 pm
From: "Leigh Johnston"
"�� Tiib" <ootiib@hot.ee> wrote in message
news:14afcc94-19e6-4024-a8d6-425716d430d4@o28g2000yqh.googlegroups.com...
> On Feb 1, 12:14 am, "Leigh Johnston" <le...@i42.co.uk> wrote:
>> >> If 0xFFFFFFFF or -1 is detected, then exception will be
>> >> thrown.
>>
>> > (Again, -1 cannot be detected, because it cannot be represented
>> > on the type of the argument.)
>>
>> assert(static_cast<unsigned int>(-1) == -1);
>>
>> :)
>>
>> /Leigh
>
> Anyway you get diagnostic warnings for it from most compilers. If
> 'static_cast<unsigned int>(-1)' is needed then '~0U' is perhaps
> shortest form that makes all compilers happy with it.
Neither VC++ nor g++ complain, two of the most popular compilers.
/Leigh
==============================================================================
TOPIC: C++0x regex supported by gcc?
http://groups.google.com/group/comp.lang.c++/t/a5e3fb25be9236a9?hl=en
==============================================================================
== 1 of 2 ==
Date: Sun, Jan 31 2010 9:08 am
From: mattia
Hi all, do you know if gcc supports the regex library defined in the C+
+0x draft? If so, which version? Can you provide a simple snippet?
Thanks, Mattia
== 2 of 2 ==
Date: Sun, Jan 31 2010 9:43 am
From: Robert Fendt
> Hi all, do you know if gcc supports the regex library defined in the C+
> +0x draft? If so, which version? Can you provide a simple snippet?
As far as I know, GCC does not support regular expressions as defined in TR1 as part of its standard library (yet). However, to use 0x features already before standardisation would be a portability nightmare (not to speak of stability issues to be expected in the early implementations).
If you want to stay at least semi-portable and need a solid regex library for C++, just use boost::regex for now. The TR1 specification is based upon it anyway. Or, if you are concerned about code changes after the compilers have caught up with the standard, you can use boost::tr1.
http://www.boost.org/doc/libs/1_41_0/libs/regex/doc/html/index.html
http://www.boost.org/doc/libs/1_41_0/doc/html/boost_tr1.html
Regards,
Robert
==============================================================================
TOPIC: Escape a string to bytes
http://groups.google.com/group/comp.lang.c++/t/0ed981f009a7ba73?hl=en
==============================================================================
== 1 of 9 ==
Date: Sun, Jan 31 2010 10:32 am
From: Philliam Auriemma
Hey guys,
I have a problem. I am building a program that needs to take a string
like "\x20\x21" or something (just the fact that it's hex is
significant) and turn it into a string that has those sequences turned
into 'bytes' or whatever. So, In the previous example, it would take
the string "\x20\x21" and turn it into " !". The source from which I
am getting this string does not provide any way to do this, so I need
the source to pass a C++ dll a string, C++ works on it, and returns
the proper string. The format in which it must be is not \xblah, it
can just be numbers separated by a space, or whatever would be
easiest, like "20 21" etc.
Thanks for any help.
== 2 of 9 ==
Date: Sun, Jan 31 2010 10:54 am
From: ram@zedat.fu-berlin.de (Stefan Ram)
Philliam Auriemma <phil.auriemma@gmail.com> writes:
>the string "\x20\x21" and turn it into " !". The source from which I
The following prints » !«, but I wrote it in C, not C++,
maybe you can translate it to C++.
#include <stdio.h> /* putchar */
#include <ctype.h> /* isxdigit */
void append( unsigned int const value ){ putchar(( int )value ); }
void terminate( void ){ putchar( '\n' ); }
int main( void )
{ const char * const source = "\\x20 21";
for( const char * p = source; *p; )
{ while( !isxdigit( *p ) && *p )++p;
if( *p )
{ unsigned int value; sscanf( p, "%x", &value );
append( value );
while( isxdigit( *p ) && *p )++p; }}
terminate(); }
== 3 of 9 ==
Date: Sun, Jan 31 2010 11:02 am
From: Philliam Auriemma
On Jan 31, 10:54 am, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
> Philliam Auriemma <phil.aurie...@gmail.com> writes:
> >the string "\x20\x21" and turn it into " !". The source from which I
>
> The following prints » !«, but I wrote it in C, not C++,
> maybe you can translate it to C++.
>
> #include <stdio.h> /* putchar */
> #include <ctype.h> /* isxdigit */
>
> void append( unsigned int const value ){ putchar(( int )value ); }
>
> void terminate( void ){ putchar( '\n' ); }
>
> int main( void )
> { const char * const source = "\\x20 21";
> for( const char * p = source; *p; )
> { while( !isxdigit( *p ) && *p )++p;
> if( *p )
> { unsigned int value; sscanf( p, "%x", &value );
> append( value );
> while( isxdigit( *p ) && *p )++p; }}
> terminate(); }
Thanks, I'll try it out right away.
== 4 of 9 ==
Date: Sun, Jan 31 2010 11:49 am
From: Victor Bazarov
Philliam Auriemma wrote:
> I have a problem. I am building a program that needs to take a string
> like "\x20\x21" or something (just the fact that it's hex is
> significant) and turn it into a string that has those sequences turned
> into 'bytes' or whatever. So, In the previous example, it would take
> the string "\x20\x21" and turn it into " !". The source from which I
> am getting this string does not provide any way to do this, so I need
> the source to pass a C++ dll a string, C++ works on it, and returns
> the proper string. The format in which it must be is not \xblah, it
> can just be numbers separated by a space, or whatever would be
> easiest, like "20 21" etc.
I honestly don't understand what the problem is.
std::string space_bang_ascii("\x20\x21");
Perhaps you need to specify it a bit clearer... Try pseudocode.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
== 5 of 9 ==
Date: Sun, Jan 31 2010 12:13 pm
From: Daniel Giaimo
On 1/31/2010 2:49 PM, Victor Bazarov wrote:
> Philliam Auriemma wrote:
>> I have a problem. I am building a program that needs to take a string
>> like "\x20\x21" or something (just the fact that it's hex is
>> significant) and turn it into a string that has those sequences turned
>> into 'bytes' or whatever. So, In the previous example, it would take
>> the string "\x20\x21" and turn it into " !". The source from which I
>> am getting this string does not provide any way to do this, so I need
>> the source to pass a C++ dll a string, C++ works on it, and returns
>> the proper string. The format in which it must be is not \xblah, it
>> can just be numbers separated by a space, or whatever would be
>> easiest, like "20 21" etc.
>
> I honestly don't understand what the problem is.
>
> std::string space_bang_ascii("\x20\x21");
>
> Perhaps you need to specify it a bit clearer... Try pseudocode.
I think he meant that he is reading the string in from somewhere else
and it is known to consist of sequences like "\\x20\\x21", (doubled '\'
to clarify that the string itself contains a '\'), and he wants to
parse the string.
--
Dan G
== 6 of 9 ==
Date: Sun, Jan 31 2010 12:43 pm
From: Philliam Auriemma
On Jan 31, 12:13 pm, Daniel Giaimo <dgia...@gmail.com> wrote:
> On 1/31/2010 2:49 PM, Victor Bazarov wrote:
>
>
>
> > Philliam Auriemma wrote:
> >> I have a problem. I am building a program that needs to take a string
> >> like "\x20\x21" or something (just the fact that it's hex is
> >> significant) and turn it into a string that has those sequences turned
> >> into 'bytes' or whatever. So, In the previous example, it would take
> >> the string "\x20\x21" and turn it into " !". The source from which I
> >> am getting this string does not provide any way to do this, so I need
> >> the source to pass a C++ dll a string, C++ works on it, and returns
> >> the proper string. The format in which it must be is not \xblah, it
> >> can just be numbers separated by a space, or whatever would be
> >> easiest, like "20 21" etc.
>
> > I honestly don't understand what the problem is.
>
> > std::string space_bang_ascii("\x20\x21");
>
> > Perhaps you need to specify it a bit clearer... Try pseudocode.
>
> I think he meant that he is reading the string in from somewhere else
> and it is known to consist of sequences like "\\x20\\x21", (doubled '\'
> to clarify that the string itself contains a '\'), and he wants to
> parse the string.
>
> --
> Dan G
Yeah, actually I am getting them from Lua which does not support
putting hex characters or whatever you call them in strings, so I
would make a DLL to load from Lua that would pass "40 39 20" for
example (since doing "\x40\x39\x20" would do absolutely nothing, and
would probably be an unknown escape sequence), and then the DLL would
return whatever that would equal if you had done "\x40\x39\x20" in C++.
== 7 of 9 ==
Date: Sun, Jan 31 2010 2:45 pm
From: ram@zedat.fu-berlin.de (Stefan Ram)
Philliam Auriemma <phil.auriemma@gmail.com> writes:
>the string "\x20\x21" and turn it into " !". The source from which I
Now, a C++ version:
#include <iostream> /* ::std::cout */
#include <ostream> /* << */
#include <sstream> /* ::std::stringstream */
#include <ios> /* ::std::hex */
int main()
{ char const * const source_ = "\\x20 21";
::std::stringstream source( source_ ), target;
int val; while( !source.eof() )
{ source >> ::std::hex >> val;
if( source.fail() ){ source.clear(); char d; source.get( d ); }
else target <<( char )val; }
::std::cout << target.str() << '\n'; }
== 8 of 9 ==
Date: Sun, Jan 31 2010 7:03 pm
From: Philliam Auriemma
On Jan 31, 2:45 pm, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
> Philliam Auriemma <phil.aurie...@gmail.com> writes:
> >the string "\x20\x21" and turn it into " !". The source from which I
>
> Now, a C++ version:
>
> #include <iostream> /* ::std::cout */
> #include <ostream> /* << */
> #include <sstream> /* ::std::stringstream */
> #include <ios> /* ::std::hex */
>
> int main()
> { char const * const source_ = "\\x20 21";
> ::std::stringstream source( source_ ), target;
> int val; while( !source.eof() )
> { source >> ::std::hex >> val;
> if( source.fail() ){ source.clear(); char d; source.get( d ); }
> else target <<( char )val; }
> ::std::cout << target.str() << '\n'; }
Any idea how I could make it into a 'string' that could contain null
characters?
== 9 of 9 ==
Date: Sun, Jan 31 2010 7:23 pm
From: ram@zedat.fu-berlin.de (Stefan Ram)
Philliam Auriemma <phil.auriemma@gmail.com> writes:
>Any idea how I could make it into a 'string' that could contain null
>characters?
This is already possible with the version you just quoted.
==============================================================================
TOPIC: Again substrings and so on
http://groups.google.com/group/comp.lang.c++/t/736557e5175db0ba?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 31 2010 2:08 pm
From: Paavo Helde
Vicent Giner-Bosch <vginer@gmail.com> wrote in news:61baf361-09b9-4ae1-
9cdd-f619901b3ed6@u41g2000yqe.googlegroups.com:
> My question is this: Is Boost string library too "heavy" to include? I
> mean, if I only use it "for a while", if I am not going to use it "a
> lot", is it worthy to use it? I DO think so, but I would like to read
> more opinions...
If you have any plans to continue to write code in C++ in the future, then
I would suggest to make use of Boost libraries as much as possible. It
might take some effort to learn how to use them, but the benefits are that
the Boost libraries are generally of much higher quality than a C++
beginner would be able to code by himself, and the code will be easier to
grok for another programmer.
Paavo
==============================================================================
TOPIC: isspace
http://groups.google.com/group/comp.lang.c++/t/89ca303518428e34?hl=en
==============================================================================
== 1 of 4 ==
Date: Sun, Jan 31 2010 2:27 pm
From: gervaz
On Jan 31, 2:17 pm, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
> gervaz <ger...@gmail.com> wrote innews:a5a4ece2-5b9d-4846-a818-9de61c130654@r24g2000yqd.googlegroups.com:
>
>
>
> > On Jan 31, 10:39 am, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
> >> Paavo Helde <myfirstn...@osa.pri.ee> wrote
> >> innews:Xns9D116950C4paavo256@2
> > 16.196.109.131:
>
> >> > gervaz <ger...@gmail.com> wrote in news:f9eec1c9-5570-461a-bdec-
> >> > 6dec26dab...@o28g2000yqh.googlegroups.com:
>
> >> >> On Jan 30, 1:15 pm, James Kanze <james.ka...@gmail.com> wrote:
> >> >>> On Jan 30, 12:05 pm, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
>
> >> >>> > James Kanze <james.ka...@gmail.com> writes:
> >> >>> > >There are no standard names for locales
> >> >>> > AFAIK, C90 defines a locale by the name of "C",
> >> >>> > which should also be visible from C++.
>
> >> >>> And Posix defines "POSIX". Neither of which are really useful
> >> >>> for anything.
>
> >> >>> --
> >> >>> James Kanze
>
> >> >> Ok, so I think that I will open my file specifying to use UTF-8
> >> >> encoding, but how can I do it in C++?
>
> >> > You can open it as a narrow stream and read in as binary UTF-8, or
> >> > (maybe) you can open it as a wide stream and get an automatic
> >> > translation from UTF-8 to wchar_t. The following example assumes
> >> > that you have a file test1.utf containing valid UTF-8 text. It
> >> > reads the file in as a wide stream and prints out the numeric
> >> > values of all wchar_t characters.
>
> >> > #include <iostream>
> >> > #include <fstream>
> >> > #include <locale>
> >> > #include <string>
>
> >> > int main() {
> >> > std::wifstream is;
> >> > const std::locale filelocale("en_US.UTF8");
> >> > is.imbue(filelocale);
> >> > is.open("test1.utf8");
>
> >> > std::wstring s;
> >> > while(std::getline(is, s)) {
> >> > for (std::wstring::size_type j=0; j<s.length(); ++j)
> > {
> >> > std::cout << s[j] << " ";
> >> > }
> >> > std::cout << "\n";
> >> > }
> >> > }
>
> >> > (Tested on Linux with a recent gcc, I am not too sure if this works
> >> > on Windows. First, wchar_t in MSVC is too narrow for real Unicode,
> >> > at best one might get UTF-16 as a result.)
>
> >> For curiosity, I tested this also on Windows with MSVC9, and as
> >> expected it did not work, the locale construction immediately threw
> >> an exception (bad locale name). Neither did any alterations work
> >> ("english.UTF8", ".UTF8", ".utf-8", ".65001").
>
> >> Thus, if one wants any portability it seems the best approach
> >> currently is still to read in binary UTF-8 and perform any needed
> >> conversions by hand.
>
> >> Paavo
>
> > Under Windows, you have to use const std::locale filelocale
> > ("English_Australia.1252") according to
> >http://docs.moodle.org/en/Table_of_locales, I've tested it in VC++08
> > and it works. Any suggestion in how to handle the dualism?
>
> Did you actually test the results? It seems this is reading UTF-8 in
> unaltered, so there is no point to use a wide stream in the first place.
>
> Paavo
Well, yeah, although using an example file like
http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt and using
plain std::string, std::ifstream and std::cout everything works fine,
if I put the 'w' in front of all this types the sysout fails
producing:
UTF-8 encoded sample plain-text file
Γ
Why??
== 2 of 4 ==
Date: Sun, Jan 31 2010 4:02 pm
From: Öö Tiib
On Feb 1, 12:27 am, gervaz <ger...@gmail.com> wrote:
> On Jan 31, 2:17 pm, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
>
>
>
>
>
> > gervaz <ger...@gmail.com> wrote innews:a5a4ece2-5b9d-4846-a818-9de61c130654@r24g2000yqd.googlegroups.com:
>
> > > On Jan 31, 10:39 am, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
> > >> Paavo Helde <myfirstn...@osa.pri.ee> wrote
> > >> innews:Xns9D116950C4paavo256@2
> > > 16.196.109.131:
>
> > >> > gervaz <ger...@gmail.com> wrote in news:f9eec1c9-5570-461a-bdec-
> > >> > 6dec26dab...@o28g2000yqh.googlegroups.com:
>
> > >> >> On Jan 30, 1:15 pm, James Kanze <james.ka...@gmail.com> wrote:
> > >> >>> On Jan 30, 12:05 pm, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
>
> > >> >>> > James Kanze <james.ka...@gmail.com> writes:
> > >> >>> > >There are no standard names for locales
> > >> >>> > AFAIK, C90 defines a locale by the name of "C",
> > >> >>> > which should also be visible from C++.
>
> > >> >>> And Posix defines "POSIX". Neither of which are really useful
> > >> >>> for anything.
>
> > >> >>> --
> > >> >>> James Kanze
>
> > >> >> Ok, so I think that I will open my file specifying to use UTF-8
> > >> >> encoding, but how can I do it in C++?
>
> > >> > You can open it as a narrow stream and read in as binary UTF-8, or
> > >> > (maybe) you can open it as a wide stream and get an automatic
> > >> > translation from UTF-8 to wchar_t. The following example assumes
> > >> > that you have a file test1.utf containing valid UTF-8 text. It
> > >> > reads the file in as a wide stream and prints out the numeric
> > >> > values of all wchar_t characters.
>
> > >> > #include <iostream>
> > >> > #include <fstream>
> > >> > #include <locale>
> > >> > #include <string>
>
> > >> > int main() {
> > >> > std::wifstream is;
> > >> > const std::locale filelocale("en_US.UTF8");
> > >> > is.imbue(filelocale);
> > >> > is.open("test1.utf8");
>
> > >> > std::wstring s;
> > >> > while(std::getline(is, s)) {
> > >> > for (std::wstring::size_type j=0; j<s.length(); ++j)
> > > {
> > >> > std::cout << s[j] << " ";
> > >> > }
> > >> > std::cout << "\n";
> > >> > }
> > >> > }
>
> > >> > (Tested on Linux with a recent gcc, I am not too sure if this works
> > >> > on Windows. First, wchar_t in MSVC is too narrow for real Unicode,
> > >> > at best one might get UTF-16 as a result.)
>
> > >> For curiosity, I tested this also on Windows with MSVC9, and as
> > >> expected it did not work, the locale construction immediately threw
> > >> an exception (bad locale name). Neither did any alterations work
> > >> ("english.UTF8", ".UTF8", ".utf-8", ".65001").
>
> > >> Thus, if one wants any portability it seems the best approach
> > >> currently is still to read in binary UTF-8 and perform any needed
> > >> conversions by hand.
>
> > >> Paavo
>
> > > Under Windows, you have to use const std::locale filelocale
> > > ("English_Australia.1252") according to
> > >http://docs.moodle.org/en/Table_of_locales, I've tested it in VC++08
> > > and it works. Any suggestion in how to handle the dualism?
>
> > Did you actually test the results? It seems this is reading UTF-8 in
> > unaltered, so there is no point to use a wide stream in the first place.
>
> > Paavo
>
> Well, yeah, although using an example file likehttp://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txtand using
> plain std::string, std::ifstream and std::cout everything works fine,
> if I put the 'w' in front of all this types the sysout fails
> producing:
>
> UTF-8 encoded sample plain-text file
> Γ
>
> Why??
Because C++ does not convert from UTF-8 to UTF-16 just like that.
UTF-8 fits into std::string. std::wstring is UTF-16 when sizeof
(wchar_t) is 2 and UTF-32 when sizeof(wchar_t) is 4. The support for
character portability is weak in STL, not sure why. Also POSIX
functions do not help much since most implementations were made before
Unicode was defined.
If you really want to convert then use platforms support. Most
platforms support Unicode (for example MultiByteToWideChar() in
Windows). If you want portable solution then use library that is
capable to provide conversions like ICU. http://site.icu-project.org/
== 3 of 4 ==
Date: Sun, Jan 31 2010 5:31 pm
From: "Leigh Johnston"
>
> The functions in <locale> are pretty useless, since they only
> handle single byte characters. The "approved" solution is to
> read into a wstring using wifstream (embedded with the
> appropriate locale), and use isspace (again with the appropriate
> locale) on the wchar_t in the wstring.
>
> --
> James Kanze
You might want to use a custom codecvt facet with that otherwise you are
just reading bytes and converting them to wchar_t which is not what you want
I don't think.
/Leigh
== 4 of 4 ==
Date: Sun, Jan 31 2010 6:29 pm
From: "Leigh Johnston"
"Leigh Johnston" <leigh@i42.co.uk> wrote in message
news:PdmdneKVNOF6s_vWnZ2dnUVZ7tydnZ2d@giganews.com...
>>
>> The functions in <locale> are pretty useless, since they only
>> handle single byte characters. The "approved" solution is to
>> read into a wstring using wifstream (embedded with the
>> appropriate locale), and use isspace (again with the appropriate
>> locale) on the wchar_t in the wstring.
>>
>> --
>> James Kanze
>
> You might want to use a custom codecvt facet with that otherwise you are
> just reading bytes and converting them to wchar_t which is not what you
> want I don't think.
>
Never mind, if the locale is correct it should do multibyte conversion
correctly.
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en
To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
No comments:
Post a Comment