Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Convert input to lower case? (http://www.velocityreviews.com/forums/t958861-convert-input-to-lower-case.html)

eli m 03-20-2013 03:39 AM

Convert input to lower case?
 
Hi guys, I have a program where it gets input and assigns it to a string. How do I make the input get converted into lowercase? Thanks in advance!

Ian Collins 03-20-2013 04:24 AM

Re: Convert input to lower case?
 
eli m wrote:
> Hi guys, I have a program where it gets input and assigns it to a
> string. How do I make the input get converted into lowercase? Thanks
> in advance!


Look up std::transform and tolower.

--
Ian Collins

James Kanze 03-20-2013 01:00 PM

Re: Convert input to lower case?
 
On Wednesday, 20 March 2013 10:18:08 UTC, robert...@yahoo.com wrote:
> On Wed, 20 Mar 2013 08:46:21 +0000 (UTC), Juha Nieminen


> <nospam@thanks.invalid> wrote:
> >Ian Collins <ian-news@hotmail.com> wrote:
> >> eli m wrote:
> >>> Hi guys, I have a program where it gets input and assigns it to a
> >>> string. How do I make the input get converted into lowercase? Thanks
> >>> in advance!


> >> Look up std::transform and tolower.


> >You are assuming ASCII.


> tolower doesn't assume ASCII.


But it does assume single byte encodings, no UTF-8. (And of
course, it also supposes that tolower has a reasonable
definition. It won't work with German, for example, where the
lower case of "SS" may be either "ss" or "", depending on
context, or in some conventions of French, where the lower case
of "E" may be "", "", "", "" or "e", depending on context.
The idea of converting a string to lower case with a linguistic
context is non-trivial, and may not even be possible.)

More to the point, of course, there are a couple of very subtle
issues when using std::transform and tolower. You can't simply
pass the tolower from <ctype.h> to std::transform, at least if
you're iterating over char, because the tolower in <ctype.h>
results in undefined behavior when called with a char. And once
you include <locale>, you get all sorts of issues regarding
ambiguity. (And of course, you don't always know whether
<locale> has been included or not.)

--
James

osmium 03-20-2013 03:58 PM

Re: Convert input to lower case?
 
James Kanze wrote:
> On Wednesday, 20 March 2013 10:18:08 UTC, robert...@yahoo.com wrote:
>> On Wed, 20 Mar 2013 08:46:21 +0000 (UTC), Juha Nieminen

>
>> <nospam@thanks.invalid> wrote:
>>> Ian Collins <ian-news@hotmail.com> wrote:
>>>> eli m wrote:
>>>>> Hi guys, I have a program where it gets input and assigns it to a
>>>>> string. How do I make the input get converted into lowercase?
>>>>> Thanks in advance!

>
>>>> Look up std::transform and tolower.

>
>>> You are assuming ASCII.

>
>> tolower doesn't assume ASCII.

>
> But it does assume single byte encodings, no UTF-8. (And of
> course, it also supposes that tolower has a reasonable
> definition. It won't work with German, for example, where the
> lower case of "SS" may be either "ss" or "", depending on
> context, or in some conventions of French, where the lower case
> of "E" may be "", "", "", "" or "e", depending on context.
> The idea of converting a string to lower case with a linguistic
> context is non-trivial, and may not even be possible.)
>
> More to the point, of course, there are a couple of very subtle
> issues when using std::transform and tolower. You can't simply
> pass the tolower from <ctype.h> to std::transform, at least if
> you're iterating over char, because the tolower in <ctype.h>
> results in undefined behavior when called with a char. And once
> you include <locale>, you get all sorts of issues regarding
> ambiguity. (And of course, you don't always know whether
> <locale> has been included or not.)


That finally answers a long term nagging question I have had.

I used to correspond with a woman in Germany. I would compose my letters in
English and send them to an instructor (who spoke with a German accent) at a
nearby university. She would translate to German and send it back to me.
One problem was she has a Mac and I had a PC. I couldn't persuade her to
use .rtf format (I thought that was the right way to approach this
situation). Anyway she used some damn Mac format thing I had to convert to
PC ese, and then make and send a hard copy to my correspondent in Germany.
My clue to whether things were going well was the , since it stands out
like a sore thumb. Then the started disappearing! I called her and asked
what was going on. She said, "Oh, the use of esset is downplayed nowadays."
Reluctantly she humored me by using the esset when sending something to me.

The upshot was I got interested in what was the glyph for the lower case .
So your answer is "There is none!"". So now I know. I think.



Victor Bazarov 03-20-2013 04:09 PM

Re: Convert input to lower case?
 
On 3/20/2013 11:58 AM, osmium wrote:
>[..]
> The upshot was I got interested in what was the glyph for the lower case .
> So your answer is "There is none!"". So now I know. I think.


Uh... The "" *is* the lower case. :-) The *upper*case is SS.

