bug fix:修正了InputMsg在空字符串场景下的问题

master v0.0.10
兔子 4 months ago
parent d528a583f4
commit 3c83d1d39f

@ -112,7 +112,10 @@ func (star *StarBuffer) Read(buf []byte) (int, error) {
data, err := star.getByte()
if err != nil {
if err == io.EOF {
return sum, err
if sum == 0 {
return sum, err
}
return sum, nil
}
if err == os.ErrNotExist {
i--

@ -168,7 +168,7 @@ func MessageBox(hint string, defaultVal string) InputMsg {
return InputMsg{msg: str, err: err}
}
func (im InputMsg) IgnoreSliceParseError(i bool) InputMsg {
func (im *InputMsg) IgnoreSliceParseError(i bool) *InputMsg {
im.skipSliceSigErr = i
return im
}
@ -189,6 +189,9 @@ func (im InputMsg) SliceString(sep string) ([]string, error) {
if im.err != nil {
return nil, im.err
}
if len(strings.TrimSpace(im.msg)) == 0 {
return []string{}, nil
}
return strings.Split(im.msg, sep), nil
}

@ -21,3 +21,29 @@ func Test_Slice(t *testing.T) {
}
fmt.Println(res)
}
func TestSliceMsg(t *testing.T) {
var data = InputMsg{
msg: "",
err: nil,
skipSliceSigErr: false,
}
res, err := data.SliceString(",")
if err != nil {
fmt.Println(res)
t.Fatal(err)
}
if len(res) != 0 {
t.Fatal(res)
}
fmt.Println(len(res))
res2, err := data.SliceInt64(",")
if err != nil {
fmt.Println(res2)
t.Fatal(err)
}
if len(res2) != 0 {
t.Fatal(res2)
}
fmt.Println(len(res2))
}

@ -16,7 +16,7 @@ func NewWaitGroup(maxCount int) WaitGroup {
return WaitGroup{wg: &sync.WaitGroup{}, maxCount: uint32(maxCount)}
}
func (swg *WaitGroup) Add(delta int) {
func (w *WaitGroup) Add(delta int) {
var Udelta uint32
if delta < 0 {
Udelta = uint32(-delta - 1)
@ -24,32 +24,32 @@ func (swg *WaitGroup) Add(delta int) {
Udelta = uint32(delta)
}
for {
allC := atomic.LoadUint32(&swg.allCount)
if atomic.LoadUint32(&swg.maxCount) == 0 || atomic.LoadUint32(&swg.maxCount) >= allC+uint32(delta) {
allC := atomic.LoadUint32(&w.allCount)
if atomic.LoadUint32(&w.maxCount) == 0 || atomic.LoadUint32(&w.maxCount) >= allC+uint32(delta) {
if delta < 0 {
atomic.AddUint32(&swg.allCount, ^uint32(Udelta))
atomic.AddUint32(&w.allCount, ^uint32(Udelta))
} else {
atomic.AddUint32(&swg.allCount, uint32(Udelta))
atomic.AddUint32(&w.allCount, uint32(Udelta))
}
break
}
time.Sleep(time.Microsecond)
}
swg.wg.Add(delta)
w.wg.Add(delta)
}
func (swg *WaitGroup) Done() {
swg.Add(-1)
func (w *WaitGroup) Done() {
w.Add(-1)
}
func (swg *WaitGroup) Wait() {
swg.wg.Wait()
func (w *WaitGroup) Wait() {
w.wg.Wait()
}
func (swg *WaitGroup) GetMaxWaitNum() int {
return int(atomic.LoadUint32(&swg.maxCount))
func (w *WaitGroup) GetMaxWaitNum() int {
return int(atomic.LoadUint32(&w.maxCount))
}
func (swg *WaitGroup) SetMaxWaitNum(num int) {
atomic.AddUint32(&swg.maxCount, uint32(num))
func (w *WaitGroup) SetMaxWaitNum(num int) {
atomic.AddUint32(&w.maxCount, uint32(num))
}

Loading…
Cancel
Save