func insertHistory(buffer *bytes.Buffer, reader *strings.Reader, historyNo int) { history1 := conio.DefaultEditor.Histories[historyNo] ch, siz, _ := reader.ReadRune() if siz > 0 && ch == '^' { if len(history1.Word) >= 2 { buffer.WriteString(history1.At(1)) } } else if siz > 0 && ch == '$' { if len(history1.Word) >= 2 { buffer.WriteString(history1.At(-1)) } } else if siz > 0 && ch == '*' { if len(history1.Word) >= 2 { buffer.WriteString(strings.Join(history1.Word[1:], " ")) } } else if siz > 0 && ch == ':' { n, count := atoi_(reader) if count <= 0 { buffer.WriteRune(':') } else if n < len(history1.Word) { buffer.WriteString(history1.Word[n]) } } else { if siz > 0 { reader.UnreadRune() } buffer.WriteString(history1.Line) } }
func quotedWordCutter(reader *strings.Reader) (string, bool) { var buffer bytes.Buffer for { if reader.Len() <= 0 { return "", false } ch, _, _ := reader.ReadRune() if ch != ' ' { reader.UnreadRune() break } } quote := NULQUOTE yenCount := 0 for reader.Len() > 0 { ch, _, _ := reader.ReadRune() if yenCount%2 == 0 { if quote == NULQUOTE && (ch == '"' || ch == '\'') { quote = ch } else if quote != NULQUOTE && ch == quote { quote = NULQUOTE } } if ch == ' ' && quote == NULQUOTE { break } if ch == '\\' { yenCount++ } else { yenCount = 0 } buffer.WriteRune(ch) } return buffer.String(), true }
func atoi_(reader *strings.Reader) (int, int) { n := 0 count := 0 for reader.Len() > 0 { ch, _, _ := reader.ReadRune() index := strings.IndexRune("0123456789", ch) if index >= 0 { n = n*10 + index count++ } else { reader.UnreadRune() break } } return n, count }
func scanToken(rd *strings.Reader) (token string, err error) { r, _, err := rd.ReadRune() if err != nil { return "", err } if isSplitRune(r) { return string(r), nil } var tok []rune for { tok = append(tok, r) r, _, err = rd.ReadRune() if err != nil { return "", err } if isSplitRune(r) { rd.UnreadRune() return string(tok), nil } } }