aboutsummaryrefslogtreecommitdiff
path: root/lib/bytes/bytes.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-02-21 08:35:02 +0700
committerShulhan <ms@kilabit.info>2019-02-21 09:05:46 +0700
commit4e4fda78a2126ac78c6c0fb88040e687bfc7950e (patch)
treedae2766f54c6d589502336bd73421cb54cf18b21 /lib/bytes/bytes.go
parent47af7f937043ba3c0f5920e1642438c2d2ca257a (diff)
downloadpakakeh.go-4e4fda78a2126ac78c6c0fb88040e687bfc7950e.tar.xz
memfs: add method to dump files as Go generated source
If you familiar with go-bindata [1], this method is similar with that. [1] github.com/shuLhan/go-bindata
Diffstat (limited to 'lib/bytes/bytes.go')
-rw-r--r--lib/bytes/bytes.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/bytes/bytes.go b/lib/bytes/bytes.go
index 63a502ab..83cd99c9 100644
--- a/lib/bytes/bytes.go
+++ b/lib/bytes/bytes.go
@@ -329,6 +329,34 @@ func ReadUint32(data []byte, x uint) uint32 {
}
//
+// InReplace do a reverse replace on input, any characters that is not on
+// allowed, will be replaced with character c.
+//
+func InReplace(in, allowed []byte, c byte) (out []byte) {
+ if len(in) == 0 {
+ return
+ }
+
+ out = make([]byte, len(in))
+ copy(out, in)
+ found := false
+ for x := 0; x < len(in); x++ {
+ found = false
+ for y := 0; y < len(allowed); y++ {
+ if in[x] == allowed[y] {
+ found = true
+ break
+ }
+ }
+ if !found {
+ out[x] = c
+ }
+ }
+
+ return
+}
+
+//
// SkipAfterToken skip all bytes until matched token is found and return the
// index after the token and boolean true.
//