From 7d1d74a3300155bfc0607e2abd816183188c579f Mon Sep 17 00:00:00 2001 From: Pit Capitain Date: Mon, 14 Nov 2022 11:29:08 +0100 Subject: [PATCH] Fix bug in Elm.Kernel.Parser.findSubString --- src/Elm/Kernel/Parser.js | 6 +++--- src/Parser/Advanced.elm | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Elm/Kernel/Parser.js b/src/Elm/Kernel/Parser.js index 958aabb..5588068 100644 --- a/src/Elm/Kernel/Parser.js +++ b/src/Elm/Kernel/Parser.js @@ -119,8 +119,8 @@ var _Parser_consumeBase16 = F2(function(offset, string) var _Parser_findSubString = F5(function(smallString, offset, row, col, bigString) { - var newOffset = bigString.indexOf(smallString, offset); - var target = newOffset < 0 ? bigString.length : newOffset + smallString.length; + var index = bigString.indexOf(smallString, offset); + var target = index < 0 ? bigString.length : index + smallString.length; while (offset < target) { @@ -130,5 +130,5 @@ var _Parser_findSubString = F5(function(smallString, offset, row, col, bigString : ( col++, (code & 0xF800) === 0xD800 && offset++ ) } - return __Utils_Tuple3(newOffset, row, col); + return __Utils_Tuple3(index < 0 ? -1 : target, row, col); }); diff --git a/src/Parser/Advanced.elm b/src/Parser/Advanced.elm index 6af483b..511c6e7 100644 --- a/src/Parser/Advanced.elm +++ b/src/Parser/Advanced.elm @@ -910,7 +910,7 @@ chompUntilEndOr str = Parser <| \s -> let (newOffset, newRow, newCol) = - Elm.Kernel.Parser.findSubString str s.offset s.row s.col s.src + findSubString str s.offset s.row s.col s.src adjustedOffset = if newOffset < 0 then String.length s.src else newOffset @@ -1125,7 +1125,7 @@ isAsciiCode = findSubString "42" offset row col "Is 42 the answer?" --==> (newOffset, newRow, newCol) -If `offset = 0` we would get `(3, 1, 4)` +If `offset = 0` we would get `(5, 1, 6)` If `offset = 7` we would get `(-1, 1, 18)` -} findSubString : String -> Int -> Int -> Int -> String -> (Int, Int, Int)