Topic: std::string::find implementation
Author: tecoberg@gmail.com
Date: Tue, 30 May 2017 06:25:55 -0700 (PDT)
Raw View
------=_Part_3562_1611131057.1496150755682
Content-Type: multipart/alternative;
boundary="----=_Part_3563_958530312.1496150755682"
------=_Part_3563_958530312.1496150755682
Content-Type: text/plain; charset="UTF-8"
I figure out we can set the start point of search on string but we cannot
set the end. For example:
mystring.find('A', 10, 15); //Search for 'A'
into mystring starting on position 10 and ends on position 15 (into
mystring)
The problem is the actual implementation allow to set the quantity of
characters to be searched from char*:
size_t find (const char* s, size_t pos, size_type n) const;
It is a little confusing and it should be deprecated.
The best solution is make another function member like std::string::search
to replace std::string::find. It could be like this:
size_t search (const string& str, size_t pos = 0, size_t end =
string::npos ) const noexcept;
size_t search (const char* s, size_t pos = 0, size_t end =
string::npos) const;
size_t search (char c, size_t pos = 0, size_t end = string::npos) const
noexcept;
where the size_t end is the end position in string where the search will be
made.
--
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/82be917c-b3c8-4cb4-bbbc-0f62ec78ce84%40isocpp.org.
------=_Part_3563_958530312.1496150755682
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><font size=3D"4">I figure out we can set the start point o=
f search on string but we cannot set the end. For example:<br><br></font><d=
iv style=3D"margin-left: 40px;"><font size=3D"4"><span style=3D"background-=
color: rgb(238, 238, 238);">mystring.find('A', 10, 15);=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 //Search for 'A' into mystring starting on=
position 10 and ends on position 15 (into mystring)</span></font><br></div=
><font size=3D"4"><br>The problem is the actual implementation allow to set=
the quantity of characters to be searched from char*:<br><br></font><div s=
tyle=3D"margin-left: 40px;"><span style=3D"background-color: rgb(238, 238, =
238);"><font size=3D"4">size_t find (const char* s, size_t pos, size_type n=
) const;</font></span><br></div><font size=3D"4"><br>It is a little confusi=
ng and it should be deprecated.<br><br>The best solution is make another fu=
nction member like <span style=3D"background-color: rgb(255, 255, 0);">std:=
:string::search</span> to replace <span style=3D"background-color: rgb(255,=
255, 0);">std::string::find</span>. It could be like this:<br><br><span st=
yle=3D"background-color: rgb(255, 255, 0);">=C2=A0=C2=A0=C2=A0 size_t searc=
h (const string& str, size_t pos =3D 0, size_t end =3D string::npos ) c=
onst noexcept;<br>=C2=A0=C2=A0=C2=A0 size_t search (const char* s, size_t p=
os =3D 0, size_t end =3D string::npos) const;<br>=C2=A0=C2=A0=C2=A0 size_t =
search (char c, size_t pos =3D 0, size_t end =3D string::npos) const noexce=
pt;</span><br><br>where the size_t end is the end position in string where =
the search will be made.<br></font></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/82be917c-b3c8-4cb4-bbbc-0f62ec78ce84%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/82be917c-b3c8-4cb4-bbbc-0f62ec78ce84=
%40isocpp.org</a>.<br />
------=_Part_3563_958530312.1496150755682--
------=_Part_3562_1611131057.1496150755682--
.
Author: =?UTF-8?Q?Jonathan_M=c3=bcller?= <jonathanmueller.dev@gmail.com>
Date: Tue, 30 May 2017 15:37:59 +0200
Raw View
Now with `string_view` this could easily be achieved by taking a
substring view and searching there. Problem is `std::string::substr()`
doesn't actually return a view which makes it kind of awkward (have to
create a view to the whole string, then substr).
--
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/fe3c4197-9cd6-3309-ee7a-1c6b99077081%40gmail.com.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 30 May 2017 08:01:27 -0700 (PDT)
Raw View
------=_Part_3461_2123507702.1496156488068
Content-Type: multipart/alternative;
boundary="----=_Part_3462_1034423566.1496156488069"
------=_Part_3462_1034423566.1496156488069
Content-Type: text/plain; charset="UTF-8"
On Tuesday, May 30, 2017 at 9:25:55 AM UTC-4, teco...@gmail.com wrote:
>
> I figure out we can set the start point of search on string but we cannot
> set the end. For example:
>
> mystring.find('A', 10, 15); //Search for
> 'A' into mystring starting on position 10 and ends on position 15 (into
> mystring)
>
> The problem is the actual implementation allow to set the quantity of
> characters to be searched from char*:
>
> size_t find (const char* s, size_t pos, size_type n) const;
>
> It is a little confusing and it should be deprecated.
>
> The best solution is make another function member like std::string::search
> to replace std::string::find. It could be like this:
>
> size_t search (const string& str, size_t pos = 0, size_t end =
> string::npos ) const noexcept;
> size_t search (const char* s, size_t pos = 0, size_t end =
> string::npos) const;
> size_t search (char c, size_t pos = 0, size_t end = string::npos)
> const noexcept;
>
> where the size_t end is the end position in string where the search will
> be made.
>
I'm not sure the cure here is better than the disease. With `string_view`
available, we should just encourage people to use that. Adding *yet another*
overload set of member functions isn't the most helpful thing we could do.
After all, `find` will still be there.
--
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/3fc83625-f594-42d1-bf7d-a30bf1b90a62%40isocpp.org.
------=_Part_3462_1034423566.1496156488069
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, May 30, 2017 at 9:25:55 AM UTC-4, teco=
....@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><font size=3D"4">I figure out we can set the start point of search=
on string but we cannot set the end. For example:<br><br></font><div style=
=3D"margin-left:40px"><font size=3D"4"><span style=3D"background-color:rgb(=
238,238,238)">mystring.find('A', 10, 15);=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<wbr>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 //Search for 'A' into mystring starting on posit=
ion 10 and ends on position 15 (into mystring)</span></font><br></div><font=
size=3D"4"><br>The problem is the actual implementation allow to set the q=
uantity of characters to be searched from char*:<br><br></font><div style=
=3D"margin-left:40px"><span style=3D"background-color:rgb(238,238,238)"><fo=
nt size=3D"4">size_t find (const char* s, size_t pos, size_type n) const;</=
font></span><br></div><font size=3D"4"><br>It is a little confusing and it =
should be deprecated.<br><br>The best solution is make another function mem=
ber like <span style=3D"background-color:rgb(255,255,0)">std::string::searc=
h</span> to replace <span style=3D"background-color:rgb(255,255,0)">std::st=
ring::find</span>. It could be like this:<br><br><span style=3D"background-=
color:rgb(255,255,0)">=C2=A0=C2=A0=C2=A0 size_t search (const string& s=
tr, size_t pos =3D 0, size_t end =3D string::npos ) const noexcept;<br>=C2=
=A0=C2=A0=C2=A0 size_t search (const char* s, size_t pos =3D 0, size_t end =
=3D string::npos) const;<br>=C2=A0=C2=A0=C2=A0 size_t search (char c, size_=
t pos =3D 0, size_t end =3D string::npos) const noexcept;</span><br><br>whe=
re the size_t end is the end position in string where the search will be ma=
de.<br></font></div></blockquote><div><br>I'm not sure the cure here is=
better than the disease. With `string_view` available, we should just enco=
urage people to use that. Adding <i>yet another</i> overload set of member =
functions isn't the most helpful thing we could do. After all, `find` w=
ill still be there.<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/3fc83625-f594-42d1-bf7d-a30bf1b90a62%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3fc83625-f594-42d1-bf7d-a30bf1b90a62=
%40isocpp.org</a>.<br />
------=_Part_3462_1034423566.1496156488069--
------=_Part_3461_2123507702.1496156488068--
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Tue, 30 May 2017 16:29:52 -0700 (PDT)
Raw View
------=_Part_3946_21777472.1496186992283
Content-Type: multipart/alternative;
boundary="----=_Part_3947_1417624030.1496186992284"
------=_Part_3947_1417624030.1496186992284
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Tuesday, May 30, 2017 at 6:38:03 AM UTC-7, Jonathan M=C3=BCller wrote:
>
> Now with `string_view` this could easily be achieved by taking a=20
> substring view and searching there. Problem is `std::string::substr()`=20
> doesn't actually return a view which makes it kind of awkward (have to=20
> create a view to the whole string, then substr).=20
>
That is, the OP's use-case is simply this:
std::string mystring;
// proposed extension:
auto p1 =3D mystring.find('A', 10, 15);
// actual C++17:
auto p1 =3D std::string_view(mystring).substr(10, 5).find('A');
Looks to me like we don't need any more surface area to get what he wants.
=E2=80=93Arthur
--=20
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 e=
mail 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/525dfba6-3329-4c8f-94eb-9f90b39e9a49%40isocpp.or=
g.
------=_Part_3947_1417624030.1496186992284
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, May 30, 2017 at 6:38:03 AM UTC-7, Jonathan M=
=C3=BCller wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Now with `str=
ing_view` this could easily be achieved by taking a=20
<br>substring view and searching there. Problem is `std::string::substr()`=
=20
<br>doesn't actually return a view which makes it kind of awkward (have=
to=20
<br>create a view to the whole string, then substr).
<br></blockquote><div><br></div><div>That is, the OP's use-case is simp=
ly this:</div><div><br></div><div>=C2=A0 =C2=A0 std::string mystring;</div>=
<div><br></div><div>=C2=A0 =C2=A0 // proposed extension:</div><div>=C2=A0 =
=C2=A0 auto p1 =3D mystring.find('A', 10, 15);<br></div><div><br></=
div><div>=C2=A0 =C2=A0 // actual C++17:</div><div>=C2=A0 =C2=A0 auto p1 =3D=
std::string_view(mystring).substr(10, 5).find('A');<br></div><div>=
<div><br></div></div><div>Looks to me like we don't need any more surfa=
ce area to get what he wants.</div><div><br></div><div>=E2=80=93Arthur</div=
></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/525dfba6-3329-4c8f-94eb-9f90b39e9a49%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/525dfba6-3329-4c8f-94eb-9f90b39e9a49=
%40isocpp.org</a>.<br />
------=_Part_3947_1417624030.1496186992284--
------=_Part_3946_21777472.1496186992283--
.