help with parsing a number with thousands comma separator

Juan Dent <[email protected]> Sun, 11 Oct 2020 00:45:42 +0000
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <BYAPR14MB307758F4EA9E7E323166444B9B060@BYAPR14MB3077.namprd14.prod.outlook.com>
--===============6774129487685942287==
Content-Language: en-US
Content-Type: multipart/alternative;
	boundary="_000_BYAPR14MB307758F4EA9E7E323166444B9B060BYAPR14MB3077namp_"

--_000_BYAPR14MB307758F4EA9E7E323166444B9B060BYAPR14MB3077namp_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Hi,

I have the grammar correct but it is not giving me the whole number, just t=
he first 2 digits. The parse says ok though=85

uint_parser<unsigned, 10, 1, 3> uint3_p;        //  1..3 digits
uint_parser<unsigned, 10, 3, 3> uint3_3_p;      //  exactly 3 digits
unsigned all_value;
test_parser_attr("12,345,678", uint3_p >> *(',' >> uint3_3_p), all_value);



this calls :


template <typename P, typename T>
void test_parser_attr(
    char const* input, P const& p, T& attr, bool full_match =3D true)
{
    using boost::spirit::qi::parse;

    char const* f(input);
    char const* l(f + strlen(f));
    if (parse(f, l, p, attr) && (!full_match || (f =3D=3D l)))
        std::cout << "ok" << std::endl;
    else
        std::cout << "fail" << std::endl;
}

Why don=92t I get 12345678 in all_value? Is this the way or is there someth=
ing similar or easier?

Regards,
Juan

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=3D550986> for Window=
s 10


--_000_BYAPR14MB307758F4EA9E7E323166444B9B060BYAPR14MB3077namp_
Content-Type: text/html; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" xmlns:w=3D"urn:sc=
hemas-microsoft-com:office:word" xmlns:m=3D"http://schemas.microsoft.com/of=
fice/2004/12/omml" xmlns=3D"http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
252">
<meta name=3D"Generator" content=3D"Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
.MsoChpDefault
	{mso-style-type:export-only;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style>
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"#954F72">
<div class=3D"WordSection1">
<p class=3D"MsoNormal">Hi,</p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">I have the grammar correct but it is not giving me t=
he whole number, just the first 2 digits. The parse says ok though=85</p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">uint_parser&lt;unsigned, 10, 1, 3&gt; uint3_p;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; 1..3 digits</p>
<p class=3D"MsoNormal">uint_parser&lt;unsigned, 10, 3, 3&gt; uint3_3_p;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; exactly 3 digits</p>
<p class=3D"MsoNormal">unsigned all_value;</p>
<p class=3D"MsoNormal">test_parser_attr(&quot;12,345,678&quot;, uint3_p &gt=
;&gt; *(',' &gt;&gt; uint3_3_p), all_value);</p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">this calls :</p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">template &lt;typename P, typename T&gt;</p>
<p class=3D"MsoNormal">void test_parser_attr(</p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp; char const* input, P const&amp; p=
, T&amp; attr, bool full_match =3D true)</p>
<p class=3D"MsoNormal">{</p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp; using boost::spirit::qi::parse;</=
p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp; char const* f(input);</p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp; char const* l(f + strlen(f));</p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp; if (parse(f, l, p, attr) &amp;&am=
p; (!full_match || (f =3D=3D l)))</p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout=
 &lt;&lt; &quot;ok&quot; &lt;&lt; std::endl;</p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp; else</p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout=
 &lt;&lt; &quot;fail&quot; &lt;&lt; std::endl;</p>
<p class=3D"MsoNormal">}</p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">Why don=92t I get 12345678 in all_value? Is this the=
 way or is there something similar or easier?</p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">Regards,</p>
<p class=3D"MsoNormal">Juan </p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">Sent from <a href=3D"https://go.microsoft.com/fwlink=
/?LinkId=3D550986">
Mail</a> for Windows 10</p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body>
</html>

--_000_BYAPR14MB307758F4EA9E7E323166444B9B060BYAPR14MB3077namp_--


--===============6774129487685942287==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============6774129487685942287==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general

--===============6774129487685942287==--