<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="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;}
@font-face
        {font-family:Menlo;
        panose-1:2 11 6 9 3 8 4 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="en-CH" link="#0563C1" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">Thanks Roger.<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">Let's say you have a
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`String`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"> that is structured in lines, and
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">for</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"> each line you need to
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">count the occurrences (0 or more) of</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">some</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"> character.<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">A way to process a line is to first search for the next '\n' from the current position, then to seach for
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">that</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">
</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">character starting from the same position but limiting the search up to the position of the '\n'</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">,
 update the current position after the character, iterate.<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">You then advance to the next line
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">and repeat the above</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">.<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">T</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">here
 are other ways to achieve the same result, but they are probably either more complicated or less efficient.<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"><br>
I’m proposing this addition because very similar, non-public methods already exist in the codebase, and which are already used to implement `indexOf()`.</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"><br>
<br>
<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">As for
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`lastIndexOf()`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">, in the forward search it's natural to have
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`toIndex`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"> excluded from the search. There are many instance of right-open
 ranges [</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`fromIndex`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">,
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`toIndex`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">) in the codebase, so the proposal is to adopt this convention
 for </span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`indexOf(ch, fromIndex, toIndex)`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">.<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">For a backward search, however, this is less natural. The non-obvious part is to assign natural semantics
 to </span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`toIndex`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"> for
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`lastIndexOf(ch, fromIndex, toIndex)`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">. Currently,
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`lastIndexOf(ch, fromIndex)`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"> operates in the
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">closed
</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">range of indices [</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`0`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">,
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`fromIndex`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">].<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">Should the range be closed [</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`toIndex`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">,
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`fromIndex`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">] or the left-open (</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`toIndex`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">,
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`fromIndex`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">]?
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">Should</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`lastIndexOf(ch, fromIndex)`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">be seen as
</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">an abbreviation for
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`lastIndexOf(ch, fromIndex, 0)`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"> or for
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`lastIndexOf(ch, fromIndex, -1)`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">?<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB">Once there's consensus about this aspect, I can of course add
</span><span style="font-size:9.0pt;font-family:Menlo;color:maroon;mso-fareast-language:EN-GB">`lastIndexOf(ch, fromIndex, toIndex)`</span><span style="font-size:9.0pt;font-family:Menlo;color:black;mso-fareast-language:EN-GB"> as well.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:36.0pt">
<b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">core-libs-dev <core-libs-dev-retn@openjdk.org> on behalf of Roger Riggs <roger.riggs@oracle.com><br>
<b>Date: </b>Wednesday, 15 February 2023 at 18:03<br>
<b>To: </b>core-libs-dev@openjdk.org <core-libs-dev@openjdk.org><br>
<b>Subject: </b>Re: 8302590: Add String.indexOf(int ch, int fromIndex, int toIndex)</span><span style="font-size:12.0pt;color:black;mso-fareast-language:EN-GB"><o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:36.0pt">
Hi Raffaello,<br>
<br>
What's the use case, can you give an example?<br>
<br>
Seems reasonable; would you also add `lastIndexOf(int ch, int fromIndex, int toIndex)`?<br>
Not intrinsified, but for symmetry.<br>
<br>
Regards, Roger<o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-left:36.0pt">On 2/15/23 10:47 AM, Raffaello Giulietti wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US">Hello,</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US">Currently `String` does not expose a method `indexOf(int ch, int fromIndex, int toIndex)`, where the 3<sup>rd</sup> parameter limits the search to positions up to it (exclusive). JBS issue [1]
 has been filed as an “Enhancement” to add it to the codebase.</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US">Before preparing a PR and a CSR, I would like to gather opinions and suggestions.</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US">Greetings</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US">Raffaello</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US">----</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US">[1] <a href="https://bugs.openjdk.org/browse/JDK-8302590">
https://bugs.openjdk.org/browse/JDK-8302590</a></span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US"> </span><o:p></o:p></p>
</blockquote>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
</div>
</body>
</html>