You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2007/05/12 19:32:56 UTC

svn commit: r537492 - /incubator/stdcxx/trunk/doc/stdlibref/money-get.html

Author: sebor
Date: Sat May 12 10:32:55 2007
New Revision: 537492

URL: http://svn.apache.org/viewvc?view=rev&rev=537492
Log:
2007-05-12  Martin Sebor  <se...@roguewave.com>

	STDCXX-411
	* money-get.html: Updated example program to (closely) match
	the latest version of the program in svn and to match shown
	output.

Modified:
    incubator/stdcxx/trunk/doc/stdlibref/money-get.html

Modified: incubator/stdcxx/trunk/doc/stdlibref/money-get.html
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/doc/stdlibref/money-get.html?view=diff&rev=537492&r1=537491&r2=537492
==============================================================================
--- incubator/stdcxx/trunk/doc/stdlibref/money-get.html (original)
+++ incubator/stdcxx/trunk/doc/stdlibref/money-get.html Sat May 12 10:32:55 2007
@@ -165,54 +165,53 @@
 #include &lt;iostream&gt;   // for cout, endl
 #include &lt;iterator&gt;   // for istreambuf_iterator
 
-#include &lt;examples.h&gt;
+int main (int argc, char *argv[])
+{
+    // Get the monetary string and locale from the argument vector.
+    const char* const buffer  = 1 &lt; argc ? argv [1] : "$1,234.6789";
+    const char* const locname = 2 &lt; argc ? argv [2] : "en_US";
+    const bool        intl    = 3 &lt; argc;
 
+    std::string smon;
+    long double fmon = 0.0;
 
-int main ()
-{
-    typedef std::istreambuf_iterator&lt;char,
-            std::char_traits&lt;char&gt; &gt; Iter;
-  
-    const std::string buffer ("$100.02");
-    std::string dest;
-    long double ldest;
-    std::ios_base::iostate state;
-    Iter end;
-
-    // Retrieve the money_get facet from the global locale.
-    const std::money_get&lt;char, Iter&gt; &amp;mgf =
-        std::use_facet&lt;std::money_get&lt;char, Iter&gt; &gt;(std::locale
-             ());
+    std::ios_base::iostate state = std::ios_base::goodbit;
+
+    // Retrieve the money_get facet from the named locale.
+    const std::locale loc (locname);
+
+    typedef std::istreambuf_iterator&lt;char&gt; Iter;
+    typedef std::money_get&lt;char, Iter&gt;     MoneyGet;
+
+    const MoneyGet &mgf = std::use_facet&lt;MoneyGet&gt;(loc);
 
     {
-        // Build an istringstream from the buffer and construct
-        // a beginning iterator on it.
+        // Build an istringstream object from the buffer
+        // and imbue the locale in it.
         std::istringstream ins (buffer);
-        Iter begin (ins);
+        ins.imbue (loc);
 
-        // Get a string representation of the monetary value
-        mgf.get (begin, end, false, ins, state, dest);
+        // Get a string representation of the monetary value.
+        mgf.get (ins, Iter (), intl, ins, state, smon);
     }
     {
-        // Build another istringstream from the buffer, etc.
-        // so we have an iterator pointing to the beginning
         std::istringstream ins (buffer);
-        Iter begin (ins);
+        ins.imbue (loc);
 
-        // Get a a long double representation of the monetary
-           value
-        mgf.get (begin, end, false, ins, state, ldest);
+        // Get a floating point representation of the monetary value.
+        mgf.get (ins, Iter (), intl, ins, state, fmon);
     }
 
-    std::cout &lt;&lt; buffer &lt;&lt; " --&gt; "
-              &lt;&lt; dest &lt;&lt; " --&gt; " &lt;&lt; ldest &lt;&lt; std::endl;
+    // Output the original sequence and its string and floating point
+    // representations.
+    std::cout &lt;&lt; buffer &lt;&lt; " --&gt; \"" &lt;&lt; smon &lt;&lt; "\" --&gt; " &lt;&lt; fmon &lt;&lt; '\n';
 
-    // return 0 on success, non-zero on failure
+    // Return 0 on success, non-zero on failure.
     return !(std::ios_base::eofbit == state);
 }
 
 Program Output:
-$100.02 --&gt; 10002 --&gt; 10002
+$1,234.6789 --&gt; "123467" --&gt; 123467
 </PRE></UL>
 <A NAME="sec13"><H3>See Also</H3></A>
 <P><B><I><A HREF="locale.html">locale</A></I></B>, <A HREF="facets.html">Facets</A>, <B><I><A HREF="money-put.html">money_put</A></I></B>, <B><I><A HREF="moneypunct.html">moneypunct</A></I></B></P>



Re: svn commit: r537492 - /incubator/stdcxx/trunk/doc/stdlibref/money-get.html

Posted by Mark Brown <mb...@inbox.com>.
Okay, after some initial technical difficulties (sorry about the messed up submissions) I opened two issues:

22.locale.money.get.cpp doesn't test international monetary formats (https://issues.apache.org/jira/browse/STDCXX-413)
and money_get fails to parse currency in international format (https://issues.apache.org/jira/browse/STDCXX-412).

-- Mark


> -----Original Message-----
> From: sebor@roguewave.com
> Sent: Sat, 12 May 2007 15:42:16 -0600
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: svn commit: r537492 -
> /incubator/stdcxx/trunk/doc/stdlibref/money-get.html
> 
> Mark Brown wrote:
>>> -----Original Message-----
>>> From: sebor@roguewave.com
>>> Sent: Sat, 12 May 2007 14:09:34 -0600
>>> To: stdcxx-dev@incubator.apache.org
>>> Subject: Re: svn commit: r537492 -
>>> /incubator/stdcxx/trunk/doc/stdlibref/money-get.html
>>> 
>>> Mark Brown wrote:
>>>> Martin,
>>>> 
>>>> Thanks for fixing it! I have a question about the new code: Could you
>>>> show an example of an international monetary string that would be
>>>> correctly parsed by the facet? I tried a few but none of them could be
>>>> parsed. For instance, "USD 1234" gives this output:
>>>> USD 1234 --> "" --> 0
>>>> The same happens with g++ and STLport so I suspect I must be doing
>>>> something wrong. Removing the space between the currency symbol and
>>>> the
>>>> number didn't make a difference.
>>> Hmm, I guess I should have tested the internationalized behavior before
>>> I put it in. I think the code is correct as is and your input should be
>>> correctly parsed by the facet (and produce 1234 on output). I'm not
>>> sure
>>> what's going on. Stepping through the code it looks like the money_get
>>> facet ends up retrieving the wrong specialization of moneypunct, i.e.,
>>> moneypunct<char, false> when it needs moneypunct<char, true>. What's
>>> puzzling is that both libstdc++ and STLport behave the same. It seems
>>> like too much of a coincidence for all three implementations to suffer
>>> from the same bug.
>>> 
>>> In any event, thanks for bringing it to our attention! Can you open an
>>> issue for this as well so we don't forget to investigate it in case I
>>> don't get around to it soon?
>> 
>> I can certainly do that. I should also mention that while investigating
>> this problem I found a test that's supposed to test this functionality:
>> 22.locale.money.get.cpp. The test fails 20 out of 1934 assertions but
>> none of them look like they have anything to do with parsing
>> international monetary values. It doesn't look like they are being
>> tested at all...
> 
> Yeah, I noticed it too. I'm in the process of enhancing the test to
> exercise the international formats as well. If you don't mind creating
> another issue for the test, just for tracking purposes, that would be
> swell!
> 
> Martin

____________________________________________________________
GET FREE 5GB ONLINE STORAGE - Safely store your documents, photos and music online!
Visit http://www.inbox.com/storage to find out more!

Re: svn commit: r537492 - /incubator/stdcxx/trunk/doc/stdlibref/money-get.html

Posted by Martin Sebor <se...@roguewave.com>.
Mark Brown wrote:
>> -----Original Message-----
>> From: sebor@roguewave.com
>> Sent: Sat, 12 May 2007 14:09:34 -0600
>> To: stdcxx-dev@incubator.apache.org
>> Subject: Re: svn commit: r537492 -
>> /incubator/stdcxx/trunk/doc/stdlibref/money-get.html
>>
>> Mark Brown wrote:
>>> Martin,
>>>
>>> Thanks for fixing it! I have a question about the new code: Could you
>>> show an example of an international monetary string that would be
>>> correctly parsed by the facet? I tried a few but none of them could be
>>> parsed. For instance, "USD 1234" gives this output:
>>> USD 1234 --> "" --> 0
>>> The same happens with g++ and STLport so I suspect I must be doing
>>> something wrong. Removing the space between the currency symbol and the
>>> number didn't make a difference.
>> Hmm, I guess I should have tested the internationalized behavior before
>> I put it in. I think the code is correct as is and your input should be
>> correctly parsed by the facet (and produce 1234 on output). I'm not sure
>> what's going on. Stepping through the code it looks like the money_get
>> facet ends up retrieving the wrong specialization of moneypunct, i.e.,
>> moneypunct<char, false> when it needs moneypunct<char, true>. What's
>> puzzling is that both libstdc++ and STLport behave the same. It seems
>> like too much of a coincidence for all three implementations to suffer
>> from the same bug.
>>
>> In any event, thanks for bringing it to our attention! Can you open an
>> issue for this as well so we don't forget to investigate it in case I
>> don't get around to it soon?
> 
> I can certainly do that. I should also mention that while investigating this problem I found a test that's supposed to test this functionality: 22.locale.money.get.cpp. The test fails 20 out of 1934 assertions but none of them look like they have anything to do with parsing international monetary values. It doesn't look like they are being tested at all...

Yeah, I noticed it too. I'm in the process of enhancing the test to
exercise the international formats as well. If you don't mind creating
another issue for the test, just for tracking purposes, that would be
swell!

Martin

Re: svn commit: r537492 - /incubator/stdcxx/trunk/doc/stdlibref/money-get.html

Posted by Mark Brown <mb...@inbox.com>.
> -----Original Message-----
> From: sebor@roguewave.com
> Sent: Sat, 12 May 2007 14:09:34 -0600
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: svn commit: r537492 -
> /incubator/stdcxx/trunk/doc/stdlibref/money-get.html
> 
> Mark Brown wrote:
>> Martin,
>> 
>> Thanks for fixing it! I have a question about the new code: Could you
>> show an example of an international monetary string that would be
>> correctly parsed by the facet? I tried a few but none of them could be
>> parsed. For instance, "USD 1234" gives this output:
>> USD 1234 --> "" --> 0
>> The same happens with g++ and STLport so I suspect I must be doing
>> something wrong. Removing the space between the currency symbol and the
>> number didn't make a difference.
> 
> Hmm, I guess I should have tested the internationalized behavior before
> I put it in. I think the code is correct as is and your input should be
> correctly parsed by the facet (and produce 1234 on output). I'm not sure
> what's going on. Stepping through the code it looks like the money_get
> facet ends up retrieving the wrong specialization of moneypunct, i.e.,
> moneypunct<char, false> when it needs moneypunct<char, true>. What's
> puzzling is that both libstdc++ and STLport behave the same. It seems
> like too much of a coincidence for all three implementations to suffer
> from the same bug.
> 
> In any event, thanks for bringing it to our attention! Can you open an
> issue for this as well so we don't forget to investigate it in case I
> don't get around to it soon?

I can certainly do that. I should also mention that while investigating this problem I found a test that's supposed to test this functionality: 22.locale.money.get.cpp. The test fails 20 out of 1934 assertions but none of them look like they have anything to do with parsing international monetary values. It doesn't look like they are being tested at all...

-- Mark

____________________________________________________________
KEEP SPYWARE OFF YOUR COMPUTER - Protect your computer with Spyware Terminator!
Visit http://www.spywareterminator.com/install and find out more!

Re: svn commit: r537492 - /incubator/stdcxx/trunk/doc/stdlibref/money-get.html

Posted by Martin Sebor <se...@roguewave.com>.
Mark Brown wrote:
> Martin,
> 
> Thanks for fixing it! I have a question about the new code: Could you show an example of an international monetary string that would be correctly parsed by the facet? I tried a few but none of them could be parsed. For instance, "USD 1234" gives this output:
> USD 1234 --> "" --> 0
> The same happens with g++ and STLport so I suspect I must be doing something wrong. Removing the space between the currency symbol and the number didn't make a difference.

Hmm, I guess I should have tested the internationalized behavior before
I put it in. I think the code is correct as is and your input should be
correctly parsed by the facet (and produce 1234 on output). I'm not sure
what's going on. Stepping through the code it looks like the money_get
facet ends up retrieving the wrong specialization of moneypunct, i.e.,
moneypunct<char, false> when it needs moneypunct<char, true>. What's
puzzling is that both libstdc++ and STLport behave the same. It seems
like too much of a coincidence for all three implementations to suffer
from the same bug.

In any event, thanks for bringing it to our attention! Can you open an
issue for this as well so we don't forget to investigate it in case I
don't get around to it soon?

Thanks
Martin

> 
> -- Mark
> 
> 
>> -----Original Message-----
>> From: sebor@apache.org
>> Sent: Sat, 12 May 2007 17:32:56 -0000
>> To: stdcxx-commits@incubator.apache.org
>> Subject: svn commit: r537492 -
>> /incubator/stdcxx/trunk/doc/stdlibref/money-get.html
>>
>> Author: sebor
>> Date: Sat May 12 10:32:55 2007
>> New Revision: 537492
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=537492
>> Log:
>> 2007-05-12  Martin Sebor  <se...@roguewave.com>
>>
>> 	STDCXX-411
>> 	* money-get.html: Updated example program to (closely) match
>> 	the latest version of the program in svn and to match shown
>> 	output.
>>
>> Modified:
>>     incubator/stdcxx/trunk/doc/stdlibref/money-get.html
>>
>> Modified: incubator/stdcxx/trunk/doc/stdlibref/money-get.html
>> URL:
>> http://svn.apache.org/viewvc/incubator/stdcxx/trunk/doc/stdlibref/money-get.html?view=diff&rev=537492&r1=537491&r2=537492
>> ==============================================================================
>> --- incubator/stdcxx/trunk/doc/stdlibref/money-get.html (original)
>> +++ incubator/stdcxx/trunk/doc/stdlibref/money-get.html Sat May 12
>> 10:32:55 2007
>> @@ -165,54 +165,53 @@
>>  #include &lt;iostream&gt;   // for cout, endl
>>  #include &lt;iterator&gt;   // for istreambuf_iterator
>>
>> -#include &lt;examples.h&gt;
>> +int main (int argc, char *argv[])
>> +{
>> +    // Get the monetary string and locale from the argument vector.
>> +    const char* const buffer  = 1 &lt; argc ? argv [1] : "$1,234.6789";
>> +    const char* const locname = 2 &lt; argc ? argv [2] : "en_US";
>> +    const bool        intl    = 3 &lt; argc;
>>
>> +    std::string smon;
>> +    long double fmon = 0.0;
>>
>> -int main ()
>> -{
>> -    typedef std::istreambuf_iterator&lt;char,
>> -            std::char_traits&lt;char&gt; &gt; Iter;
>> -
>> -    const std::string buffer ("$100.02");
>> -    std::string dest;
>> -    long double ldest;
>> -    std::ios_base::iostate state;
>> -    Iter end;
>> -
>> -    // Retrieve the money_get facet from the global locale.
>> -    const std::money_get&lt;char, Iter&gt; &amp;mgf =
>> -        std::use_facet&lt;std::money_get&lt;char, Iter&gt;
>> &gt;(std::locale
>> -             ());
>> +    std::ios_base::iostate state = std::ios_base::goodbit;
>> +
>> +    // Retrieve the money_get facet from the named locale.
>> +    const std::locale loc (locname);
>> +
>> +    typedef std::istreambuf_iterator&lt;char&gt; Iter;
>> +    typedef std::money_get&lt;char, Iter&gt;     MoneyGet;
>> +
>> +    const MoneyGet &mgf = std::use_facet&lt;MoneyGet&gt;(loc);
>>
>>      {
>> -        // Build an istringstream from the buffer and construct
>> -        // a beginning iterator on it.
>> +        // Build an istringstream object from the buffer
>> +        // and imbue the locale in it.
>>          std::istringstream ins (buffer);
>> -        Iter begin (ins);
>> +        ins.imbue (loc);
>>
>> -        // Get a string representation of the monetary value
>> -        mgf.get (begin, end, false, ins, state, dest);
>> +        // Get a string representation of the monetary value.
>> +        mgf.get (ins, Iter (), intl, ins, state, smon);
>>      }
>>      {
>> -        // Build another istringstream from the buffer, etc.
>> -        // so we have an iterator pointing to the beginning
>>          std::istringstream ins (buffer);
>> -        Iter begin (ins);
>> +        ins.imbue (loc);
>>
>> -        // Get a a long double representation of the monetary
>> -           value
>> -        mgf.get (begin, end, false, ins, state, ldest);
>> +        // Get a floating point representation of the monetary value.
>> +        mgf.get (ins, Iter (), intl, ins, state, fmon);
>>      }
>>
>> -    std::cout &lt;&lt; buffer &lt;&lt; " --&gt; "
>> -              &lt;&lt; dest &lt;&lt; " --&gt; " &lt;&lt; ldest &lt;&lt;
>> std::endl;
>> +    // Output the original sequence and its string and floating point
>> +    // representations.
>> +    std::cout &lt;&lt; buffer &lt;&lt; " --&gt; \"" &lt;&lt; smon
>> &lt;&lt; "\" --&gt; " &lt;&lt; fmon &lt;&lt; '\n';
>>
>> -    // return 0 on success, non-zero on failure
>> +    // Return 0 on success, non-zero on failure.
>>      return !(std::ios_base::eofbit == state);
>>  }
>>
>>  Program Output:
>> -$100.02 --&gt; 10002 --&gt; 10002
>> +$1,234.6789 --&gt; "123467" --&gt; 123467
>>  </PRE></UL>
>>  <A NAME="sec13"><H3>See Also</H3></A>
>>  <P><B><I><A HREF="locale.html">locale</A></I></B>, <A
>> HREF="facets.html">Facets</A>, <B><I><A
>> HREF="money-put.html">money_put</A></I></B>, <B><I><A
>> HREF="moneypunct.html">moneypunct</A></I></B></P>
> 
> ____________________________________________________________
> ONE-CLICK WEBMAIL ACCESS - Easily monitor & access your email accounts!
> Visit http://www.inbox.com/notifier and check it out!
> 


RE: svn commit: r537492 - /incubator/stdcxx/trunk/doc/stdlibref/money-get.html

Posted by Mark Brown <mb...@inbox.com>.
Martin,

Thanks for fixing it! I have a question about the new code: Could you show an example of an international monetary string that would be correctly parsed by the facet? I tried a few but none of them could be parsed. For instance, "USD 1234" gives this output:
USD 1234 --> "" --> 0
The same happens with g++ and STLport so I suspect I must be doing something wrong. Removing the space between the currency symbol and the number didn't make a difference.

-- Mark


> -----Original Message-----
> From: sebor@apache.org
> Sent: Sat, 12 May 2007 17:32:56 -0000
> To: stdcxx-commits@incubator.apache.org
> Subject: svn commit: r537492 -
> /incubator/stdcxx/trunk/doc/stdlibref/money-get.html
> 
> Author: sebor
> Date: Sat May 12 10:32:55 2007
> New Revision: 537492
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=537492
> Log:
> 2007-05-12  Martin Sebor  <se...@roguewave.com>
> 
> 	STDCXX-411
> 	* money-get.html: Updated example program to (closely) match
> 	the latest version of the program in svn and to match shown
> 	output.
> 
> Modified:
>     incubator/stdcxx/trunk/doc/stdlibref/money-get.html
> 
> Modified: incubator/stdcxx/trunk/doc/stdlibref/money-get.html
> URL:
> http://svn.apache.org/viewvc/incubator/stdcxx/trunk/doc/stdlibref/money-get.html?view=diff&rev=537492&r1=537491&r2=537492
> ==============================================================================
> --- incubator/stdcxx/trunk/doc/stdlibref/money-get.html (original)
> +++ incubator/stdcxx/trunk/doc/stdlibref/money-get.html Sat May 12
> 10:32:55 2007
> @@ -165,54 +165,53 @@
>  #include &lt;iostream&gt;   // for cout, endl
>  #include &lt;iterator&gt;   // for istreambuf_iterator
> 
> -#include &lt;examples.h&gt;
> +int main (int argc, char *argv[])
> +{
> +    // Get the monetary string and locale from the argument vector.
> +    const char* const buffer  = 1 &lt; argc ? argv [1] : "$1,234.6789";
> +    const char* const locname = 2 &lt; argc ? argv [2] : "en_US";
> +    const bool        intl    = 3 &lt; argc;
> 
> +    std::string smon;
> +    long double fmon = 0.0;
> 
> -int main ()
> -{
> -    typedef std::istreambuf_iterator&lt;char,
> -            std::char_traits&lt;char&gt; &gt; Iter;
> -
> -    const std::string buffer ("$100.02");
> -    std::string dest;
> -    long double ldest;
> -    std::ios_base::iostate state;
> -    Iter end;
> -
> -    // Retrieve the money_get facet from the global locale.
> -    const std::money_get&lt;char, Iter&gt; &amp;mgf =
> -        std::use_facet&lt;std::money_get&lt;char, Iter&gt;
> &gt;(std::locale
> -             ());
> +    std::ios_base::iostate state = std::ios_base::goodbit;
> +
> +    // Retrieve the money_get facet from the named locale.
> +    const std::locale loc (locname);
> +
> +    typedef std::istreambuf_iterator&lt;char&gt; Iter;
> +    typedef std::money_get&lt;char, Iter&gt;     MoneyGet;
> +
> +    const MoneyGet &mgf = std::use_facet&lt;MoneyGet&gt;(loc);
> 
>      {
> -        // Build an istringstream from the buffer and construct
> -        // a beginning iterator on it.
> +        // Build an istringstream object from the buffer
> +        // and imbue the locale in it.
>          std::istringstream ins (buffer);
> -        Iter begin (ins);
> +        ins.imbue (loc);
> 
> -        // Get a string representation of the monetary value
> -        mgf.get (begin, end, false, ins, state, dest);
> +        // Get a string representation of the monetary value.
> +        mgf.get (ins, Iter (), intl, ins, state, smon);
>      }
>      {
> -        // Build another istringstream from the buffer, etc.
> -        // so we have an iterator pointing to the beginning
>          std::istringstream ins (buffer);
> -        Iter begin (ins);
> +        ins.imbue (loc);
> 
> -        // Get a a long double representation of the monetary
> -           value
> -        mgf.get (begin, end, false, ins, state, ldest);
> +        // Get a floating point representation of the monetary value.
> +        mgf.get (ins, Iter (), intl, ins, state, fmon);
>      }
> 
> -    std::cout &lt;&lt; buffer &lt;&lt; " --&gt; "
> -              &lt;&lt; dest &lt;&lt; " --&gt; " &lt;&lt; ldest &lt;&lt;
> std::endl;
> +    // Output the original sequence and its string and floating point
> +    // representations.
> +    std::cout &lt;&lt; buffer &lt;&lt; " --&gt; \"" &lt;&lt; smon
> &lt;&lt; "\" --&gt; " &lt;&lt; fmon &lt;&lt; '\n';
> 
> -    // return 0 on success, non-zero on failure
> +    // Return 0 on success, non-zero on failure.
>      return !(std::ios_base::eofbit == state);
>  }
> 
>  Program Output:
> -$100.02 --&gt; 10002 --&gt; 10002
> +$1,234.6789 --&gt; "123467" --&gt; 123467
>  </PRE></UL>
>  <A NAME="sec13"><H3>See Also</H3></A>
>  <P><B><I><A HREF="locale.html">locale</A></I></B>, <A
> HREF="facets.html">Facets</A>, <B><I><A
> HREF="money-put.html">money_put</A></I></B>, <B><I><A
> HREF="moneypunct.html">moneypunct</A></I></B></P>

____________________________________________________________
ONE-CLICK WEBMAIL ACCESS - Easily monitor & access your email accounts!
Visit http://www.inbox.com/notifier and check it out!