Topic: Feature Request for ios_base::capitali{s,z}e
Author: ao@shell.core.com (Mike Harrold)
Date: Wed, 14 Nov 2001 18:23:03 GMT Raw View
Hi,
Apologies if this has been requested before, but I didn't find any prior
mention of it. If discussion on this topic has happened before I would
appreciate a pointer to such.
One of the things I have found "missing" from streams is the ability to
capitalise the next letter of a word. std::ios_base contains both
uppercase and lowercase, but those work on the entire input.
While I understand that I can expand an (eg) output stream class and
implement this myself (which I do), I am sure many folks would find this
additional feature useful.
Thank you for your consideration,
/Mike
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Thu, 15 Nov 2001 16:56:47 GMT Raw View
Mike Harrold wrote:
...
> One of the things I have found "missing" from streams is the ability to
> capitalise the next letter of a word. std::ios_base contains both
> uppercase and lowercase, but those work on the entire input.
'uppercase' and 'lowercase' have only a very restricted application. See
22.2.2.1.2p4: "For conversion to an integral type, the function
determines the integral conversion specifier ...". In other words,
cout << hex << lowercase << 16 << uppercase << 16 << endl;
Should produce "0x10 0X10\n".
> While I understand that I can expand an (eg) output stream class and
> implement this myself (which I do), I am sure many folks would find this
> additional feature useful.
std::toupper() and std::tolower() are the relevant functions for single
character conversion. if you need to convert more than one character at
a time, you should look at the ctype class; it has toupper() and
tolower() member functions specialized to convert strings of characters,
as well as individual characters.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: ao@shell.core.com (Mike Harrold)
Date: Thu, 15 Nov 2001 21:46:13 GMT Raw View
In article <3BF328D3.1BD8D2B5@wizard.net>,
James Kuyper Jr. <kuyper@wizard.net> wrote:
>Mike Harrold wrote:
>...
>> One of the things I have found "missing" from streams is the ability to
>> capitalise the next letter of a word. std::ios_base contains both
>> uppercase and lowercase, but those work on the entire input.
>
>'uppercase' and 'lowercase' have only a very restricted application. See
>22.2.2.1.2p4: "For conversion to an integral type, the function
>determines the integral conversion specifier ...". In other words,
>
>cout << hex << lowercase << 16 << uppercase << 16 << endl;
>
>Should produce "0x10 0X10\n".
It might if "hex" was valid ;-)
>
>
>> While I understand that I can expand an (eg) output stream class and
>> implement this myself (which I do), I am sure many folks would find this
>> additional feature useful.
>
>std::toupper() and std::tolower() are the relevant functions for single
>character conversion. if you need to convert more than one character at
>a time, you should look at the ctype class; it has toupper() and
>tolower() member functions specialized to convert strings of characters,
>as well as individual characters.
You're not understanding what I would like to see. Take the following:
viewer << "Information for " << get_subject_name(TP_MATH)
<< '.' << std::endl
<< get_intro_text(TP_MATH);
viewer.setf(std::ios_base::cap); // or, viewer << std::cap;
viewer << get_subject_name(TP_MATH) << " will be held on "
<< get_class_day(TP_MATH) << '.' << std::endl;
The function get_subject_name() returns the name of a subject (eg, math,
history, geography, etc.). That name is returned in lower case. However,
the second occurrence needs to be capitalised as it's the beginning of a
new sentence.
If get_subject_name() is defined as:
const std::string& get_subject_name(eSubjectType);
then the only way I can capitalise it myself is to copy it into another
string and then use std::toupper() which is inefficient. Either that or
write an extension to the o(string)stream class to implement my own
capitalisation function, which is even more inefficient, not to mention
very time consuming.
Anyway, it seems such a useful function and it would be nice to see it
added to the streams part of the standard.
/Mike
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]