!51 完成InterIO.go:RecvUntil函数

Merge pull request !51 from a-alpha/alpha-dev
This commit is contained in:
a-alpha 2022-11-07 05:07:25 +00:00 committed by Gitee
commit e7cf7aed5a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 21 additions and 0 deletions

View File

@ -30,6 +30,7 @@ package Interpreter
import (
"bufio"
"bytes"
)
////////////////////////////////////////////////////////////////
@ -56,6 +57,26 @@ func (iio InterIO) Sendline(str string) (rc error) {
}
func (iio InterIO) RecvUntil(delim_s string) (ret string, rc error) {
output := ""
/* */
for {
recv, err := iio.reader.ReadBytes(delim_s[len(delim_s) - 1])
/* */
if (nil != err) {
return "", err
} // if ( ...
output += string(recv)
if ( ( len(recv) >= len(delim_s) ) &&
( bytes.Equal(recv[len(recv) - len(delim_s):], []byte(delim_s)) ) ) {
break
}
} // for { ...
ret = output
rc = nil
/* */
return ret, rc
}