Welcome to mirror list, hosted at ThFree Co, Russian Federation.

byte.go « helper « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5c1f75463399bbdf529f2dcc3282471aa6ebca47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package helper

import (
	"bytes"
)

// ByteSliceHasAnyPrefix tests whether the byte slice s begins with any of the prefixes.
func ByteSliceHasAnyPrefix(s []byte, prefixes ...string) bool {
	for _, prefix := range prefixes {
		if bytes.HasPrefix(s, []byte(prefix)) {
			return true
		}
	}

	return false
}

// IsNumber tests whether the byte slice s contains only digits or not
func IsNumber(s []byte) bool {
	for i := range s {
		if !bytes.Contains([]byte("1234567890"), s[i:i+1]) {
			return false
		}
	}
	return true
}

// UnquoteBytes removes surrounding double-quotes from a byte slice returning
// a new slice if they exist, otherwise it returns the same byte slice passed.
func UnquoteBytes(s []byte) []byte {
	if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' {
		return s[1 : len(s)-1]
	}

	return s
}