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> </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> </o:p></p>
<p class=3D"MsoNormal">uint_parser<unsigned, 10, 1, 3> uint3_p; =
// 1..3 digits</p>
<p class=3D"MsoNormal">uint_parser<unsigned, 10, 3, 3> uint3_3_p;&nbs=
p; // exactly 3 digits</p>
<p class=3D"MsoNormal">unsigned all_value;</p>
<p class=3D"MsoNormal">test_parser_attr("12,345,678", uint3_p >=
;> *(',' >> uint3_3_p), all_value);</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">this calls :</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">template <typename P, typename T></p>
<p class=3D"MsoNormal">void test_parser_attr(</p>
<p class=3D"MsoNormal"> char const* input, P const& p=
, T& attr, bool full_match =3D true)</p>
<p class=3D"MsoNormal">{</p>
<p class=3D"MsoNormal"> using boost::spirit::qi::parse;</=
p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> char const* f(input);</p>
<p class=3D"MsoNormal"> char const* l(f + strlen(f));</p>
<p class=3D"MsoNormal"> if (parse(f, l, p, attr) &&am=
p; (!full_match || (f =3D=3D l)))</p>
<p class=3D"MsoNormal"> std::cout=
<< "ok" << std::endl;</p>
<p class=3D"MsoNormal"> else</p>
<p class=3D"MsoNormal"> std::cout=
<< "fail" << std::endl;</p>
<p class=3D"MsoNormal">}</p>
<p class=3D"MsoNormal"><o:p> </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> </o:p></p>
<p class=3D"MsoNormal">Regards,</p>
<p class=3D"MsoNormal">Juan </p>
<p class=3D"MsoNormal"><o:p> </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> </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==--