Skip to content

Commit

Permalink
👔 up(arr,byte): update some tests and add byteutil add new func
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Mar 18, 2023
1 parent f4abba1 commit a31b4d6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions arrutil/arrutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,7 @@ func TestUnique(t *testing.T) {
assert.Eq(t, []int{2, 3, 4}, arrutil.Unique[int]([]int{2, 3, 2, 4}))
assert.Eq(t, []uint{2, 3, 4}, arrutil.Unique([]uint{2, 3, 2, 4}))
assert.Eq(t, []string{"ab", "bc", "cd"}, arrutil.Unique([]string{"ab", "bc", "ab", "cd"}))

assert.Eq(t, 1, arrutil.IndexOf(3, []int{2, 3, 4}))
assert.Eq(t, -1, arrutil.IndexOf(5, []int{2, 3, 4}))
}
11 changes: 11 additions & 0 deletions byteutil/byteutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package byteutil

import (
"bytes"
"unsafe"
)

// FirstLine from command output
Expand All @@ -27,3 +28,13 @@ func SafeString(bs []byte, err error) string {
}
return string(bs)
}

// String convert bytes to string
func String(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}

// ToString convert bytes to string
func ToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
2 changes: 1 addition & 1 deletion dump/_examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/gookit/color v1.5.2
github.com/gookit/goutil v0.6.0-00010101000000-000000000000
github.com/gookit/goutil v0.6.6-00010101000000-000000000000
github.com/kortschak/utter v1.0.1
github.com/kr/pretty v0.2.1
)
Expand Down
29 changes: 29 additions & 0 deletions sysutil/clipboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Clipboard

Package `clipboard` provide a simple clipboard read and write operations.

### Install

```bash
go get github.com/gookit/goutil/sysutil/clipboard
```

### Usage

Examples:

```go
src := "hello, this is clipboard"
err = clipboard.WriteString(src)
assert.NoErr(t, err)

// str: "hello, this is clipboard"
str, err = clipboard.ReadString()
assert.NoErr(t, err)
assert.NotEmpty(t, str)
assert.Eq(t, src, str)
```

## Related

- https://github.com/zyedidia/clipper

0 comments on commit a31b4d6

Please sign in to comment.