public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: peturr02@ru.is To: gcc-gnats@gcc.gnu.org Subject: libstdc++/9027: codecvt example from The C++ Programming Language does not work. Date: Fri, 20 Dec 2002 07:16:00 -0000 [thread overview] Message-ID: <20021220150553.17393.qmail@sources.redhat.com> (raw) >Number: 9027 >Category: libstdc++ >Synopsis: codecvt example from The C++ Programming Language does not work. >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Fri Dec 20 07:16:14 PST 2002 >Closed-Date: >Last-Modified: >Originator: peturr02@ru.is >Release: gcc-3.2.1 >Organization: >Environment: Red Hat Linux 8.0 on i686; glibc-2.2.93 >Description: In appendix D of The C++ Programming Language, 3rd edition <http://www.research.att.com/~bs/3rd_loc.pdf> Stroustrup describes a codecvt facet that converts input to uppercase. This example doesn't work on gcc-3.2.1, as basic_filebuf<char> never calls codecvt<char, char, mbstate_t>::in(). >How-To-Repeat: See attachment for a modified version of the example. >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: text/plain; name="charupper.cc" Content-Disposition: inline; filename="charupper.cc" #include <locale> #include <algorithm> #include <cstddef> #include <cstdio> #include <string> #include <fstream> #include <iostream> using namespace std; class Cvt_to_upper : public codecvt<char, char, mbstate_t> { typedef codecvt<char, char, mbstate_t> Base; public: explicit Cvt_to_upper(size_t refs = 0) : Base(refs) { } protected: result do_in(state_type&, const extern_type* from, const extern_type* from_end, const extern_type*& from_next, intern_type* to, intern_type* to_end, intern_type*& to_next) const { while (from < from_end && to < to_end) *to++ = toupper(*from++); to_next = to; from_next = from; return from == from_end ? ok : partial; } bool do_always_noconv() const throw() { return false; } }; int main() { locale loc1; locale loc (loc1, new Cvt_to_upper); char name[] = "charupperXXXXXX"; mktemp(name); string str ("abcdefghijklmnopqrstuvwxyz"); string tmp; { ofstream out (name); copy(str.begin(), str.end(), ostreambuf_iterator<char>(out)); } { ifstream in; in.imbue(loc); in.open(name); copy(istreambuf_iterator<char>(in), istreambuf_iterator<char>(), back_inserter(tmp)); } remove(name); cout << tmp << endl; assert(tmp.size() == str.size()); for (size_t i = 0; i < tmp.size(); ++i) assert(isupper(tmp[i])); return 0; }
next reply other threads:[~2002-12-20 15:16 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-12-20 7:16 peturr02 [this message] 2002-12-21 7:45 paolo 2003-05-16 19:58 bkoz 2003-05-16 22:36 Giovanni Bajo 2003-05-16 23:46 Benjamin Kosnik
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20021220150553.17393.qmail@sources.redhat.com \ --to=peturr02@ru.is \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).