Portable 'lowercase' function for stl string?

S

Steve Edwards

Hi,
I'm re-writing some code that had relied on some platform/third-party
dependent utility functions, as I want to make it more portable.
Is there a standard C/C++/stl routine for changing an stl string to all
lowercase?
(I know how to do it manually, but in the interests of portability...)

Thanks

Steve
 
L

loufoque

Steve Edwards a écrit :
Hi,
I'm re-writing some code that had relied on some platform/third-party
dependent utility functions, as I want to make it more portable.
Is there a standard C/C++/stl routine for changing an stl string to all
lowercase?

I think it depends on the locale.
To be portable you could use your own implementation of that kind of
functions according to the character set of your choice (Unicode would
be a good one).
 
P

Pete Becker

loufoque said:
I think it depends on the locale.
To be portable you could use your own implementation of that kind of
functions according to the character set of your choice (Unicode would
be a good one).

Unicode would be a poor choice if, for example, your characters are
encoded in ASCII and you care about speed. Case conversions (and just
about any other character manipulation) in Unicode can be rather slow,
because of the size of the character set and the resulting complexity of
the data representation for character attributes (you really don't want
to carry around a bunch of 64K arrays). With ASCII, on the other hand,
converting to lowercase is just a test and an addition.
 
A

Alf P. Steinbach

* Pete Becker:
Unicode would be a poor choice if, for example, your characters are
encoded in ASCII and you care about speed. Case conversions (and just
about any other character manipulation) in Unicode can be rather slow,
because of the size of the character set and the resulting complexity of
the data representation for character attributes (you really don't want
to carry around a bunch of 64K arrays). With ASCII, on the other hand,
converting to lowercase is just a test and an addition.

I think that's incorrect.

To convince me otherwise, could you give an example where case
conversion of an arbitrary ASCII text is necessarily faster than the
same case conversion of the same text in fixed a size per character
Unicode representation (e.g. USC2 limited to BMP, or USC4)?

Consider that ASCII is a subset of Unicode.
 
S

Steve Edwards

Pete Becker said:
Unicode would be a poor choice if, for example, your characters are
encoded in ASCII and you care about speed. Case conversions (and just
about any other character manipulation) in Unicode can be rather slow,
because of the size of the character set and the resulting complexity of
the data representation for character attributes (you really don't want
to carry around a bunch of 64K arrays). With ASCII, on the other hand,
converting to lowercase is just a test and an addition.

Thanks, ASCII is fine for my needs, I'll do it manually. (I'm just
surprised, given how many equally simple tasks _do_ have a defined
library function.)

Steve
 
R

Rolf Magnus

Steve said:
Hi,
I'm re-writing some code that had relied on some platform/third-party
dependent utility functions, as I want to make it more portable.
Is there a standard C/C++/stl routine for changing an stl string to all
lowercase?
(I know how to do it manually, but in the interests of portability...)

Well, there is no unique way. A simple solution is to use a loop that calls
std::tolower for each character, but this doesn't work for every locale,
since in many languages, some letters don't have a straight 1:1 mapping
between lower case and upper case.
 
P

Pete Becker

Alf said:
* Pete Becker:



I think that's incorrect.

To convince me otherwise, could you give an example where case
conversion of an arbitrary ASCII text is necessarily faster than the
same case conversion of the same text in fixed a size per character
Unicode representation (e.g. USC2 limited to BMP, or USC4)?

Consider that ASCII is a subset of Unicode.

Case conversions in Unicode can't assume that the characters they're
dealing with are ASCII.
 
P

Pete Becker

Steve said:
Thanks, ASCII is fine for my needs, I'll do it manually. (I'm just
surprised, given how many equally simple tasks _do_ have a defined
library function.)

If you're only interested in the native character set, you've got the
builtin C functions toupper and tolower. You can also do some stuff with
C++ locales to get the same result.
 
A

Alf P. Steinbach

* Pete Becker:
Case conversions in Unicode can't assume that the characters they're
dealing with are ASCII.

Well, that's not much of an example! ;-)

To quote yourself, again, "With ASCII, converting to lowercase is just a
test and an addition".

How would it be more if the same text is represented in UCS2 or UCS4?
 
P

Pete Becker

Alf said:
* Pete Becker:



Well, that's not much of an example! ;-)

It wasn't meant to be. You misrepresented what I said, and I gave an
accurate response.
To quote yourself, again, "With ASCII, converting to lowercase is just a
test and an addition".

How would it be more if the same text is represented in UCS2 or UCS4?

Read what I said again, this time without the attitude. But don't bother
replying, because I don't have any more time to waste on your sophomoric
games.
 
P

Pete Becker

Pete said:
If you're only interested in the native character set, you've got the
builtin C functions toupper and tolower. You can also do some stuff with
C++ locales to get the same result.

