Bug 5808 – std.string.indexOf enhancement with start-at parameter

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-04-03T11:53:00Z
Last change time
2014-07-07T13:31:23Z
Assigned to
nobody
Creator
ruzicic.aleksandar

Comments

Comment #0 by ruzicic.aleksandar — 2011-04-03T11:53:13Z
Other languages/libraries have start_index as an optional parameter used to start search at, in their versions of indexOf function. currently, signature of indexOf is: sizediff_t indexOf(Char)(in Char[] s, dchar c, CaseSensitive cs = CaseSensitive.yes); and desired is: sizediff_t indexOf(Char)(in Char[] s, dchar c, CaseSensitive cs = CaseSensitive.yes, sizediff_t sp = 0); where sp stands for "starting position" and is from where search will start. Negative indices -N should also be allowed to be able to search a char only in last N characters of the string. Example implementation of this parameter (it's really simple addition) can be found here: https://gist.github.com/900589 Note: if this gets copied to Phobos without changing, it must be properly tested, since I wrote it just as a quick example... Also, it would be great if this variation of indexOf template is added (which can be seen in the gist link above): sizediff_t indexOf(Char, T = sizediff_t)(in Char[] s, dchar c, T sp = 0) if (isSomeChar!Char) { return indexOf(s, c, CaseSensitive.yes, sp); } since it allows to skip case sensitivity parameter when not needed (which is mostly the case).
Comment #1 by rburners — 2014-07-07T13:31:23Z
D Hackday Round 2 precursor indexOf has a startIdx version now