# Issue with return values of new 3 argument prevind and nextind functions

**URL:** <https://discourse.julialang.org/t/issue-with-return-values-of-new-3-argument-prevind-and-nextind-functions/9910>\
**Category:** Internals & Design\
**Created:** [March 22, 2018, 11:24pm UTC](https://discourse.julialang.org/t/issue-with-return-values-of-new-3-argument-prevind-and-nextind-functions/9910 "2018-03-22T23:24:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [March 22, 2018, 11:24pm UTC](https://discourse.julialang.org/t/issue-with-return-values-of-new-3-argument-prevind-and-nextind-functions/9910/1 "2018-03-22T23:24:23Z")

</div>

In cases where the number of characters plus the starting position is greater than `ncodeunits(str)+1`, `nextind` should really return (as documented) `ncodeunits(str)+1`.  
Also, if `nchar` is 0, `nextind` and `prevind` should act the same as `thisind`, IMO.  
`prevind`, if `nchar` is greater than the number of characters before the given position,  
should really return a 0, instead of some negative number.

```julia
julia> prevind("foobar", 7, 10000)
-9993

julia> nextind("foobar", 1, 10000)
10001

julia> prevind("foobar", 1)
0

julia> nextind("foobar", 6)
7

```

(I discovered this after implementing these new functions for my `Strs.jl` package, and then comparing the results to `nextind` and `prevind` on `String`).

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 23, 2018, 2:26am UTC](https://discourse.julialang.org/t/issue-with-return-values-of-new-3-argument-prevind-and-nextind-functions/9910/2 "2018-03-23T02:26:02Z")

</div>

There was a long discussion on GitHub. This is intentional and documented.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [March 23, 2018, 2:29am UTC](https://discourse.julialang.org/t/issue-with-return-values-of-new-3-argument-prevind-and-nextind-functions/9910/3 "2018-03-23T02:29:06Z")

</div>

What is the value of returning totally invalid indexes from `prevind` and `nextind`?  
That is inconsistent with the 2 argument forms of the functions.

Also, that behavior isn’t in the docstring.
