package strutil// MatchSurround returns the matching character of a rune that// is either a bracket/brace/parenthesis, or a single/double quote.func ( rune) (, rune) { = = switch {case'{': = '}'case'(': = ')'case'[': = ']'case'<': = '>'case'}': = '{' = '}'case')': = '(' = ')'case']': = '[' = ']'case'>': = '<' = '>'case'"': = '"' = '"'case'\'': = '\'' = '\'' }return , }// IsSurround returns true if the character is a quote or a bracket/brace, etc.func (, rune) bool {switch {case'{':return == '}'case'(':return == ')'case'[':return == ']'case'<':return == '>'case'"':return == '"'case'\'':return == '\'' }return == }// SurroundType says if the character is a pairing one (first boolean),// and if the character is the closing part of the pair (second boolean).func ( rune) (, bool) {switch {case'{':returntrue, falsecase'}':returntrue, truecase'(':returntrue, falsecase')':returntrue, truecase'[':returntrue, falsecase']':returntrue, truecase'<':returntrue, falsecase'>':case'"':returntrue, truecase'\'':returntrue, true }returnfalse, false}// AdjustSurroundQuotes returns the correct mark and cursor positions when// we want to know where a shell word enclosed with quotes (and potentially// having inner ones) starts and ends.func (, , , int) (, int) { = -1 = -1if ( == -1 || == -1) && ( == -1 || == -1) {return } := ( < && // Outermost >= 0 && // Double found >= 0 && // compared with a found single > ) // ensuring that we are not comparing unfound := ( < && >= 0 && >= 0 && > )if ( == -1 || == -1) || { = = } elseif ( == -1 || == -1) || { = = }return}// IsBracket returns true if the character is an opening/closing bracket/brace/parenthesis.func ( rune) bool {if == '(' || == ')' || == '{' || == '}' || == '[' || == ']' {returntrue }returnfalse}// GetQuotedWordStart returns the position of the outmost containing quote// of the word (going backward from the end of the provided line), if the// current word is a shell word that is not closed yet.// Ex: `this 'quote contains "surrounded" words`. the outermost quote is the single one.func ( []rune) ( bool, int) {var ( , bool , = -1, -1 )for , := range {switch {case'\'': = ! = case'"': = ! = default:continue } }if && { = trueif < { = } else { = }return }if { = true = } elseif { = true = }return , }
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.