Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

locate throws error #159

Open
MaxSagebaum opened this issue Jun 4, 2018 · 3 comments
Open

locate throws error #159

MaxSagebaum opened this issue Jun 4, 2018 · 3 comments

Comments

@MaxSagebaum
Copy link

A string.locate which does not find the string to locate throws an error in gsl e.g.:

create.gsl

.ignorecase = 0 
echo string.locate("Test", "Te")
echo string.locate("Test", "Ta")

The output is:

> gsl create    
GSL/4.1.4 Copyright (c) 1996-2016 iMatix Corporation
gsl/4 I: Processing create...
gsl/4 M: 0
(create.gsl 3) Undefined expression: string.locate (...)

Is there an option to catch this error or to return -1 instead?
The error message is also not very helpful. It should be something like:

(create.gsl 3) Could not locate 'Ta' in 'Test'.
@jschultz
Copy link
Contributor

jschultz commented Jun 4, 2018

The behaviour you observe is by design. That is, if the substring is not found string.locate returns an undefined value. If you want your code to handle such a case, you would do something like:

echo string.locate("Test", "Ta") ? "UNDEFINED"

or if you want to assign the (undefined) result to a variable

res = string.locate("Test", "Ta") ?

@MaxSagebaum
Copy link
Author

MaxSagebaum commented Jun 4, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants