MCPcopy Create free account
hub / github.com/github/gh-aw / extractWordBefore

Function extractWordBefore

pkg/workflow/js.go:366–383  ·  view source on GitHub ↗

extractWordBefore extracts the word that ends at the given position

(runes []rune, endPos int)

Source from the content-addressed store, hash-verified

364
365// extractWordBefore extracts the word that ends at the given position
366func 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
386func isLetter(r rune) bool {

Callers 1

canStartRegexLiteralAtFunction · 0.85

Calls 2

isLetterFunction · 0.85
isDigitFunction · 0.85

Tested by

no test coverage detected