Topic: std::string slicer by tags (parsing command line


Author: PAVEL SOKOLOV <pavel.sokolov@gmail.com>
Date: Sat, 22 Apr 2017 10:20:57 -0700 (PDT)
Raw View
------=_Part_944_318082879.1492881657413
Content-Type: multipart/alternative;
 boundary="----=_Part_945_559407529.1492881657413"

------=_Part_945_559407529.1492881657413
Content-Type: text/plain; charset=UTF-8

It can be useful for a simple tasks (for a difficult parsing rules regexp
can be used). Looks like it's a very frequent task.

Possible implementation on github <https://github.com/crea7or/stringslice> (makefile
included). Supported: one char(wchar) delimiter, char*(wchar*) as delimiter
in each_slice(...), any one from char(wchar) as delimiter from
char*(wchar*) in any_slice(...).

Example:

std::string testString( "cpp=1,2,3,4,5,6,7,8,9" );

std::vector< std::string > allSlices;
each_slice( testString.begin(), testString.end(), '=',
back_insert_functor<std::vector< std::string >>( allSlices ) );
if ( allSlices.size() == 2 )
{
each_slice( allSlices[ 1 ].begin(), allSlices[ 1 ].end(), ',', []( const
std::string& tag )
{
std::cout << tag << std::endl;
} );
}

Result: 1 2 3 4 5 6 7 8 9

Can be easily switched to string_view. Can be a part of std::algorithms or
even std::string. Easy and fast.

ps: back_insert_functor is a wrapper that allows passing OutputIterator as
functor.
pss: implementation is not final and may contain bugs.



--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b76801b8-8ace-4129-8030-1664d1cbbc05%40isocpp.org.

------=_Part_945_559407529.1492881657413
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">It can be useful for a simple tasks=C2=A0(for a difficult =
parsing rules regexp can be used). Looks like it&#39;s a very frequent task=
..<div><br></div><div>Possible <a href=3D"https://github.com/crea7or/strings=
lice">implementation on github</a>=C2=A0(makefile included). Supported: one=
 char(wchar) delimiter, char*(wchar*) as delimiter in each_slice(...), any =
one from char(wchar) as delimiter from char*(wchar*) in any_slice(...).=C2=
=A0</div><div><br></div><div>Example:</div><div><br></div><div><div><span c=
lass=3D"Apple-tab-span" style=3D"white-space:pre"> </span>std::string testS=
tring( &quot;cpp=3D1,2,3,4,5,6,7,8,9&quot; );</div><div><br></div><div><spa=
n class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>std::vector&lt=
; std::string &gt; allSlices;</div><div><span class=3D"Apple-tab-span" styl=
e=3D"white-space:pre"> </span>each_slice( testString.begin(), testString.en=
d(), &#39;=3D&#39;, back_insert_functor&lt;std::vector&lt; std::string &gt;=
&gt;( allSlices ) );</div><div><span class=3D"Apple-tab-span" style=3D"whit=
e-space:pre"> </span>if ( allSlices.size() =3D=3D 2 )</div><div><span class=
=3D"Apple-tab-span" style=3D"white-space:pre"> </span>{</div><div><span cla=
ss=3D"Apple-tab-span" style=3D"white-space:pre">  </span>each_slice( allSli=
ces[ 1 ].begin(), allSlices[ 1 ].end(), &#39;,&#39;, []( const std::string&=
amp; tag )</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pr=
e">  </span>{</div><div><span class=3D"Apple-tab-span" style=3D"white-space=
:pre">   </span>std::cout &lt;&lt; tag &lt;&lt; std::endl;</div><div><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>} );</div><div>=
<span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>}</div></d=
iv><div><br></div><div>Result: 1 2 3 4 5 6 7 8 9</div><div><br></div><div>C=
an be easily switched to string_view. Can be a part of std::algorithms or e=
ven std::string. Easy and fast.=C2=A0</div><div><br></div><div>ps: back_ins=
ert_functor is a wrapper that allows passing OutputIterator as functor.</di=
v><div>pss: implementation is not final and may contain bugs.</div><div><br=
></div><div><br></div><div><br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b76801b8-8ace-4129-8030-1664d1cbbc05%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b76801b8-8ace-4129-8030-1664d1cbbc05=
%40isocpp.org</a>.<br />

------=_Part_945_559407529.1492881657413--

------=_Part_944_318082879.1492881657413--

.


Author: Richard Thorell <richard.thorell@king.com>
Date: Sat, 22 Apr 2017 11:55:05 -0700 (PDT)
Raw View
------=_Part_971_652429460.1492887306053
Content-Type: multipart/alternative;
 boundary="----=_Part_972_1728352162.1492887306053"

------=_Part_972_1728352162.1492887306053
Content-Type: text/plain; charset=UTF-8

Here's a discussion about the same functionality from a while
back; https://groups.google.com/a/isocpp.org/forum/?utm_medium=email&utm_source=footer#!topic/std-proposals/JTKTThJ-7Ko

Cheers

