Skip to content

Commit

Permalink
fix: getSpaceBoundaryIndiv stack overflow, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Mar 13, 2024
1 parent 9b5509f commit 5534e94
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions error_templates/java/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,21 @@ func getSpaceBoundaryIndiv(line string, idx int, defaultDirection spaceComputeDi
}

if defaultDirection == spaceComputeDirectionLeft {
// if idx is...
// 1. greater than 0
// 2. not a space character (if stopOnSpace is false)
// 3. or a space character (if stopOnSpace is true)
// then return the current index
if idx-1 >= 0 && ((!stopOnSpace && !isSpace(line, idx-1)) ||
(stopOnSpace && isSpace(line, idx-1))) {
return idx
}

// if idx is less than 0, return the current index
if idx-1 < 0 {
// check if the current index is not a space
if !isSpace(line, idx) {
// go to the reverse direction to get the nearest space
// check if the index next to the current index is a space
// if it is, then we go to the reverse direction to get the nearest space
if isSpace(line, idx+1) {
newIdx := getSpaceBoundaryIndiv(line, idx, spaceComputeDirectionRight)
return newIdx
}
Expand Down

0 comments on commit 5534e94

Please sign in to comment.