github.com/abemedia/appcast@v0.4.0/integrations/apt/deb/utils.go (about)

     1  package deb
     2  
     3  import (
     4  	"bytes"
     5  	"reflect"
     6  	"strings"
     7  	"sync"
     8  	"time"
     9  	"unsafe"
    10  )
    11  
    12  //nolint:gochecknoglobals
    13  var (
    14  	bufPool = sync.Pool{New: func() any { return bytes.NewBuffer(make([]byte, 1024)) }}
    15  
    16  	colon = []byte(":")
    17  	space = []byte(" ")
    18  	nl    = []byte("\n")
    19  
    20  	dateType = reflect.TypeOf((*time.Time)(nil)).Elem()
    21  )
    22  
    23  func getFieldName(field reflect.StructField) string {
    24  	if !field.IsExported() {
    25  		return ""
    26  	}
    27  
    28  	name, _, _ := strings.Cut(field.Tag.Get("deb"), ",")
    29  	if name == "" {
    30  		return field.Name
    31  	}
    32  	if name[0] == '-' {
    33  		return ""
    34  	}
    35  
    36  	return name
    37  }
    38  
    39  func trim(s []byte) []byte {
    40  	i := 0
    41  	for i < len(s) && (s[i] == ' ' || s[i] == '\t') {
    42  		i++
    43  	}
    44  	n := len(s)
    45  	for n > i && (s[n-1] == ' ' || s[n-1] == '\t' || s[n-1] == '\n' || s[n-1] == '\r') {
    46  		n--
    47  	}
    48  	return s[i:n]
    49  }
    50  
    51  func atob(s string) []byte {
    52  	return unsafe.Slice(unsafe.StringData(s), len(s))
    53  }
    54  
    55  func btoa(b []byte) string {
    56  	return *(*string)(unsafe.Pointer(&b))
    57  }