On Saturday, April 22, 2017 at 6:20:57 PM UTC+1, PAVEL SOKOLOV wrote:
>
> It can be useful for a simple tasks (for a difficult parsing rules regexp
> can be used). Looks like it's a very frequent task.
>
> Possible implementation on github <https://github.com/crea7or/stringslice> (makefile
> included). Supported: one char(wchar) delimiter, char*(wchar*) as delimiter
> in each_slice(...), any one from char(wchar) as delimiter from
> char*(wchar*) in any_slice(...).
>
> Example:
>
> std::string testString( "cpp=1,2,3,4,5,6,7,8,9" );
>
> std::vector< std::string > allSlices;
> each_slice( testString.begin(), testString.end(), '=',
> back_insert_functor<std::vector< std::string >>( allSlices ) );
> if ( allSlices.size() == 2 )
> {
> each_slice( allSlices[ 1 ].begin(), allSlices[ 1 ].end(), ',', []( const
> std::string& tag )
> {
> std::cout << tag << std::endl;
> } );
> }
>
> Result: 1 2 3 4 5 6 7 8 9
>
> Can be easily switched to string_view. Can be a part of std::algorithms or
> even std::string. Easy and fast.
>
> ps: back_insert_functor is a wrapper that allows passing OutputIterator as
> functor.
> pss: implementation is not final and may contain bugs.
>
>
>
>

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a4d5f8d6-1050-4868-a859-3ee782a26f8b%40isocpp.org.

------=_Part_972_1728352162.1492887306053
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Here&#39;s a discussion about the same functionality from =
a while back;=C2=A0https://groups.google.com/a/isocpp.org/forum/?utm_medium=
=3Demail&amp;utm_source=3Dfooter#!topic/std-proposals/JTKTThJ-7Ko<div><br><=
/div><div>Cheers</div><div><div><br>On Saturday, April 22, 2017 at 6:20:57 =
PM UTC+1, PAVEL SOKOLOV wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"ltr">It can be useful for a simple tasks=C2=A0(for a difficult =
parsing rules regexp can be used). Looks like it&#39;s a very frequent task=
..<div><br></div><div>Possible <a href=3D"https://github.com/crea7or/strings=
lice" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;ht=
tps://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcrea7or%2Fstringsl=
ice\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEvVWeglLNm4XgutFOCCdnlYiwTSg&#3=
9;;return true;" onclick=3D"this.href=3D&#39;https://www.google.com/url?q\x=
3dhttps%3A%2F%2Fgithub.com%2Fcrea7or%2Fstringslice\x26sa\x3dD\x26sntz\x3d1\=
x26usg\x3dAFQjCNEvVWeglLNm4XgutFOCCdnlYiwTSg&#39;;return true;">implementat=
ion on github</a>=C2=A0(makefile included). Supported: one char(wchar) deli=
miter, char*(wchar*) as delimiter in each_slice(...), any one from char(wch=
ar) as delimiter from char*(wchar*) in any_slice(...).=C2=A0</div><div><br>=
</div><div>Example:</div><div><br></div><div><div><span style=3D"white-spac=
e:pre"> </span>std::string testString( &quot;cpp=3D1,2,3,4,5,6,7,8,9&quot; =
);</div><div><br></div><div><span style=3D"white-space:pre"> </span>std::ve=
ctor&lt; std::string &gt; allSlices;</div><div><span style=3D"white-space:p=
re"> </span>each_slice( testString.begin(), testString.end(), &#39;=3D&#39;=
, back_insert_functor&lt;std::<wbr>vector&lt; std::string &gt;&gt;( allSlic=
es ) );</div><div><span style=3D"white-space:pre"> </span>if ( allSlices.si=
ze() =3D=3D 2 )</div><div><span style=3D"white-space:pre"> </span>{</div><d=
iv><span style=3D"white-space:pre">  </span>each_slice( allSlices[ 1 ].begi=
n(), allSlices[ 1 ].end(), &#39;,&#39;, []( const std::string&amp; tag )</d=
iv><div><span style=3D"white-space:pre">  </span>{</div><div><span style=3D=
"white-space:pre">   </span>std::cout &lt;&lt; tag &lt;&lt; std::endl;</div=
><div><span style=3D"white-space:pre">  </span>} );</div><div><span style=
=3D"white-space:pre"> </span>}</div></div><div><br></div><div>Result: 1 2 3=
 4 5 6 7 8 9</div><div><br></div><div>Can be easily switched to string_view=
.. Can be a part of std::algorithms or even std::string. Easy and fast.=C2=
=A0</div><div><br></div><div>ps: back_insert_functor is a wrapper that allo=
ws passing OutputIterator as functor.</div><div>pss: implementation is not =
final and may contain bugs.</div><div><br></div><div><br></div><div><br></d=
iv></div></blockquote></div></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a4d5f8d6-1050-4868-a859-3ee782a26f8b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a4d5f8d6-1050-4868-a859-3ee782a26f8b=
%40isocpp.org</a>.<br />

------=_Part_972_1728352162.1492887306053--

------=_Part_971_652429460.1492887306053--

.