V
--
I do not respond to top-posted replies, please don't ask

osmium 03-20-2013 04:18 PM

Re: Convert input to lower case?
 
"Victor Bazarov" wrote:

> On 3/20/2013 11:58 AM, osmium wrote:
>>[..]
>> The upshot was I got interested in what was the glyph for the lower case
>> .
>> So your answer is "There is none!"". So now I know. I think.

>
> Uh... The "" *is* the lower case. :-) The *upper*case is SS.


Oops. Thanks, Victor.

It just *looks* so upper case. The first time I saw it I thought it was a
Greek upper case beta.

We Americans are quite insular. But you probably already knew that.



Victor Bazarov 03-20-2013 06:23 PM

Re: Convert input to lower case?
 
On 3/20/2013 12:18 PM, osmium wrote:
> "Victor Bazarov" wrote:
>
>> On 3/20/2013 11:58 AM, osmium wrote:
>>> [..]
>>> The upshot was I got interested in what was the glyph for the lower case
>>> .
>>> So your answer is "There is none!"". So now I know. I think.

>>
>> Uh... The "" *is* the lower case. :-) The *upper*case is SS.

>
> Oops. Thanks, Victor.
>
> It just *looks* so upper case. The first time I saw it I thought it was a
> Greek upper case beta.


You're going to hate me... It's actually a *lowercase* beta. The
uppercase beta looks just like the Latin/English B.

> We Americans are quite insular. But you probably already knew that.


What do they say? "All generalizations are wrong"... ;-)

V
--
I do not respond to top-posted replies, please don't ask

Stefan Ram 03-20-2013 11:35 PM

Re: Convert input to lower case?
 
Victor Bazarov <v.bazarov@comcast.invalid> writes:
>On 3/20/2013 11:58 AM, osmium wrote:
>>[..]
>> The upshot was I got interested in what was the glyph for the lower case .
>> So your answer is "There is none!"". So now I know. I think.

>Uh... The "" *is* the lower case. :-) The *upper*case is SS.


Some rule guides recommend to use SZ when SS would be ambiguous.

Ich trinke in Massen. I mass-drink (drink huge amounts).
Ich trinke in Maen. I drink moderately.

--> "ICH TRINKE IN MASSEN."


Ian Collins 03-21-2013 02:57 AM

Re: Convert input to lower case?
 
osmium wrote:
> "Victor Bazarov" wrote:
>
>> On 3/20/2013 11:58 AM, osmium wrote:
>>> [..]
>>> The upshot was I got interested in what was the glyph for the lower case
>>> .
>>> So your answer is "There is none!"". So now I know. I think.

>>
>> Uh... The "" *is* the lower case. :-) The *upper*case is SS.

>
> Oops. Thanks, Victor.
>
> It just *looks* so upper case. The first time I saw it I thought it was a
> Greek upper case beta.
>
> We Americans are quite insular. But you probably already knew that.


Us Brits just use std::shout for our translations :)

--
Ian Collins


All times are GMT. The time now is 11:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.