extractWordBefore extracts the word that ends at the given position
(runes []rune, endPos int)
| 364 | |
| 365 | // extractWordBefore extracts the word that ends at the given position |
| 366 | func extractWordBefore(runes []rune, endPos int) string { |
| 367 | if endPos < 0 || endPos >= len(runes) { |
| 368 | return "" |
| 369 | } |
| 370 | |
| 371 | // Find the start of the word |
| 372 | start := endPos |
| 373 | for start >= 0 && (isLetter(runes[start]) || isDigit(runes[start]) || runes[start] == '_' || runes[start] == '$') { |
| 374 | start-- |
| 375 | } |
| 376 | start++ // Move to the first character of the word |
| 377 | |
| 378 | if start > endPos { |
| 379 | return "" |
| 380 | } |
| 381 | |
| 382 | return string(runes[start : endPos+1]) |
| 383 | } |
| 384 | |
| 385 | // isLetter checks if a rune is a letter |
| 386 | func isLetter(r rune) bool { |
no test coverage detected