Author: sebor
Date: Mon Apr 30 10:12:37 2007
New Revision: 533806
URL: http://svn.apache.org/viewvc?view=rev&rev=533806
Log:
2007-04-30 Martin Sebor <[EMAIL PROTECTED]>
* codecvt.cpp (main): Zero-initialized mbstate_t variable
before passing it to codecvt::in() and codecvt::out().
Replaced std::endl with '\n' for efficiency.
Modified:
incubator/stdcxx/trunk/examples/manual/codecvt.cpp
Modified: incubator/stdcxx/trunk/examples/manual/codecvt.cpp
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/manual/codecvt.cpp?view=diff&rev=533806&r1=533805&r2=533806
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/codecvt.cpp (original)
+++ incubator/stdcxx/trunk/examples/manual/codecvt.cpp Mon Apr 30 10:12:37 2007
@@ -2,20 +2,27 @@
*
* codecvt.cpp - Example program of codecvt facet.
*
- * $Id: //stdlib/dev/examples/stdlib/manual/codecvt.cpp#14 $
+ * $Id$
*
***************************************************************************
*
- * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave
- * Software division. Licensed under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0. Unless required by
- * applicable law or agreed to in writing, software distributed under
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
- * CONDITIONS OF ANY KIND, either express or implied. See the License
- * for the specific language governing permissions and limitations under
- * the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1998-2006 Rogue Wave Software.
*
**************************************************************************/
@@ -26,8 +33,8 @@
int main ()
{
- // not used, must be supplied to facet
- std::mbstate_t state;
+ // not used, must be zero-initialized and supplied to facet
+ std::mbstate_t state = std::mbstate_t ();
// three strings to use as buffers
std::string ins ("\xfc \xcc \xcd \x61 \xe1 \xd9 \xc6 \xe6 \xf5");
@@ -36,9 +43,9 @@
// Print initial contents of buffers
std::cout << "Before:\n"
- << ins << std::endl
- << ins2 << std::endl
- << outs << std::endl << std::endl;
+ << ins << '\n'
+ << ins2 << '\n'
+ << outs << '\n' << '\n';
// Create a user defined codecvt fact
// This facet converts from ISO Latin Alphabet No. 1 (ISO 8859-1)
@@ -62,19 +69,21 @@
&outs [0], &outs [0] + outs.length (), out_next);
std::cout << "After in:\n"
- << ins << std::endl
- << ins2 << std::endl
- << outs << std::endl << std::endl;
+ << ins << '\n'
+ << ins2 << '\n'
+ << outs << "\n\n";
- // Finally, convert back to the original codeset
+ // zero-initialize (unused) state object
+ state = std::mbstate_t ();
+ // Finally, convert back to the original codeset
cdcvt.out (state, outs.c_str (), outs.c_str () + outs.length (),
const_out_next, &ins [0], &ins [0] + ins.length (), in_next);
std::cout << "After out:\n"
- << ins << std::endl
- << ins2 << std::endl
- << outs << std::endl;
+ << ins << '\n'
+ << ins2 << '\n'
+ << outs << '\n';
return 0;
}