diff --git a/doc/site/core-library.markdown b/doc/site/core-library.markdown index f37c67a6..8cbcbc9d 100644 --- a/doc/site/core-library.markdown +++ b/doc/site/core-library.markdown @@ -244,7 +244,7 @@ It is a runtime error if `other` is not a number. ## String Class -An object representing a string that is created via the string literal syntax. +A string of Unicode code points stored in UTF-8. ### **contains**(other) @@ -264,8 +264,8 @@ It is a runtime error if `suffix` is not a string. ### **indexOf(search)** -Returns the index of `search` in the string or -1 if `search` is not a substring -of the string. +Returns the index of `search` in the string or -1 if `search` is not a +substring of the string. It is a runtime error if `search` is not a string. @@ -291,11 +291,12 @@ Check if the string is not equal to `other`. ### **[**index**]** operator -Returns a one character string of the value at `index`. This does not handle -UTF-8 characters correctly. +Returns a one character string of the value at `index`. It is a runtime error if `index` is greater than the length of the string. +*Note: This does not currently handle UTF-8 characters correctly.* + ## List Class **TODO** diff --git a/src/wren_core.c b/src/wren_core.c index ccd80b45..0ee7f528 100644 --- a/src/wren_core.c +++ b/src/wren_core.c @@ -955,7 +955,7 @@ DEF_NATIVE(string_indexOf) char* firstOccurrence = strstr(string->value, search->value); - RETURN_NUM(firstOccurrence ? (firstOccurrence - string->value) : -1); + RETURN_NUM(firstOccurrence ? firstOccurrence - string->value : -1); } DEF_NATIVE(string_startsWith) diff --git a/test/string/indexOf.wren b/test/string/index_of.wren similarity index 75% rename from test/string/indexOf.wren rename to test/string/index_of.wren index 67106d5c..7f983f58 100644 --- a/test/string/indexOf.wren +++ b/test/string/index_of.wren @@ -1,4 +1,4 @@ IO.print("abcd".indexOf("cd")) // expect: 2 IO.print("abcd".indexOf("a")) // expect: 0 IO.print("abcd".indexOf("abcde")) // expect: -1 -IO.print("abab".indexOf("ab")) // expect: 0 \ No newline at end of file +IO.print("abab".indexOf("ab")) // expect: 0 diff --git a/test/string/indexOf_invalid_arg.wren b/test/string/index_of_invalid_arg.wren similarity index 77% rename from test/string/indexOf_invalid_arg.wren rename to test/string/index_of_invalid_arg.wren index 171c0bd0..5d9393c5 100644 --- a/test/string/indexOf_invalid_arg.wren +++ b/test/string/index_of_invalid_arg.wren @@ -1 +1 @@ -IO.print("abcd".indexOf(null)) // expect runtime error: Argument must be a string. \ No newline at end of file +IO.print("abcd".indexOf(null)) // expect runtime error: Argument must be a string. diff --git a/test/string/startsWith.wren b/test/string/starts_with.wren similarity index 81% rename from test/string/startsWith.wren rename to test/string/starts_with.wren index be9691c0..cc2879e8 100644 --- a/test/string/startsWith.wren +++ b/test/string/starts_with.wren @@ -2,4 +2,4 @@ IO.print("abcd".startsWith("cd")) // expect: false IO.print("abcd".startsWith("a")) // expect: true IO.print("abcd".startsWith("abcd")) // expect: true IO.print("abcd".startsWith("abcde")) // expect: false -IO.print("abcd".startsWith("")) // expect: true \ No newline at end of file +IO.print("abcd".startsWith("")) // expect: true diff --git a/test/string/startsWith_invalid_arg.wren b/test/string/starts_with_invalid_arg.wren similarity index 74% rename from test/string/startsWith_invalid_arg.wren rename to test/string/starts_with_invalid_arg.wren index 25ffc605..7863aebc 100644 --- a/test/string/startsWith_invalid_arg.wren +++ b/test/string/starts_with_invalid_arg.wren @@ -1 +1 @@ -IO.print("abcd".startsWith(null)) // expect runtime error: Argument must be a string. \ No newline at end of file +IO.print("abcd".startsWith(null)) // expect runtime error: Argument must be a string.