Whoops, sorry, got distracted by the noise. You undoubtedly know about
these. Yes, you have to call them multiple times to transform a text
seqquence.
 
A

Alf P. Steinbach

* Pete Becker:
It wasn't meant to be. You misrepresented what I said, and I gave an
accurate response.


Read what I said again, this time without the attitude. But don't bother
replying, because I don't have any more time to waste on your sophomoric
games.

That's the second time in a row you've elected to use a personal attack
when cornered in a technical matter, Pete.

Are you the same Pete Becker who used to work at Dinkumware, and was
technically able and courteous?
 
P

Pete Becker

Alf said:
That's the second time in a row you've elected to use a personal attack
when cornered in a technical matter, Pete.

I wasn't aware that I had been "cornered." You claimed that what I said
wasn't correct, but didn't say why. You did, however, misrepresent what
I said, and you have not corrected that. That's all that needs to be said.
 
A

Alf P. Steinbach

* Pete Becker:
I wasn't aware that I had been "cornered." You claimed that what I said
wasn't correct, but didn't say why. You did, however, misrepresent what
I said, and you have not corrected that. That's all that needs to be said.

What you wrote earlier was technically incorrect, at the novice level,
and when questioned you offered an ad hominem attack in response.

What you write now is, as I count them, four lies.

Are you the same Pete Becker who used to work at Dinkumware, and was
technically able and courteous?
 
P

P.J. Plauger

* Pete Becker:

What you wrote earlier was technically incorrect, at the novice level, and
when questioned you offered an ad hominem attack in response.

What you write now is, as I count them, four lies.

Are you the same Pete Becker who used to work at Dinkumware, and was
technically able and courteous?

Back off, Dude. I just reviewed this entire exchange and can
attest that everything Pete said was accurate. To accuse
*anybody* in this forum of lying is way out of line.

And yes, this is the same Pete Becker who used to be an employee
of Dinkumware and still works with Dinkumware. IM(extensive)E
he remains technically able and courteous.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 
A

Alf P. Steinbach

* P.J. Plauger:
Back off, Dude. I just reviewed this entire exchange and can
attest that everything Pete said was accurate. To accuse
*anybody* in this forum of lying is way out of line.

It's natural to defend one's friends.

But I don't think it's a good idea to want to be associated with his
slights and ad hominem attacks, nor the tecnical level of competence he
displayed here.

You know well that Pete has not been accurate in even one sentence in
this thread, from the point of not-answering my question, and you know
well that I'm not the kind of person to let a second such attack in a
row (as this was) go by, turning the other cheek, as I did with the
first, no matter how much respect I have had for the person previously.
 
S

Squeamizh

P.J. Plauger said:
Back off, Dude. I just reviewed this entire exchange and can
attest that everything Pete said was accurate. To accuse
*anybody* in this forum of lying is way out of line.

For those of us who are interested in learning more, I'll engage.
Since you've put yourself on the spot and attested to Pete's accuracy,
would you please briefly explain how Pete's original response is
correct?
 
I

Ivan Vecerina

:* Pete Becker:
: > Alf P. Steinbach wrote:
: >>
: >> That's the second time in a row you've elected to use a personal
: >> attack when cornered in a technical matter, Pete.
: >
: > I wasn't aware that I had been "cornered." You claimed that what I
said
: > wasn't correct, but didn't say why. You did, however, misrepresent
what
: > I said, and you have not corrected that. That's all that needs to be
said.
:
: What you wrote earlier was technically incorrect, at the novice level,
: and when questioned you offered an ad hominem attack in response.
:
: What you write now is, as I count them, four lies.
:
: Are you the same Pete Becker who used to work at Dinkumware, and was
: technically able and courteous?

I only know Pete from this NG. He definitely is technically able,
but I never found him to be excessively courteous (or patient).
This being given, I think we can accept him as he is, take the
good and leave the rest.

I don't think this is worth much of an argument. I assume that,
for non-ASCII, Pete was thinking of converting the case of the
many letters with diacritical marks, and those of non-latin
alphabets. This reasonably seems to require more work...

Peace,
Ivan
 
P

Pete Becker

Squeamizh said:
For those of us who are interested in learning more, I'll engage.
Since you've put yourself on the spot and attested to Pete's accuracy,
would you please briefly explain how Pete's original response is
correct?

Look, it's simple: I said that case conversions under Unicode can be
rather slow compared to straight ASCII, and Alf challenged me to prove
that they're always slower. I declined to try to prove something that I
didn't say.
 
P

Pete Becker

Pete Becker wrote:

Whoops, better correct that before I get accused again of lying:
Look, it's simple: I said that case conversions


of characters in the ASCII character set
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,647
Latest member
NelleMacy9

Latest Threads

Top