id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
151,400
nmiyake/pkg
errorstringer/errorstringer.go
StackWithInterleavedMessages
func StackWithInterleavedMessages(err error) string { // error is expected to alternate between stackTracer and non-stackTracer errors expectStackTracer := true var stackErrs []errWithStack errCause := err for errCause != nil { s, isStackTracer := errCause.(stackTracer) if isStackTracer { stackErrs = append(stackErrs, errWithStack{ err: errCause, msg: errCause.Error(), stack: s.StackTrace(), }) } if c, ok := errCause.(causer); ok { if isStackTracer != expectStackTracer { // if current error is a causer and does not meet the expectation of whether or not it // should be a stackTracer, error is not supported. stackErrs = nil break } errCause = c.Cause() } else { break } expectStackTracer = !expectStackTracer } if len(stackErrs) == 0 { return fmt.Sprintf("%+v", err) } for i := len(stackErrs) - 1; i > 0; i-- { if hasSuffix(stackErrs[i].stack, stackErrs[i-1].stack) { // if the inner stack has the outer stack as a suffix, trim the outer stack from the inner stack stackErrs[i].stack = stackErrs[i].stack[0 : len(stackErrs[i].stack)-len(stackErrs[i-1].stack)] } } for i := 0; i < len(stackErrs)-1; i++ { stackErrs[i].msg = currErrMsg(stackErrs[i].err, stackErrs[i+1].err) } var errs []string if errCause != nil { // if root cause is non-nil, print its error message if it differs from cause stackErrs[len(stackErrs)-1].msg = currErrMsg(stackErrs[len(stackErrs)-1].err, errCause) rootErr := errCause.Error() if rootErr != stackErrs[len(stackErrs)-1].msg { errs = append(errs, errCause.Error()) } } for i := len(stackErrs) - 1; i >= 0; i-- { stack := strings.Replace(fmt.Sprintf("%+v", stackErrs[i].stack), "\n", "\n"+strings.Repeat("\t", 1), -1) errs = append(errs, stackErrs[i].msg+stack) } return strings.Join(errs, "\n") }
go
func StackWithInterleavedMessages(err error) string { // error is expected to alternate between stackTracer and non-stackTracer errors expectStackTracer := true var stackErrs []errWithStack errCause := err for errCause != nil { s, isStackTracer := errCause.(stackTracer) if isStackTracer { stackErrs = append(stackErrs, errWithStack{ err: errCause, msg: errCause.Error(), stack: s.StackTrace(), }) } if c, ok := errCause.(causer); ok { if isStackTracer != expectStackTracer { // if current error is a causer and does not meet the expectation of whether or not it // should be a stackTracer, error is not supported. stackErrs = nil break } errCause = c.Cause() } else { break } expectStackTracer = !expectStackTracer } if len(stackErrs) == 0 { return fmt.Sprintf("%+v", err) } for i := len(stackErrs) - 1; i > 0; i-- { if hasSuffix(stackErrs[i].stack, stackErrs[i-1].stack) { // if the inner stack has the outer stack as a suffix, trim the outer stack from the inner stack stackErrs[i].stack = stackErrs[i].stack[0 : len(stackErrs[i].stack)-len(stackErrs[i-1].stack)] } } for i := 0; i < len(stackErrs)-1; i++ { stackErrs[i].msg = currErrMsg(stackErrs[i].err, stackErrs[i+1].err) } var errs []string if errCause != nil { // if root cause is non-nil, print its error message if it differs from cause stackErrs[len(stackErrs)-1].msg = currErrMsg(stackErrs[len(stackErrs)-1].err, errCause) rootErr := errCause.Error() if rootErr != stackErrs[len(stackErrs)-1].msg { errs = append(errs, errCause.Error()) } } for i := len(stackErrs) - 1; i >= 0; i-- { stack := strings.Replace(fmt.Sprintf("%+v", stackErrs[i].stack), "\n", "\n"+strings.Repeat("\t", 1), -1) errs = append(errs, stackErrs[i].msg+stack) } return strings.Join(errs, "\n") }
[ "func", "StackWithInterleavedMessages", "(", "err", "error", ")", "string", "{", "// error is expected to alternate between stackTracer and non-stackTracer errors", "expectStackTracer", ":=", "true", "\n", "var", "stackErrs", "[", "]", "errWithStack", "\n", "errCause", ":=", ...
// StackWithInterleavedMessages prints the representation of the provided error as a stack trace with messages // interleaved in the relevant locations. If the error implements causer and the error and its causes alternate between // stackTracer and non-stackTracer errors, the returned string representation is one in which the messages are // interleaved at the proper positions in the stack and common stack frames in consecutive elements are removed. If the // provided error is not of this form, the result of printing the provided error using the "%+v" formatting directive is // returned.
[ "StackWithInterleavedMessages", "prints", "the", "representation", "of", "the", "provided", "error", "as", "a", "stack", "trace", "with", "messages", "interleaved", "in", "the", "relevant", "locations", ".", "If", "the", "error", "implements", "causer", "and", "th...
ae0375219445def9b33b6fcbf5eb8f4dd68ea561
https://github.com/nmiyake/pkg/blob/ae0375219445def9b33b6fcbf5eb8f4dd68ea561/errorstringer/errorstringer.go#L109-L166
151,401
nmiyake/pkg
errorstringer/errorstringer.go
hasSuffix
func hasSuffix(inner errors.StackTrace, outer errors.StackTrace) bool { outerIndex := len(outer) - 1 innerIndex := len(inner) - 1 for outerIndex >= 0 && innerIndex >= 0 { if outer[outerIndex] != inner[innerIndex] { break } outerIndex-- innerIndex-- } return outerIndex == 0 && innerIndex >= 0 }
go
func hasSuffix(inner errors.StackTrace, outer errors.StackTrace) bool { outerIndex := len(outer) - 1 innerIndex := len(inner) - 1 for outerIndex >= 0 && innerIndex >= 0 { if outer[outerIndex] != inner[innerIndex] { break } outerIndex-- innerIndex-- } return outerIndex == 0 && innerIndex >= 0 }
[ "func", "hasSuffix", "(", "inner", "errors", ".", "StackTrace", ",", "outer", "errors", ".", "StackTrace", ")", "bool", "{", "outerIndex", ":=", "len", "(", "outer", ")", "-", "1", "\n", "innerIndex", ":=", "len", "(", "inner", ")", "-", "1", "\n", "...
// hasSuffix returns true if the inner stack trace ends with the outer stack trace, false otherwise.
[ "hasSuffix", "returns", "true", "if", "the", "inner", "stack", "trace", "ends", "with", "the", "outer", "stack", "trace", "false", "otherwise", "." ]
ae0375219445def9b33b6fcbf5eb8f4dd68ea561
https://github.com/nmiyake/pkg/blob/ae0375219445def9b33b6fcbf5eb8f4dd68ea561/errorstringer/errorstringer.go#L179-L190
151,402
fanout/go-pubcontrol
item.go
Export
func (item *Item) Export() (map[string]interface{}, error) { formatNames := make([]string, 0) for _, format := range item.formats { for _, formatName := range formatNames { if formatName == format.Name() { return nil, &ItemFormatError{err: "Only one instance of a " + "specific Formatter implementation can be specified."} } } formatNames = append(formatNames, format.Name()) } out := make(map[string]interface{}) if item.id != "" { out["id"] = item.id } if item.prevId != "" { out["prev-id"] = item.prevId } for _, format := range item.formats { out[format.Name()] = format.Export() } return out, nil }
go
func (item *Item) Export() (map[string]interface{}, error) { formatNames := make([]string, 0) for _, format := range item.formats { for _, formatName := range formatNames { if formatName == format.Name() { return nil, &ItemFormatError{err: "Only one instance of a " + "specific Formatter implementation can be specified."} } } formatNames = append(formatNames, format.Name()) } out := make(map[string]interface{}) if item.id != "" { out["id"] = item.id } if item.prevId != "" { out["prev-id"] = item.prevId } for _, format := range item.formats { out[format.Name()] = format.Export() } return out, nil }
[ "func", "(", "item", "*", "Item", ")", "Export", "(", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "formatNames", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "format", ":="...
// The export method serializes all of the formats, ID, and previous ID // into a hash that is used for publishing to clients. If more than one // instance of the same type of Format implementation was specified then // an error will be raised.
[ "The", "export", "method", "serializes", "all", "of", "the", "formats", "ID", "and", "previous", "ID", "into", "a", "hash", "that", "is", "used", "for", "publishing", "to", "clients", ".", "If", "more", "than", "one", "instance", "of", "the", "same", "ty...
6700863ff8fe6be673bfa0c25c391077b328a8c4
https://github.com/fanout/go-pubcontrol/blob/6700863ff8fe6be673bfa0c25c391077b328a8c4/item.go#L37-L59
151,403
fanout/go-pubcontrol
pubcontrolclient.go
NewPubControlClient
func NewPubControlClient(uri string) *PubControlClient { // This is basically the same as the default in Go 1.6, but with these changes: // Timeout: 30s -> 10s // TLSHandshakeTimeout: 10s -> 7s // MaxIdleConnsPerHost: 2 -> 100 transport := &http.Transport{ Proxy: http.ProxyFromEnvironment, Dial: (&net.Dialer{ Timeout: 10 * time.Second, KeepAlive: 30 * time.Second, }).Dial, TLSHandshakeTimeout: 7 * time.Second, ExpectContinueTimeout: 1 * time.Second, MaxIdleConnsPerHost: 100, } newPcc := new(PubControlClient) newPcc.uri = uri newPcc.lock = &sync.Mutex{} newPcc.pubCall = pubCall newPcc.publish = publish newPcc.makeHttpRequest = makeHttpRequest newPcc.httpClient = &http.Client{Transport: transport, Timeout: 15 * time.Second} return newPcc }
go
func NewPubControlClient(uri string) *PubControlClient { // This is basically the same as the default in Go 1.6, but with these changes: // Timeout: 30s -> 10s // TLSHandshakeTimeout: 10s -> 7s // MaxIdleConnsPerHost: 2 -> 100 transport := &http.Transport{ Proxy: http.ProxyFromEnvironment, Dial: (&net.Dialer{ Timeout: 10 * time.Second, KeepAlive: 30 * time.Second, }).Dial, TLSHandshakeTimeout: 7 * time.Second, ExpectContinueTimeout: 1 * time.Second, MaxIdleConnsPerHost: 100, } newPcc := new(PubControlClient) newPcc.uri = uri newPcc.lock = &sync.Mutex{} newPcc.pubCall = pubCall newPcc.publish = publish newPcc.makeHttpRequest = makeHttpRequest newPcc.httpClient = &http.Client{Transport: transport, Timeout: 15 * time.Second} return newPcc }
[ "func", "NewPubControlClient", "(", "uri", "string", ")", "*", "PubControlClient", "{", "// This is basically the same as the default in Go 1.6, but with these changes:", "// Timeout: 30s -> 10s", "// TLSHandshakeTimeout: 10s -> 7s", "// MaxIdleConnsPerHost: 2 -> 100", "transport", ":=",...
// Initialize this struct with a URL representing the publishing endpoint.
[ "Initialize", "this", "struct", "with", "a", "URL", "representing", "the", "publishing", "endpoint", "." ]
6700863ff8fe6be673bfa0c25c391077b328a8c4
https://github.com/fanout/go-pubcontrol/blob/6700863ff8fe6be673bfa0c25c391077b328a8c4/pubcontrolclient.go#L55-L79
151,404
fanout/go-pubcontrol
pubcontrolclient.go
SetAuthBasic
func (pcc *PubControlClient) SetAuthBasic(username, password string) { pcc.lock.Lock() pcc.authBasicUser = username pcc.authBasicPass = password pcc.lock.Unlock() }
go
func (pcc *PubControlClient) SetAuthBasic(username, password string) { pcc.lock.Lock() pcc.authBasicUser = username pcc.authBasicPass = password pcc.lock.Unlock() }
[ "func", "(", "pcc", "*", "PubControlClient", ")", "SetAuthBasic", "(", "username", ",", "password", "string", ")", "{", "pcc", ".", "lock", ".", "Lock", "(", ")", "\n", "pcc", ".", "authBasicUser", "=", "username", "\n", "pcc", ".", "authBasicPass", "=",...
// Call this method and pass a username and password to use basic // authentication with the configured endpoint.
[ "Call", "this", "method", "and", "pass", "a", "username", "and", "password", "to", "use", "basic", "authentication", "with", "the", "configured", "endpoint", "." ]
6700863ff8fe6be673bfa0c25c391077b328a8c4
https://github.com/fanout/go-pubcontrol/blob/6700863ff8fe6be673bfa0c25c391077b328a8c4/pubcontrolclient.go#L83-L88
151,405
fanout/go-pubcontrol
pubcontrolclient.go
SetAuthJwt
func (pcc *PubControlClient) SetAuthJwt(claim map[string]interface{}, key []byte) { pcc.lock.Lock() pcc.authJwtClaim = claim pcc.authJwtKey = key pcc.lock.Unlock() }
go
func (pcc *PubControlClient) SetAuthJwt(claim map[string]interface{}, key []byte) { pcc.lock.Lock() pcc.authJwtClaim = claim pcc.authJwtKey = key pcc.lock.Unlock() }
[ "func", "(", "pcc", "*", "PubControlClient", ")", "SetAuthJwt", "(", "claim", "map", "[", "string", "]", "interface", "{", "}", ",", "key", "[", "]", "byte", ")", "{", "pcc", ".", "lock", ".", "Lock", "(", ")", "\n", "pcc", ".", "authJwtClaim", "="...
// Call this method and pass a claim and key to use JWT authentication // with the configured endpoint.
[ "Call", "this", "method", "and", "pass", "a", "claim", "and", "key", "to", "use", "JWT", "authentication", "with", "the", "configured", "endpoint", "." ]
6700863ff8fe6be673bfa0c25c391077b328a8c4
https://github.com/fanout/go-pubcontrol/blob/6700863ff8fe6be673bfa0c25c391077b328a8c4/pubcontrolclient.go#L92-L98
151,406
fanout/go-pubcontrol
pubcontrolclient.go
Publish
func (pcc *PubControlClient) Publish(channel string, item *Item) error { return pcc.publish(pcc, channel, item) }
go
func (pcc *PubControlClient) Publish(channel string, item *Item) error { return pcc.publish(pcc, channel, item) }
[ "func", "(", "pcc", "*", "PubControlClient", ")", "Publish", "(", "channel", "string", ",", "item", "*", "Item", ")", "error", "{", "return", "pcc", ".", "publish", "(", "pcc", ",", "channel", ",", "item", ")", "\n", "}" ]
// The publish method for publishing the specified item to the specified // channel on the configured endpoint.
[ "The", "publish", "method", "for", "publishing", "the", "specified", "item", "to", "the", "specified", "channel", "on", "the", "configured", "endpoint", "." ]
6700863ff8fe6be673bfa0c25c391077b328a8c4
https://github.com/fanout/go-pubcontrol/blob/6700863ff8fe6be673bfa0c25c391077b328a8c4/pubcontrolclient.go#L132-L134
151,407
fanout/go-pubcontrol
pubcontrolclient.go
publish
func publish(pcc *PubControlClient, channel string, item *Item) error { export, err := item.Export() if err != nil { return err } export["channel"] = channel uri := "" auth := "" pcc.lock.Lock() uri = pcc.uri auth, err = pcc.generateAuthHeader() pcc.lock.Unlock() if err != nil { return err } err = pcc.pubCall(pcc, uri, auth, [](map[string]interface{}){export}) if err != nil { return err } return nil }
go
func publish(pcc *PubControlClient, channel string, item *Item) error { export, err := item.Export() if err != nil { return err } export["channel"] = channel uri := "" auth := "" pcc.lock.Lock() uri = pcc.uri auth, err = pcc.generateAuthHeader() pcc.lock.Unlock() if err != nil { return err } err = pcc.pubCall(pcc, uri, auth, [](map[string]interface{}){export}) if err != nil { return err } return nil }
[ "func", "publish", "(", "pcc", "*", "PubControlClient", ",", "channel", "string", ",", "item", "*", "Item", ")", "error", "{", "export", ",", "err", ":=", "item", ".", "Export", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", ...
// An internal publish method to facilitate testing.
[ "An", "internal", "publish", "method", "to", "facilitate", "testing", "." ]
6700863ff8fe6be673bfa0c25c391077b328a8c4
https://github.com/fanout/go-pubcontrol/blob/6700863ff8fe6be673bfa0c25c391077b328a8c4/pubcontrolclient.go#L137-L157
151,408
fanout/go-pubcontrol
pubcontrolclient.go
pubCall
func pubCall(pcc *PubControlClient, uri, authHeader string, items []map[string]interface{}) error { uri = strings.Join([]string{uri, "/publish/"}, "") content := make(map[string]interface{}) content["items"] = items var jsonContent []byte jsonContent, err := json.Marshal(content) if err != nil { return err } statusCode, body, err := pcc.makeHttpRequest(pcc, uri, authHeader, jsonContent) if err != nil { return err } if statusCode < 200 || statusCode >= 300 { return &PublishError{err: strings.Join([]string{"Failure status code: ", strconv.Itoa(statusCode), " with message: ", string(body)}, "")} } return nil }
go
func pubCall(pcc *PubControlClient, uri, authHeader string, items []map[string]interface{}) error { uri = strings.Join([]string{uri, "/publish/"}, "") content := make(map[string]interface{}) content["items"] = items var jsonContent []byte jsonContent, err := json.Marshal(content) if err != nil { return err } statusCode, body, err := pcc.makeHttpRequest(pcc, uri, authHeader, jsonContent) if err != nil { return err } if statusCode < 200 || statusCode >= 300 { return &PublishError{err: strings.Join([]string{"Failure status code: ", strconv.Itoa(statusCode), " with message: ", string(body)}, "")} } return nil }
[ "func", "pubCall", "(", "pcc", "*", "PubControlClient", ",", "uri", ",", "authHeader", "string", ",", "items", "[", "]", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "uri", "=", "strings", ".", "Join", "(", "[", "]", "string",...
// An internal method for preparing the HTTP POST request for publishing // data to the endpoint. This method accepts the URI endpoint, authorization // header, and a list of items to publish.
[ "An", "internal", "method", "for", "preparing", "the", "HTTP", "POST", "request", "for", "publishing", "data", "to", "the", "endpoint", ".", "This", "method", "accepts", "the", "URI", "endpoint", "authorization", "header", "and", "a", "list", "of", "items", ...
6700863ff8fe6be673bfa0c25c391077b328a8c4
https://github.com/fanout/go-pubcontrol/blob/6700863ff8fe6be673bfa0c25c391077b328a8c4/pubcontrolclient.go#L162-L183
151,409
fanout/go-pubcontrol
pubcontrolclient.go
makeHttpRequest
func makeHttpRequest(pcc *PubControlClient, uri, authHeader string, jsonContent []byte) (int, []byte, error) { var req *http.Request req, err := http.NewRequest("POST", uri, bytes.NewReader(jsonContent)) if err != nil { return 0, nil, err } req.Header.Add("Content-Type", "application/json") req.Header.Add("Authorization", authHeader) resp, err := pcc.httpClient.Do(req) if err != nil { return 0, nil, err } defer resp.Body.Close() var body []byte body, err = ioutil.ReadAll(resp.Body) if err != nil { return 0, nil, err } return resp.StatusCode, body, nil }
go
func makeHttpRequest(pcc *PubControlClient, uri, authHeader string, jsonContent []byte) (int, []byte, error) { var req *http.Request req, err := http.NewRequest("POST", uri, bytes.NewReader(jsonContent)) if err != nil { return 0, nil, err } req.Header.Add("Content-Type", "application/json") req.Header.Add("Authorization", authHeader) resp, err := pcc.httpClient.Do(req) if err != nil { return 0, nil, err } defer resp.Body.Close() var body []byte body, err = ioutil.ReadAll(resp.Body) if err != nil { return 0, nil, err } return resp.StatusCode, body, nil }
[ "func", "makeHttpRequest", "(", "pcc", "*", "PubControlClient", ",", "uri", ",", "authHeader", "string", ",", "jsonContent", "[", "]", "byte", ")", "(", "int", ",", "[", "]", "byte", ",", "error", ")", "{", "var", "req", "*", "http", ".", "Request", ...
// An internal method used to make the HTTP request for publishing based // on the specified URI, auth header, and JSON content. An HTTP status // code, response body, and an error will be returned.
[ "An", "internal", "method", "used", "to", "make", "the", "HTTP", "request", "for", "publishing", "based", "on", "the", "specified", "URI", "auth", "header", "and", "JSON", "content", ".", "An", "HTTP", "status", "code", "response", "body", "and", "an", "er...
6700863ff8fe6be673bfa0c25c391077b328a8c4
https://github.com/fanout/go-pubcontrol/blob/6700863ff8fe6be673bfa0c25c391077b328a8c4/pubcontrolclient.go#L188-L208
151,410
martinusso/go-docs
cpf/cpf.go
Valid
func Valid(cpf string) bool { isValid, err := AssertValid(cpf) if err != nil { return false } return isValid }
go
func Valid(cpf string) bool { isValid, err := AssertValid(cpf) if err != nil { return false } return isValid }
[ "func", "Valid", "(", "cpf", "string", ")", "bool", "{", "isValid", ",", "err", ":=", "AssertValid", "(", "cpf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "isValid", "\n", "}" ]
// Valid validates the CPF returning a boolean
[ "Valid", "validates", "the", "CPF", "returning", "a", "boolean" ]
84299b8633b3adbaa5cf9696455795c2b1eb023e
https://github.com/martinusso/go-docs/blob/84299b8633b3adbaa5cf9696455795c2b1eb023e/cpf/cpf.go#L20-L26
151,411
martinusso/go-docs
cpf/cpf.go
AssertValid
func AssertValid(cpf string) (bool, error) { cpf = sanitize(cpf) if len(cpf) != cpfValidLength { return false, errors.New(invalidLength) } for i := 0; i <= 9; i++ { if cpf == strings.Repeat(strconv.Itoa(i), 11) { return false, errors.New(repeatedDigits) } } return checkDigits(cpf), nil }
go
func AssertValid(cpf string) (bool, error) { cpf = sanitize(cpf) if len(cpf) != cpfValidLength { return false, errors.New(invalidLength) } for i := 0; i <= 9; i++ { if cpf == strings.Repeat(strconv.Itoa(i), 11) { return false, errors.New(repeatedDigits) } } return checkDigits(cpf), nil }
[ "func", "AssertValid", "(", "cpf", "string", ")", "(", "bool", ",", "error", ")", "{", "cpf", "=", "sanitize", "(", "cpf", ")", "\n", "if", "len", "(", "cpf", ")", "!=", "cpfValidLength", "{", "return", "false", ",", "errors", ".", "New", "(", "inv...
// AssertValid validates the CPF returning a boolean and the error if any
[ "AssertValid", "validates", "the", "CPF", "returning", "a", "boolean", "and", "the", "error", "if", "any" ]
84299b8633b3adbaa5cf9696455795c2b1eb023e
https://github.com/martinusso/go-docs/blob/84299b8633b3adbaa5cf9696455795c2b1eb023e/cpf/cpf.go#L29-L40
151,412
martinusso/go-docs
cpf/cpf.go
Generate
func Generate() string { rand.Seed(time.Now().UTC().UnixNano()) data := make([]int, 9) for i := 0; i < 9; i++ { data[i] = rand.Intn(9) } checkDigit1 := computeCheckDigit(data) data = append(data, checkDigit1) checkDigit2 := computeCheckDigit(data) data = append(data, checkDigit2) var cpf string for _, value := range data { cpf += strconv.Itoa(value) } return cpf }
go
func Generate() string { rand.Seed(time.Now().UTC().UnixNano()) data := make([]int, 9) for i := 0; i < 9; i++ { data[i] = rand.Intn(9) } checkDigit1 := computeCheckDigit(data) data = append(data, checkDigit1) checkDigit2 := computeCheckDigit(data) data = append(data, checkDigit2) var cpf string for _, value := range data { cpf += strconv.Itoa(value) } return cpf }
[ "func", "Generate", "(", ")", "string", "{", "rand", ".", "Seed", "(", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ".", "UnixNano", "(", ")", ")", "\n\n", "data", ":=", "make", "(", "[", "]", "int", ",", "9", ")", "\n", "for", "i", ...
// Generate returns a random valid CPF
[ "Generate", "returns", "a", "random", "valid", "CPF" ]
84299b8633b3adbaa5cf9696455795c2b1eb023e
https://github.com/martinusso/go-docs/blob/84299b8633b3adbaa5cf9696455795c2b1eb023e/cpf/cpf.go#L43-L60
151,413
cosiner/gohper
os2/path2/path.go
ExpandHome
func ExpandHome(path string) string { if len(path) == 0 || path[0] != '~' { return path } u, _ := user.Current() return u.HomeDir + path[1:] }
go
func ExpandHome(path string) string { if len(path) == 0 || path[0] != '~' { return path } u, _ := user.Current() return u.HomeDir + path[1:] }
[ "func", "ExpandHome", "(", "path", "string", ")", "string", "{", "if", "len", "(", "path", ")", "==", "0", "||", "path", "[", "0", "]", "!=", "'~'", "{", "return", "path", "\n", "}", "\n\n", "u", ",", "_", ":=", "user", ".", "Current", "(", ")"...
// ExpandHome expand ~ to user's home dir
[ "ExpandHome", "expand", "~", "to", "user", "s", "home", "dir" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/path2/path.go#L22-L30
151,414
cosiner/gohper
os2/path2/path.go
ExpandAbs
func ExpandAbs(path string) string { path, _ = filepath.Abs(ExpandHome(path)) return path }
go
func ExpandAbs(path string) string { path, _ = filepath.Abs(ExpandHome(path)) return path }
[ "func", "ExpandAbs", "(", "path", "string", ")", "string", "{", "path", ",", "_", "=", "filepath", ".", "Abs", "(", "ExpandHome", "(", "path", ")", ")", "\n\n", "return", "path", "\n", "}" ]
// ExpandAbs expand path to absolute path
[ "ExpandAbs", "expand", "path", "to", "absolute", "path" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/path2/path.go#L33-L37
151,415
cosiner/gohper
os2/path2/path.go
LastDir
func LastDir(path string) (string, error) { absPath, err := filepath.Abs(path) if err != nil { return "", err } info, err := os.Stat(absPath) if err != nil { return "", err } var dir string if info.IsDir() { _, dir = filepath.Split(absPath) } else { dir = filepath.Dir(absPath) _, dir = filepath.Split(dir) } return dir, nil }
go
func LastDir(path string) (string, error) { absPath, err := filepath.Abs(path) if err != nil { return "", err } info, err := os.Stat(absPath) if err != nil { return "", err } var dir string if info.IsDir() { _, dir = filepath.Split(absPath) } else { dir = filepath.Dir(absPath) _, dir = filepath.Split(dir) } return dir, nil }
[ "func", "LastDir", "(", "path", "string", ")", "(", "string", ",", "error", ")", "{", "absPath", ",", "err", ":=", "filepath", ".", "Abs", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n",...
// LastDir return last dir of path, // if path is dir, return itself // else return path's contain dir name
[ "LastDir", "return", "last", "dir", "of", "path", "if", "path", "is", "dir", "return", "itself", "else", "return", "path", "s", "contain", "dir", "name" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/path2/path.go#L47-L67
151,416
cosiner/gohper
os2/path2/path.go
IsWinRoot
func IsWinRoot(path string) bool { if path == "" { return false } return unibyte.IsLetter(path[0]) && strings.HasPrefix(path[1:], ":\\") }
go
func IsWinRoot(path string) bool { if path == "" { return false } return unibyte.IsLetter(path[0]) && strings.HasPrefix(path[1:], ":\\") }
[ "func", "IsWinRoot", "(", "path", "string", ")", "bool", "{", "if", "path", "==", "\"", "\"", "{", "return", "false", "\n", "}", "\n\n", "return", "unibyte", ".", "IsLetter", "(", "path", "[", "0", "]", ")", "&&", "strings", ".", "HasPrefix", "(", ...
// IsWinRoot check whether a path is windows absolute path with disk letter
[ "IsWinRoot", "check", "whether", "a", "path", "is", "windows", "absolute", "path", "with", "disk", "letter" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/path2/path.go#L79-L85
151,417
cosiner/gohper
os2/path2/path.go
IsRoot
func IsRoot(path string) bool { l := len(path) if l == 0 { return false } switch os2.OS() { case os2.WINDOWS: return IsWinRoot(path) case os2.LINUX, os2.DARWIN, os2.FREEBSD, os2.SOLARIS, os2.ANDROID: return l == 1 && path[0] == '/' default: return false } }
go
func IsRoot(path string) bool { l := len(path) if l == 0 { return false } switch os2.OS() { case os2.WINDOWS: return IsWinRoot(path) case os2.LINUX, os2.DARWIN, os2.FREEBSD, os2.SOLARIS, os2.ANDROID: return l == 1 && path[0] == '/' default: return false } }
[ "func", "IsRoot", "(", "path", "string", ")", "bool", "{", "l", ":=", "len", "(", "path", ")", "\n", "if", "l", "==", "0", "{", "return", "false", "\n", "}", "\n\n", "switch", "os2", ".", "OS", "(", ")", "{", "case", "os2", ".", "WINDOWS", ":",...
// IsRoot check wether or not path is root of filesystem
[ "IsRoot", "check", "wether", "or", "not", "path", "is", "root", "of", "filesystem" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/path2/path.go#L88-L102
151,418
cosiner/gohper
os2/file/rw.go
Open
func Open(fname string, flags int, fn FileOpFunc) error { fd, err := os.OpenFile(fname, flags, FilePerm) if err != nil { return err } if fn != nil { err = fn(fd) } if e := fd.Close(); e != nil && err == nil { err = e } return io2.NonEOF(err) }
go
func Open(fname string, flags int, fn FileOpFunc) error { fd, err := os.OpenFile(fname, flags, FilePerm) if err != nil { return err } if fn != nil { err = fn(fd) } if e := fd.Close(); e != nil && err == nil { err = e } return io2.NonEOF(err) }
[ "func", "Open", "(", "fname", "string", ",", "flags", "int", ",", "fn", "FileOpFunc", ")", "error", "{", "fd", ",", "err", ":=", "os", ".", "OpenFile", "(", "fname", ",", "flags", ",", "FilePerm", ")", "\n", "if", "err", "!=", "nil", "{", "return",...
// Open file use given flag
[ "Open", "file", "use", "given", "flag" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/file/rw.go#L19-L33
151,419
cosiner/gohper
os2/file/rw.go
FirstLine
func FirstLine(src string) (line string, err error) { err = Filter(src, func(_ int, l []byte) (error) { line = string(l) return io.EOF }) return }
go
func FirstLine(src string) (line string, err error) { err = Filter(src, func(_ int, l []byte) (error) { line = string(l) return io.EOF }) return }
[ "func", "FirstLine", "(", "src", "string", ")", "(", "line", "string", ",", "err", "error", ")", "{", "err", "=", "Filter", "(", "src", ",", "func", "(", "_", "int", ",", "l", "[", "]", "byte", ")", "(", "error", ")", "{", "line", "=", "string"...
// FirstLine read first line from file
[ "FirstLine", "read", "first", "line", "from", "file" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/file/rw.go#L45-L53
151,420
cosiner/gohper
os2/file/rw.go
Filter
func Filter(src string, filter func(int, []byte) error) error { return Read(src, func(fd *os.File) (err error) { return io2.FilterRead(fd, filter) }) }
go
func Filter(src string, filter func(int, []byte) error) error { return Read(src, func(fd *os.File) (err error) { return io2.FilterRead(fd, filter) }) }
[ "func", "Filter", "(", "src", "string", ",", "filter", "func", "(", "int", ",", "[", "]", "byte", ")", "error", ")", "error", "{", "return", "Read", "(", "src", ",", "func", "(", "fd", "*", "os", ".", "File", ")", "(", "err", "error", ")", "{",...
// Filter file content with given filter, file is in ReadOnly mode
[ "Filter", "file", "content", "with", "given", "filter", "file", "is", "in", "ReadOnly", "mode" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/file/rw.go#L56-L60
151,421
cosiner/gohper
os2/file/rw.go
FilterTo
func FilterTo(dst, src string, trunc bool, filter io2.LineFilterFunc) error { return Read(src, func(sfd *os.File) (err error) { return OpenOrCreate(dst, trunc, func(dfd *os.File) error { return io2.Filter(sfd, dfd, true, filter) }) }) }
go
func FilterTo(dst, src string, trunc bool, filter io2.LineFilterFunc) error { return Read(src, func(sfd *os.File) (err error) { return OpenOrCreate(dst, trunc, func(dfd *os.File) error { return io2.Filter(sfd, dfd, true, filter) }) }) }
[ "func", "FilterTo", "(", "dst", ",", "src", "string", ",", "trunc", "bool", ",", "filter", "io2", ".", "LineFilterFunc", ")", "error", "{", "return", "Read", "(", "src", ",", "func", "(", "sfd", "*", "os", ".", "File", ")", "(", "err", "error", ")"...
// FilterTo filter file content with given filter, then write result // to dest file
[ "FilterTo", "filter", "file", "content", "with", "given", "filter", "then", "write", "result", "to", "dest", "file" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/file/rw.go#L64-L70
151,422
cosiner/gohper
os2/file/rw.go
Copy
func Copy(dst, src string) error { return FilterTo(dst, src, true, nil) }
go
func Copy(dst, src string) error { return FilterTo(dst, src, true, nil) }
[ "func", "Copy", "(", "dst", ",", "src", "string", ")", "error", "{", "return", "FilterTo", "(", "dst", ",", "src", ",", "true", ",", "nil", ")", "\n", "}" ]
// Copy src file to dest file
[ "Copy", "src", "file", "to", "dest", "file" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/file/rw.go#L73-L75
151,423
cosiner/gohper
os2/file/rw.go
CopyDir
func CopyDir(dst, src string) error { err := os.MkdirAll(dst, 0755) if err != nil { return err } files, err := ioutil.ReadDir(src) for i := 0; i < len(files) && err == nil; i++ { file := files[i].Name() df := filepath.Join(dst, file) sf := filepath.Join(src, file) if IsFile(sf) { err = Copy(df, sf) } else { err = CopyDir(df, sf) } } return err }
go
func CopyDir(dst, src string) error { err := os.MkdirAll(dst, 0755) if err != nil { return err } files, err := ioutil.ReadDir(src) for i := 0; i < len(files) && err == nil; i++ { file := files[i].Name() df := filepath.Join(dst, file) sf := filepath.Join(src, file) if IsFile(sf) { err = Copy(df, sf) } else { err = CopyDir(df, sf) } } return err }
[ "func", "CopyDir", "(", "dst", ",", "src", "string", ")", "error", "{", "err", ":=", "os", ".", "MkdirAll", "(", "dst", ",", "0755", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "files", ",", "err", ":=", "ioutil"...
// CopyDir copy directory from source to destination
[ "CopyDir", "copy", "directory", "from", "source", "to", "destination" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/file/rw.go#L78-L98
151,424
cosiner/gohper
os2/file/rw.go
Overwrite
func Overwrite(src string, content string) error { return Trunc(src, func(fd *os.File) error { _, err := fd.WriteString(content) return err }) }
go
func Overwrite(src string, content string) error { return Trunc(src, func(fd *os.File) error { _, err := fd.WriteString(content) return err }) }
[ "func", "Overwrite", "(", "src", "string", ",", "content", "string", ")", "error", "{", "return", "Trunc", "(", "src", ",", "func", "(", "fd", "*", "os", ".", "File", ")", "error", "{", "_", ",", "err", ":=", "fd", ".", "WriteString", "(", "content...
// Overwrite delete all content in file, and write new content to it
[ "Overwrite", "delete", "all", "content", "in", "file", "and", "write", "new", "content", "to", "it" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/file/rw.go#L101-L107
151,425
cosiner/gohper
index/index.go
BitIn
func BitIn(index int, bitset uint) uint { if index < 0 { return 0 } var idx uint = 1 << uint(index) if idx&bitset != 0 { return idx } return 0 }
go
func BitIn(index int, bitset uint) uint { if index < 0 { return 0 } var idx uint = 1 << uint(index) if idx&bitset != 0 { return idx } return 0 }
[ "func", "BitIn", "(", "index", "int", ",", "bitset", "uint", ")", "uint", "{", "if", "index", "<", "0", "{", "return", "0", "\n", "}", "\n\n", "var", "idx", "uint", "=", "1", "<<", "uint", "(", "index", ")", "\n", "if", "idx", "&", "bitset", "!...
// BitIn test whether the bit at index is set to 1, if true, return 1 << index, else 0
[ "BitIn", "test", "whether", "the", "bit", "at", "index", "is", "set", "to", "1", "if", "true", "return", "1", "<<", "index", "else", "0" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/index/index.go#L4-L15
151,426
cosiner/gohper
index/index.go
BitNotIn
func BitNotIn(index int, bitset uint) uint { if index < 0 { return 0 } var idx uint = 1 << uint(index) if idx&bitset == 0 { return idx } return 0 }
go
func BitNotIn(index int, bitset uint) uint { if index < 0 { return 0 } var idx uint = 1 << uint(index) if idx&bitset == 0 { return idx } return 0 }
[ "func", "BitNotIn", "(", "index", "int", ",", "bitset", "uint", ")", "uint", "{", "if", "index", "<", "0", "{", "return", "0", "\n", "}", "\n\n", "var", "idx", "uint", "=", "1", "<<", "uint", "(", "index", ")", "\n", "if", "idx", "&", "bitset", ...
// BitNotIn test whether the bit at index is set to 0, if true, return 1 << index, else 0
[ "BitNotIn", "test", "whether", "the", "bit", "at", "index", "is", "set", "to", "0", "if", "true", "return", "1", "<<", "index", "else", "0" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/index/index.go#L18-L29
151,427
cosiner/gohper
index/index.go
RuneIn
func RuneIn(ru rune, rs ...rune) int { for index, r := range rs { if r == ru { return index } } return -1 }
go
func RuneIn(ru rune, rs ...rune) int { for index, r := range rs { if r == ru { return index } } return -1 }
[ "func", "RuneIn", "(", "ru", "rune", ",", "rs", "...", "rune", ")", "int", "{", "for", "index", ",", "r", ":=", "range", "rs", "{", "if", "r", "==", "ru", "{", "return", "index", "\n", "}", "\n", "}", "\n\n", "return", "-", "1", "\n", "}" ]
// RuneIn return the index that rune in rune list or -1 if not exist
[ "RuneIn", "return", "the", "index", "that", "rune", "in", "rune", "list", "or", "-", "1", "if", "not", "exist" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/index/index.go#L32-L40
151,428
cosiner/gohper
index/index.go
ByteIn
func ByteIn(b byte, bs ...byte) int { for index, c := range bs { if b == c { return index } } return -1 }
go
func ByteIn(b byte, bs ...byte) int { for index, c := range bs { if b == c { return index } } return -1 }
[ "func", "ByteIn", "(", "b", "byte", ",", "bs", "...", "byte", ")", "int", "{", "for", "index", ",", "c", ":=", "range", "bs", "{", "if", "b", "==", "c", "{", "return", "index", "\n", "}", "\n", "}", "\n\n", "return", "-", "1", "\n", "}" ]
// ByteIn return the index that byte in byte list or -1 if not exist
[ "ByteIn", "return", "the", "index", "that", "byte", "in", "byte", "list", "or", "-", "1", "if", "not", "exist" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/index/index.go#L43-L51
151,429
cosiner/gohper
index/index.go
StringIn
func StringIn(str string, strs []string) int { for i, s := range strs { if s == str { return i } } return -1 }
go
func StringIn(str string, strs []string) int { for i, s := range strs { if s == str { return i } } return -1 }
[ "func", "StringIn", "(", "str", "string", ",", "strs", "[", "]", "string", ")", "int", "{", "for", "i", ",", "s", ":=", "range", "strs", "{", "if", "s", "==", "str", "{", "return", "i", "\n", "}", "\n", "}", "\n\n", "return", "-", "1", "\n", ...
// StringIn return the index of string to find in a string slice or -1 if not found
[ "StringIn", "return", "the", "index", "of", "string", "to", "find", "in", "a", "string", "slice", "or", "-", "1", "if", "not", "found" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/index/index.go#L54-L62
151,430
cosiner/gohper
index/index.go
SortedNumberIn
func SortedNumberIn(n int, nums ...int) int { for l, h := 0, len(nums)-1; l <= h; { m := l + (h-l)>>1 if c := nums[m]; c == n { return m } else if c < n { l = m + 1 } else { h = m - 1 } } return -1 }
go
func SortedNumberIn(n int, nums ...int) int { for l, h := 0, len(nums)-1; l <= h; { m := l + (h-l)>>1 if c := nums[m]; c == n { return m } else if c < n { l = m + 1 } else { h = m - 1 } } return -1 }
[ "func", "SortedNumberIn", "(", "n", "int", ",", "nums", "...", "int", ")", "int", "{", "for", "l", ",", "h", ":=", "0", ",", "len", "(", "nums", ")", "-", "1", ";", "l", "<=", "h", ";", "{", "m", ":=", "l", "+", "(", "h", "-", "l", ")", ...
// SortedNumberIn search index of number in sorted numbers with ascending order
[ "SortedNumberIn", "search", "index", "of", "number", "in", "sorted", "numbers", "with", "ascending", "order" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/index/index.go#L65-L79
151,431
cosiner/gohper
index/index.go
CharIn
func CharIn(b byte, s string) int { for l, h := 0, len(s)-1; l <= h; { m := l + (h-l)>>1 if c := s[m]; c == b { return m } else if c < b { l = m + 1 } else { h = m - 1 } } return -1 }
go
func CharIn(b byte, s string) int { for l, h := 0, len(s)-1; l <= h; { m := l + (h-l)>>1 if c := s[m]; c == b { return m } else if c < b { l = m + 1 } else { h = m - 1 } } return -1 }
[ "func", "CharIn", "(", "b", "byte", ",", "s", "string", ")", "int", "{", "for", "l", ",", "h", ":=", "0", ",", "len", "(", "s", ")", "-", "1", ";", "l", "<=", "h", ";", "{", "m", ":=", "l", "+", "(", "h", "-", "l", ")", ">>", "1", "\n...
// CharIn search index of char in sorted string with ascending order
[ "CharIn", "search", "index", "of", "char", "in", "sorted", "string", "with", "ascending", "order" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/index/index.go#L82-L96
151,432
cosiner/gohper
io2/rw.go
BufReader
func BufReader(r io.Reader) *bufio.Reader { if r, is := r.(*bufio.Reader); is { return r } return bufio.NewReader(r) }
go
func BufReader(r io.Reader) *bufio.Reader { if r, is := r.(*bufio.Reader); is { return r } return bufio.NewReader(r) }
[ "func", "BufReader", "(", "r", "io", ".", "Reader", ")", "*", "bufio", ".", "Reader", "{", "if", "r", ",", "is", ":=", "r", ".", "(", "*", "bufio", ".", "Reader", ")", ";", "is", "{", "return", "r", "\n", "}", "\n\n", "return", "bufio", ".", ...
// BufReader return a new bufio.Reader from exist io.Reader // if current reader is already bufferd, return itself
[ "BufReader", "return", "a", "new", "bufio", ".", "Reader", "from", "exist", "io", ".", "Reader", "if", "current", "reader", "is", "already", "bufferd", "return", "itself" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/io2/rw.go#L14-L20
151,433
cosiner/gohper
io2/rw.go
BufWriter
func BufWriter(w io.Writer) *bufio.Writer { if w, is := w.(*bufio.Writer); is { return w } return bufio.NewWriter(w) }
go
func BufWriter(w io.Writer) *bufio.Writer { if w, is := w.(*bufio.Writer); is { return w } return bufio.NewWriter(w) }
[ "func", "BufWriter", "(", "w", "io", ".", "Writer", ")", "*", "bufio", ".", "Writer", "{", "if", "w", ",", "is", ":=", "w", ".", "(", "*", "bufio", ".", "Writer", ")", ";", "is", "{", "return", "w", "\n", "}", "\n\n", "return", "bufio", ".", ...
// BufWriter return a new bufio.Writer from exist io.Writer // if current Writer is already bufferd, return itself
[ "BufWriter", "return", "a", "new", "bufio", ".", "Writer", "from", "exist", "io", ".", "Writer", "if", "current", "Writer", "is", "already", "bufferd", "return", "itself" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/io2/rw.go#L24-L30
151,434
cosiner/gohper
io2/rw.go
Writeln
func Writeln(w io.Writer, bs []byte) (int, error) { n, err := w.Write(bs) if err == nil { if !bytes.HasSuffix(bs, _newLine) { _, err = w.Write(_newLine) } } return n, err }
go
func Writeln(w io.Writer, bs []byte) (int, error) { n, err := w.Write(bs) if err == nil { if !bytes.HasSuffix(bs, _newLine) { _, err = w.Write(_newLine) } } return n, err }
[ "func", "Writeln", "(", "w", "io", ".", "Writer", ",", "bs", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "n", ",", "err", ":=", "w", ".", "Write", "(", "bs", ")", "\n", "if", "err", "==", "nil", "{", "if", "!", "bytes", ".", ...
// Writeln write bytes to writer and append a newline character
[ "Writeln", "write", "bytes", "to", "writer", "and", "append", "a", "newline", "character" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/io2/rw.go#L53-L62
151,435
cosiner/gohper
io2/rw.go
WriteStringln
func WriteStringln(w io.Writer, s string) (int, error) { return Writeln(w, unsafe2.Bytes(s)) }
go
func WriteStringln(w io.Writer, s string) (int, error) { return Writeln(w, unsafe2.Bytes(s)) }
[ "func", "WriteStringln", "(", "w", "io", ".", "Writer", ",", "s", "string", ")", "(", "int", ",", "error", ")", "{", "return", "Writeln", "(", "w", ",", "unsafe2", ".", "Bytes", "(", "s", ")", ")", "\n", "}" ]
// WriteStringln write string to writer and append a newline character
[ "WriteStringln", "write", "string", "to", "writer", "and", "append", "a", "newline", "character" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/io2/rw.go#L65-L67
151,436
cosiner/gohper
io2/rw.go
WriteLString
func WriteLString(w io.Writer, strs ...string) (n int, err error) { var c int for i := range strs { if c, err = w.Write(unsafe2.Bytes(strs[i])); err == nil { n += c } else { break } } return }
go
func WriteLString(w io.Writer, strs ...string) (n int, err error) { var c int for i := range strs { if c, err = w.Write(unsafe2.Bytes(strs[i])); err == nil { n += c } else { break } } return }
[ "func", "WriteLString", "(", "w", "io", ".", "Writer", ",", "strs", "...", "string", ")", "(", "n", "int", ",", "err", "error", ")", "{", "var", "c", "int", "\n", "for", "i", ":=", "range", "strs", "{", "if", "c", ",", "err", "=", "w", ".", "...
// WriteL write a string list to writer, return total bytes writed
[ "WriteL", "write", "a", "string", "list", "to", "writer", "return", "total", "bytes", "writed" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/io2/rw.go#L70-L81
151,437
cosiner/gohper
io2/rw.go
WriteL
func WriteL(w io.Writer, bs ...[]byte) (n int, err error) { var c int for i := range bs { if c, err = w.Write(bs[i]); err == nil { n += c } else { break } } return }
go
func WriteL(w io.Writer, bs ...[]byte) (n int, err error) { var c int for i := range bs { if c, err = w.Write(bs[i]); err == nil { n += c } else { break } } return }
[ "func", "WriteL", "(", "w", "io", ".", "Writer", ",", "bs", "...", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "var", "c", "int", "\n", "for", "i", ":=", "range", "bs", "{", "if", "c", ",", "err", "=", "w", ".", ...
// WriteL write a bytes list to writer, return total bytes writed
[ "WriteL", "write", "a", "bytes", "list", "to", "writer", "return", "total", "bytes", "writed" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/io2/rw.go#L84-L95
151,438
cosiner/gohper
utils/routinepool/pool.go
New
func New(processor func(Job), jobBufsize int, maxIdle, maxActive uint64) *Pool { p := &Pool{ processor: processor, jobs: make(chan Job, jobBufsize), maxIdle: maxIdle, maxActive: maxActive, } return p }
go
func New(processor func(Job), jobBufsize int, maxIdle, maxActive uint64) *Pool { p := &Pool{ processor: processor, jobs: make(chan Job, jobBufsize), maxIdle: maxIdle, maxActive: maxActive, } return p }
[ "func", "New", "(", "processor", "func", "(", "Job", ")", ",", "jobBufsize", "int", ",", "maxIdle", ",", "maxActive", "uint64", ")", "*", "Pool", "{", "p", ":=", "&", "Pool", "{", "processor", ":", "processor", ",", "jobs", ":", "make", "(", "chan", ...
// New create a pool with fix number of goroutine, if maxActive is 0, there is no // limit of goroutine number
[ "New", "create", "a", "pool", "with", "fix", "number", "of", "goroutine", "if", "maxActive", "is", "0", "there", "is", "no", "limit", "of", "goroutine", "number" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/utils/routinepool/pool.go#L26-L34
151,439
cosiner/gohper
utils/routinepool/pool.go
Info
func (p *Pool) Info() (numIdle, numActive uint64) { p.lock.RLock() numIdle = p.numIdle numActive = p.numActive p.lock.RUnlock() return }
go
func (p *Pool) Info() (numIdle, numActive uint64) { p.lock.RLock() numIdle = p.numIdle numActive = p.numActive p.lock.RUnlock() return }
[ "func", "(", "p", "*", "Pool", ")", "Info", "(", ")", "(", "numIdle", ",", "numActive", "uint64", ")", "{", "p", ".", "lock", ".", "RLock", "(", ")", "\n", "numIdle", "=", "p", ".", "numIdle", "\n", "numActive", "=", "p", ".", "numActive", "\n", ...
// Info return current infomation about idle and activing goroutine number of the pool
[ "Info", "return", "current", "infomation", "about", "idle", "and", "activing", "goroutine", "number", "of", "the", "pool" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/utils/routinepool/pool.go#L37-L43
151,440
cosiner/gohper
utils/routinepool/pool.go
Do
func (p *Pool) Do(job Job) bool { p.lock.RLock() closeCond := p.closeCond numIdle := p.numIdle numActive := p.numActive p.lock.RUnlock() if closeCond != nil { return false } if numIdle == 0 && (p.maxActive == 0 || numActive < p.maxActive) { p.lock.Lock() p.numActive++ p.numIdle++ p.lock.Unlock() go p.routine() } p.jobs <- job return true }
go
func (p *Pool) Do(job Job) bool { p.lock.RLock() closeCond := p.closeCond numIdle := p.numIdle numActive := p.numActive p.lock.RUnlock() if closeCond != nil { return false } if numIdle == 0 && (p.maxActive == 0 || numActive < p.maxActive) { p.lock.Lock() p.numActive++ p.numIdle++ p.lock.Unlock() go p.routine() } p.jobs <- job return true }
[ "func", "(", "p", "*", "Pool", ")", "Do", "(", "job", "Job", ")", "bool", "{", "p", ".", "lock", ".", "RLock", "(", ")", "\n", "closeCond", ":=", "p", ".", "closeCond", "\n", "numIdle", ":=", "p", ".", "numIdle", "\n", "numActive", ":=", "p", "...
// Do process a job. If there is no goroutine available and goroutine number already // reach the limitation, it will blocked untile a goroutine is free. Otherwise // create a new goroutine. Return false only if pool already closed
[ "Do", "process", "a", "job", ".", "If", "there", "is", "no", "goroutine", "available", "and", "goroutine", "number", "already", "reach", "the", "limitation", "it", "will", "blocked", "untile", "a", "goroutine", "is", "free", ".", "Otherwise", "create", "a", ...
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/utils/routinepool/pool.go#L48-L70
151,441
cosiner/gohper
utils/routinepool/pool.go
Close
func (p *Pool) Close() { p.lock.Lock() if p.closeCond != nil { p.lock.Unlock() return } p.closeCond = sync2.NewLockCond(nil) if len(p.jobs) != 0 { p.lock.Unlock() p.closeCond.Wait() } else { p.lock.Unlock() } close(p.jobs) }
go
func (p *Pool) Close() { p.lock.Lock() if p.closeCond != nil { p.lock.Unlock() return } p.closeCond = sync2.NewLockCond(nil) if len(p.jobs) != 0 { p.lock.Unlock() p.closeCond.Wait() } else { p.lock.Unlock() } close(p.jobs) }
[ "func", "(", "p", "*", "Pool", ")", "Close", "(", ")", "{", "p", ".", "lock", ".", "Lock", "(", ")", "\n", "if", "p", ".", "closeCond", "!=", "nil", "{", "p", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "\n", "}", "\n\n", "p", "."...
// Close stop receive new job, and waiting for all exists jobs to be processed
[ "Close", "stop", "receive", "new", "job", "and", "waiting", "for", "all", "exists", "jobs", "to", "be", "processed" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/utils/routinepool/pool.go#L108-L124
151,442
cosiner/gohper
goutil/package.go
PackagePath
func PackagePath(pkgName string) string { gopath := os.Getenv("GOPATH") if gopath == "" { return "" } fn := func(c rune) bool { sep := os.PathListSeparator return c == sep && sep != path2.UNKNOWN } for _, path := range strings.FieldsFunc(gopath, fn) { path = filepath.Join(path, "src", pkgName) if file.IsExist(path) && file.IsDir(path) { return path } } return "" }
go
func PackagePath(pkgName string) string { gopath := os.Getenv("GOPATH") if gopath == "" { return "" } fn := func(c rune) bool { sep := os.PathListSeparator return c == sep && sep != path2.UNKNOWN } for _, path := range strings.FieldsFunc(gopath, fn) { path = filepath.Join(path, "src", pkgName) if file.IsExist(path) && file.IsDir(path) { return path } } return "" }
[ "func", "PackagePath", "(", "pkgName", "string", ")", "string", "{", "gopath", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "gopath", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n\n", "fn", ":=", "func", "(", "c", "r...
// PackagePath find package absolute path use env variable GOPATH
[ "PackagePath", "find", "package", "absolute", "path", "use", "env", "variable", "GOPATH" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/goutil/package.go#L15-L35
151,443
cosiner/gohper
unibyte/byte.go
ToLowerString
func ToLowerString(b byte) string { if IsUpper(b) { b = b - 'A' + 'a' } return string(b) }
go
func ToLowerString(b byte) string { if IsUpper(b) { b = b - 'A' + 'a' } return string(b) }
[ "func", "ToLowerString", "(", "b", "byte", ")", "string", "{", "if", "IsUpper", "(", "b", ")", "{", "b", "=", "b", "-", "'A'", "+", "'a'", "\n", "}", "\n\n", "return", "string", "(", "b", ")", "\n", "}" ]
// ToLowerString convert a byte to lower case string
[ "ToLowerString", "convert", "a", "byte", "to", "lower", "case", "string" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/unibyte/byte.go#L49-L55
151,444
cosiner/gohper
unibyte/byte.go
ToUpperString
func ToUpperString(b byte) string { if IsLower(b) { b = b - 'a' + 'A' } return string(b) }
go
func ToUpperString(b byte) string { if IsLower(b) { b = b - 'a' + 'A' } return string(b) }
[ "func", "ToUpperString", "(", "b", "byte", ")", "string", "{", "if", "IsLower", "(", "b", ")", "{", "b", "=", "b", "-", "'a'", "+", "'A'", "\n", "}", "\n\n", "return", "string", "(", "b", ")", "\n", "}" ]
// ToUpperString convert a byte to upper case string
[ "ToUpperString", "convert", "a", "byte", "to", "upper", "case", "string" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/unibyte/byte.go#L58-L64
151,445
cosiner/gohper
unsafe2/conv.go
Bytes
func Bytes(s string) []byte { if !Enable { return []byte(s) } pstring := (*reflect.StringHeader)(unsafe.Pointer(&s)) return BytesFromPtr(pstring.Data, pstring.Len) }
go
func Bytes(s string) []byte { if !Enable { return []byte(s) } pstring := (*reflect.StringHeader)(unsafe.Pointer(&s)) return BytesFromPtr(pstring.Data, pstring.Len) }
[ "func", "Bytes", "(", "s", "string", ")", "[", "]", "byte", "{", "if", "!", "Enable", "{", "return", "[", "]", "byte", "(", "s", ")", "\n", "}", "\n", "pstring", ":=", "(", "*", "reflect", ".", "StringHeader", ")", "(", "unsafe", ".", "Pointer", ...
// Bytes bring a no copy convert from string to byte slice // consider the risk
[ "Bytes", "bring", "a", "no", "copy", "convert", "from", "string", "to", "byte", "slice", "consider", "the", "risk" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/unsafe2/conv.go#L28-L34
151,446
cosiner/gohper
ds/region/region.go
NewRegion
func NewRegion(from, to int) Region { dir := POSITIVE if from > to { from, to, dir = to, from, REVERSE } return Region{from, to, dir} }
go
func NewRegion(from, to int) Region { dir := POSITIVE if from > to { from, to, dir = to, from, REVERSE } return Region{from, to, dir} }
[ "func", "NewRegion", "(", "from", ",", "to", "int", ")", "Region", "{", "dir", ":=", "POSITIVE", "\n", "if", "from", ">", "to", "{", "from", ",", "to", ",", "dir", "=", "to", ",", "from", ",", "REVERSE", "\n", "}", "\n", "return", "Region", "{", ...
// New a Region
[ "New", "a", "Region" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L18-L24
151,447
cosiner/gohper
ds/region/region.go
RealFrom
func (r Region) RealFrom() int { return MinByDir(r.From, r.To, r.Dir) }
go
func (r Region) RealFrom() int { return MinByDir(r.From, r.To, r.Dir) }
[ "func", "(", "r", "Region", ")", "RealFrom", "(", ")", "int", "{", "return", "MinByDir", "(", "r", ".", "From", ",", "r", ".", "To", ",", "r", ".", "Dir", ")", "\n", "}" ]
// RealFrom return region's real from
[ "RealFrom", "return", "region", "s", "real", "from" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L32-L34
151,448
cosiner/gohper
ds/region/region.go
RealTo
func (r Region) RealTo() int { return MaxByDir(r.From, r.To, r.Dir) }
go
func (r Region) RealTo() int { return MaxByDir(r.From, r.To, r.Dir) }
[ "func", "(", "r", "Region", ")", "RealTo", "(", ")", "int", "{", "return", "MaxByDir", "(", "r", ".", "From", ",", "r", ".", "To", ",", "r", ".", "Dir", ")", "\n", "}" ]
// RealTo return real's real to
[ "RealTo", "return", "real", "s", "real", "to" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L37-L39
151,449
cosiner/gohper
ds/region/region.go
Contains
func (r Region) Contains(point int) bool { return point >= r.From && point <= r.To }
go
func (r Region) Contains(point int) bool { return point >= r.From && point <= r.To }
[ "func", "(", "r", "Region", ")", "Contains", "(", "point", "int", ")", "bool", "{", "return", "point", ">=", "r", ".", "From", "&&", "point", "<=", "r", ".", "To", "\n", "}" ]
// Contains returns whether the region contains the given point or not.
[ "Contains", "returns", "whether", "the", "region", "contains", "the", "given", "point", "or", "not", "." ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L52-L54
151,450
cosiner/gohper
ds/region/region.go
MidIn
func (r Region) MidIn(point int) bool { return point > r.From && point < r.To }
go
func (r Region) MidIn(point int) bool { return point > r.From && point < r.To }
[ "func", "(", "r", "Region", ")", "MidIn", "(", "point", "int", ")", "bool", "{", "return", "point", ">", "r", ".", "From", "&&", "point", "<", "r", ".", "To", "\n", "}" ]
// MidIn returns whether the point is in the reign and is't the begin and end
[ "MidIn", "returns", "whether", "the", "point", "is", "in", "the", "reign", "and", "is", "t", "the", "begin", "and", "end" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L57-L59
151,451
cosiner/gohper
ds/region/region.go
Cover
func (r Region) Cover(r2 Region) bool { return r.From <= r2.From && r2.To <= r.To }
go
func (r Region) Cover(r2 Region) bool { return r.From <= r2.From && r2.To <= r.To }
[ "func", "(", "r", "Region", ")", "Cover", "(", "r2", "Region", ")", "bool", "{", "return", "r", ".", "From", "<=", "r2", ".", "From", "&&", "r2", ".", "To", "<=", "r", ".", "To", "\n", "}" ]
// Cover returns whether the region fully covers the argument region
[ "Cover", "returns", "whether", "the", "region", "fully", "covers", "the", "argument", "region" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L62-L64
151,452
cosiner/gohper
ds/region/region.go
Combine
func (r Region) Combine(r2 Region) Region { return Region{Min(r.From, r2.From), Max(r.To, r2.To), r.Dir} }
go
func (r Region) Combine(r2 Region) Region { return Region{Min(r.From, r2.From), Max(r.To, r2.To), r.Dir} }
[ "func", "(", "r", "Region", ")", "Combine", "(", "r2", "Region", ")", "Region", "{", "return", "Region", "{", "Min", "(", "r", ".", "From", ",", "r2", ".", "From", ")", ",", "Max", "(", "r", ".", "To", ",", "r2", ".", "To", ")", ",", "r", "...
// Combine returns a region covering both regions, dir is same as r
[ "Combine", "returns", "a", "region", "covering", "both", "regions", "dir", "is", "same", "as", "r" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L77-L79
151,453
cosiner/gohper
ds/region/region.go
Clip
func (r Region) Clip(r2 Region) Region { var ret Region = r if r2.Cover(r) { return r } if r2.Contains(ret.From) { ret.From = r2.To } else if r2.Contains(ret.To) { ret.To = r2.From } return ret }
go
func (r Region) Clip(r2 Region) Region { var ret Region = r if r2.Cover(r) { return r } if r2.Contains(ret.From) { ret.From = r2.To } else if r2.Contains(ret.To) { ret.To = r2.From } return ret }
[ "func", "(", "r", "Region", ")", "Clip", "(", "r2", "Region", ")", "Region", "{", "var", "ret", "Region", "=", "r", "\n", "if", "r2", ".", "Cover", "(", "r", ")", "{", "return", "r", "\n", "}", "\n", "if", "r2", ".", "Contains", "(", "ret", "...
// Clip return the cliped against another region // if r is inside r2 or r2 inside r, return r, // else return r that remove intesect part
[ "Clip", "return", "the", "cliped", "against", "another", "region", "if", "r", "is", "inside", "r2", "or", "r2", "inside", "r", "return", "r", "else", "return", "r", "that", "remove", "intesect", "part" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L84-L95
151,454
cosiner/gohper
ds/region/region.go
Cut
func (r Region) Cut(r2 Region) (ret []Region) { if r.MidIn(r2.From) { ret = append(ret, Region{r.From, r2.From, r.Dir}) } if r.MidIn(r2.To) { ret = append(ret, Region{r2.To, r.To, r.Dir}) } if len(ret) == 0 && r2.Size() > 0 && !r2.Cover(r) { ret = append(ret, r) } return }
go
func (r Region) Cut(r2 Region) (ret []Region) { if r.MidIn(r2.From) { ret = append(ret, Region{r.From, r2.From, r.Dir}) } if r.MidIn(r2.To) { ret = append(ret, Region{r2.To, r.To, r.Dir}) } if len(ret) == 0 && r2.Size() > 0 && !r2.Cover(r) { ret = append(ret, r) } return }
[ "func", "(", "r", "Region", ")", "Cut", "(", "r2", "Region", ")", "(", "ret", "[", "]", "Region", ")", "{", "if", "r", ".", "MidIn", "(", "r2", ".", "From", ")", "{", "ret", "=", "append", "(", "ret", ",", "Region", "{", "r", ".", "From", "...
// Cuts remove the intersect part
[ "Cuts", "remove", "the", "intersect", "part" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L98-L109
151,455
cosiner/gohper
ds/region/region.go
Intersects
func (r Region) Intersects(r2 Region) bool { return r.Intersection(r2).Size() > 0 }
go
func (r Region) Intersects(r2 Region) bool { return r.Intersection(r2).Size() > 0 }
[ "func", "(", "r", "Region", ")", "Intersects", "(", "r2", "Region", ")", "bool", "{", "return", "r", ".", "Intersection", "(", "r2", ")", ".", "Size", "(", ")", ">", "0", "\n", "}" ]
// Intersects check whether the two regions intersects
[ "Intersects", "check", "whether", "the", "two", "regions", "intersects" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L112-L114
151,456
cosiner/gohper
ds/region/region.go
Intersection
func (r Region) Intersection(r2 Region) (ret Region) { from := Max(r.From, r2.From) to := Min(r.To, r2.To) if from < to { ret = Region{from, to, r.Dir} } return }
go
func (r Region) Intersection(r2 Region) (ret Region) { from := Max(r.From, r2.From) to := Min(r.To, r2.To) if from < to { ret = Region{from, to, r.Dir} } return }
[ "func", "(", "r", "Region", ")", "Intersection", "(", "r2", "Region", ")", "(", "ret", "Region", ")", "{", "from", ":=", "Max", "(", "r", ".", "From", ",", "r2", ".", "From", ")", "\n", "to", ":=", "Min", "(", "r", ".", "To", ",", "r2", ".", ...
// Intersection returns the region that is the intersection of the two
[ "Intersection", "returns", "the", "region", "that", "is", "the", "intersection", "of", "the", "two" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/region/region.go#L117-L124
151,457
cosiner/gohper
ds/bitset/bitset.go
unitCount
func unitCount(length uint) uint { count := length >> unitLenLogN if length&(unitLen-1) != 0 { count++ } return count }
go
func unitCount(length uint) uint { count := length >> unitLenLogN if length&(unitLen-1) != 0 { count++ } return count }
[ "func", "unitCount", "(", "length", "uint", ")", "uint", "{", "count", ":=", "length", ">>", "unitLenLogN", "\n", "if", "length", "&", "(", "unitLen", "-", "1", ")", "!=", "0", "{", "count", "++", "\n", "}", "\n\n", "return", "count", "\n", "}" ]
// unitCount return unit count need for the length
[ "unitCount", "return", "unit", "count", "need", "for", "the", "length" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L18-L25
151,458
cosiner/gohper
ds/bitset/bitset.go
NewBitset
func NewBitset(length uint, indexs ...uint) *Bitset { nonZeroLen(length) s := &Bitset{ length: length, set: newUnits(unitCount(length)), } for _, i := range indexs { s.Set(i) } return s }
go
func NewBitset(length uint, indexs ...uint) *Bitset { nonZeroLen(length) s := &Bitset{ length: length, set: newUnits(unitCount(length)), } for _, i := range indexs { s.Set(i) } return s }
[ "func", "NewBitset", "(", "length", "uint", ",", "indexs", "...", "uint", ")", "*", "Bitset", "{", "nonZeroLen", "(", "length", ")", "\n", "s", ":=", "&", "Bitset", "{", "length", ":", "length", ",", "set", ":", "newUnits", "(", "unitCount", "(", "le...
// NewBitset return a new bitset with given length, all index in list are set to 1
[ "NewBitset", "return", "a", "new", "bitset", "with", "given", "length", "all", "index", "in", "list", "are", "set", "to", "1" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L50-L62
151,459
cosiner/gohper
ds/bitset/bitset.go
SetAll
func (s *Bitset) SetAll() *Bitset { return s.unitOp(func(s *Bitset, i int) { s.set[i] = unitMax }) }
go
func (s *Bitset) SetAll() *Bitset { return s.unitOp(func(s *Bitset, i int) { s.set[i] = unitMax }) }
[ "func", "(", "s", "*", "Bitset", ")", "SetAll", "(", ")", "*", "Bitset", "{", "return", "s", ".", "unitOp", "(", "func", "(", "s", "*", "Bitset", ",", "i", "int", ")", "{", "s", ".", "set", "[", "i", "]", "=", "unitMax", "\n", "}", ")", "\n...
// SetAll set all bits to 1
[ "SetAll", "set", "all", "bits", "to", "1" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L73-L77
151,460
cosiner/gohper
ds/bitset/bitset.go
Unset
func (s *Bitset) Unset(index uint) *Bitset { s.extend(index) s.set[unitPos(index)] &= ^(1 << unitIndex(index)) return s }
go
func (s *Bitset) Unset(index uint) *Bitset { s.extend(index) s.set[unitPos(index)] &= ^(1 << unitIndex(index)) return s }
[ "func", "(", "s", "*", "Bitset", ")", "Unset", "(", "index", "uint", ")", "*", "Bitset", "{", "s", ".", "extend", "(", "index", ")", "\n", "s", ".", "set", "[", "unitPos", "(", "index", ")", "]", "&=", "^", "(", "1", "<<", "unitIndex", "(", "...
// Unset set index bit to 0, expand the bitset if index out of length range
[ "Unset", "set", "index", "bit", "to", "0", "expand", "the", "bitset", "if", "index", "out", "of", "length", "range" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L80-L85
151,461
cosiner/gohper
ds/bitset/bitset.go
UnsetAll
func (s *Bitset) UnsetAll() *Bitset { return s.unitOp(func(s *Bitset, i int) { s.set[i] = 0 }) }
go
func (s *Bitset) UnsetAll() *Bitset { return s.unitOp(func(s *Bitset, i int) { s.set[i] = 0 }) }
[ "func", "(", "s", "*", "Bitset", ")", "UnsetAll", "(", ")", "*", "Bitset", "{", "return", "s", ".", "unitOp", "(", "func", "(", "s", "*", "Bitset", ",", "i", "int", ")", "{", "s", ".", "set", "[", "i", "]", "=", "0", "\n", "}", ")", "\n", ...
// UnsetAll set all bits to 0
[ "UnsetAll", "set", "all", "bits", "to", "0" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L88-L92
151,462
cosiner/gohper
ds/bitset/bitset.go
Flip
func (s *Bitset) Flip(index uint) *Bitset { if index >= s.Length(0) { s.Set(index) } s.set[unitPos(index)] ^= 1 << unitIndex(index) return s }
go
func (s *Bitset) Flip(index uint) *Bitset { if index >= s.Length(0) { s.Set(index) } s.set[unitPos(index)] ^= 1 << unitIndex(index) return s }
[ "func", "(", "s", "*", "Bitset", ")", "Flip", "(", "index", "uint", ")", "*", "Bitset", "{", "if", "index", ">=", "s", ".", "Length", "(", "0", ")", "{", "s", ".", "Set", "(", "index", ")", "\n", "}", "\n", "s", ".", "set", "[", "unitPos", ...
// Flip the index bit, expand the bitset if index out of length range
[ "Flip", "the", "index", "bit", "expand", "the", "bitset", "if", "index", "out", "of", "length", "range" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L95-L102
151,463
cosiner/gohper
ds/bitset/bitset.go
FlipAll
func (s *Bitset) FlipAll() *Bitset { return s.unitOp(func(s *Bitset, i int) { s.set[i] = ^s.set[i] }) }
go
func (s *Bitset) FlipAll() *Bitset { return s.unitOp(func(s *Bitset, i int) { s.set[i] = ^s.set[i] }) }
[ "func", "(", "s", "*", "Bitset", ")", "FlipAll", "(", ")", "*", "Bitset", "{", "return", "s", ".", "unitOp", "(", "func", "(", "s", "*", "Bitset", ",", "i", "int", ")", "{", "s", ".", "set", "[", "i", "]", "=", "^", "s", ".", "set", "[", ...
// FlipAll flip all the index bit
[ "FlipAll", "flip", "all", "the", "index", "bit" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L105-L109
151,464
cosiner/gohper
ds/bitset/bitset.go
Except
func (s *Bitset) Except(index ...uint) *Bitset { s.SetAll() for _, i := range index { s.Unset(i) } return s }
go
func (s *Bitset) Except(index ...uint) *Bitset { s.SetAll() for _, i := range index { s.Unset(i) } return s }
[ "func", "(", "s", "*", "Bitset", ")", "Except", "(", "index", "...", "uint", ")", "*", "Bitset", "{", "s", ".", "SetAll", "(", ")", "\n", "for", "_", ",", "i", ":=", "range", "index", "{", "s", ".", "Unset", "(", "i", ")", "\n", "}", "\n\n", ...
// Except set all bits except given index to 1, the except bits set to 0
[ "Except", "set", "all", "bits", "except", "given", "index", "to", "1", "the", "except", "bits", "set", "to", "0" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L112-L119
151,465
cosiner/gohper
ds/bitset/bitset.go
IsSet
func (s *Bitset) IsSet(index uint) bool { return index < s.Length(0) && (s.set[unitPos(index)]&(1<<unitIndex(index))) != 0 }
go
func (s *Bitset) IsSet(index uint) bool { return index < s.Length(0) && (s.set[unitPos(index)]&(1<<unitIndex(index))) != 0 }
[ "func", "(", "s", "*", "Bitset", ")", "IsSet", "(", "index", "uint", ")", "bool", "{", "return", "index", "<", "s", ".", "Length", "(", "0", ")", "&&", "(", "s", ".", "set", "[", "unitPos", "(", "index", ")", "]", "&", "(", "1", "<<", "unitIn...
// IsSet check whether or not index bit is set
[ "IsSet", "check", "whether", "or", "not", "index", "bit", "is", "set" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L122-L124
151,466
cosiner/gohper
ds/bitset/bitset.go
SetTo
func (s *Bitset) SetTo(index uint, value bool) *Bitset { if value { return s.Set(index) } return s.Unset(index) }
go
func (s *Bitset) SetTo(index uint, value bool) *Bitset { if value { return s.Set(index) } return s.Unset(index) }
[ "func", "(", "s", "*", "Bitset", ")", "SetTo", "(", "index", "uint", ",", "value", "bool", ")", "*", "Bitset", "{", "if", "value", "{", "return", "s", ".", "Set", "(", "index", ")", "\n", "}", "\n\n", "return", "s", ".", "Unset", "(", "index", ...
// SetTo set index bit to 1 if value is true, otherwise 0
[ "SetTo", "set", "index", "bit", "to", "1", "if", "value", "is", "true", "otherwise", "0" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L127-L133
151,467
cosiner/gohper
ds/bitset/bitset.go
unitOp
func (s *Bitset) unitOp(f func(*Bitset, int)) *Bitset { for i, n := 0, len(s.set); i < n; i++ { f(s, i) } return s }
go
func (s *Bitset) unitOp(f func(*Bitset, int)) *Bitset { for i, n := 0, len(s.set); i < n; i++ { f(s, i) } return s }
[ "func", "(", "s", "*", "Bitset", ")", "unitOp", "(", "f", "func", "(", "*", "Bitset", ",", "int", ")", ")", "*", "Bitset", "{", "for", "i", ",", "n", ":=", "0", ",", "len", "(", "s", ".", "set", ")", ";", "i", "<", "n", ";", "i", "++", ...
// unitOp iter the bitset unit, apply function to each unit
[ "unitOp", "iter", "the", "bitset", "unit", "apply", "function", "to", "each", "unit" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L136-L142
151,468
cosiner/gohper
ds/bitset/bitset.go
Union
func (s *Bitset) Union(b *Bitset) *Bitset { return s.bitsetOp( b, func(s, b *Bitset, length *uint) { bl, l := s.Length(0), *length if bl < l { s.unsetTop() s.Length(l) } else if bl > l { b.unsetTop() } }, func(s, b *Bitset, index uint) { s.set[index] |= b.set[index] }, ) }
go
func (s *Bitset) Union(b *Bitset) *Bitset { return s.bitsetOp( b, func(s, b *Bitset, length *uint) { bl, l := s.Length(0), *length if bl < l { s.unsetTop() s.Length(l) } else if bl > l { b.unsetTop() } }, func(s, b *Bitset, index uint) { s.set[index] |= b.set[index] }, ) }
[ "func", "(", "s", "*", "Bitset", ")", "Union", "(", "b", "*", "Bitset", ")", "*", "Bitset", "{", "return", "s", ".", "bitsetOp", "(", "b", ",", "func", "(", "s", ",", "b", "*", "Bitset", ",", "length", "*", "uint", ")", "{", "bl", ",", "l", ...
// Union union another bitset to current bitset, expand the bitset if index out of length range
[ "Union", "union", "another", "bitset", "to", "current", "bitset", "expand", "the", "bitset", "if", "index", "out", "of", "length", "range" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L145-L164
151,469
cosiner/gohper
ds/bitset/bitset.go
Diff
func (s *Bitset) Diff(b *Bitset) *Bitset { return s.bitsetOp( b, func(s, b *Bitset, length *uint) { if *length > s.Length(0) { *length = s.Length(0) } else { b.unsetTop() } }, func(s, b *Bitset, index uint) { s.set[index] &= ^b.set[index] }, ) }
go
func (s *Bitset) Diff(b *Bitset) *Bitset { return s.bitsetOp( b, func(s, b *Bitset, length *uint) { if *length > s.Length(0) { *length = s.Length(0) } else { b.unsetTop() } }, func(s, b *Bitset, index uint) { s.set[index] &= ^b.set[index] }, ) }
[ "func", "(", "s", "*", "Bitset", ")", "Diff", "(", "b", "*", "Bitset", ")", "*", "Bitset", "{", "return", "s", ".", "bitsetOp", "(", "b", ",", "func", "(", "s", ",", "b", "*", "Bitset", ",", "length", "*", "uint", ")", "{", "if", "*", "length...
// Diff calculate difference between current and another bitset
[ "Diff", "calculate", "difference", "between", "current", "and", "another", "bitset" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L189-L205
151,470
cosiner/gohper
ds/bitset/bitset.go
bitsetOp
func (s *Bitset) bitsetOp(b *Bitset, lenFn func(s, b *Bitset, len *uint), opFn func(s, b *Bitset, index uint)) *Bitset { length := b.Length(0) if b == nil || b.Length(0) == 0 { return s } lenFn(s, b, &length) for i, n := Uint0, unitCount(length); i < n; i++ { opFn(s, b, i) } return s }
go
func (s *Bitset) bitsetOp(b *Bitset, lenFn func(s, b *Bitset, len *uint), opFn func(s, b *Bitset, index uint)) *Bitset { length := b.Length(0) if b == nil || b.Length(0) == 0 { return s } lenFn(s, b, &length) for i, n := Uint0, unitCount(length); i < n; i++ { opFn(s, b, i) } return s }
[ "func", "(", "s", "*", "Bitset", ")", "bitsetOp", "(", "b", "*", "Bitset", ",", "lenFn", "func", "(", "s", ",", "b", "*", "Bitset", ",", "len", "*", "uint", ")", ",", "opFn", "func", "(", "s", ",", "b", "*", "Bitset", ",", "index", "uint", ")...
// bitsetOp is common operation for union, intersection, diff
[ "bitsetOp", "is", "common", "operation", "for", "union", "intersection", "diff" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L208-L223
151,471
cosiner/gohper
ds/bitset/bitset.go
extend
func (s *Bitset) extend(index uint) { if index >= s.Length(0) { s.Length(index + 1) } }
go
func (s *Bitset) extend(index uint) { if index >= s.Length(0) { s.Length(index + 1) } }
[ "func", "(", "s", "*", "Bitset", ")", "extend", "(", "index", "uint", ")", "{", "if", "index", ">=", "s", ".", "Length", "(", "0", ")", "{", "s", ".", "Length", "(", "index", "+", "1", ")", "\n", "}", "\n", "}" ]
// extend check if it's necessery to extend bitset's data store
[ "extend", "check", "if", "it", "s", "necessery", "to", "extend", "bitset", "s", "data", "store" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L226-L230
151,472
cosiner/gohper
ds/bitset/bitset.go
unsetTop
func (s *Bitset) unsetTop() { c := unitCount(s.length) for i := s.UnitCount() - 1; i >= c; i-- { s.set[i] = 0 } s.set[c-1] &= (unitMax >> (c*unitLen - s.length)) }
go
func (s *Bitset) unsetTop() { c := unitCount(s.length) for i := s.UnitCount() - 1; i >= c; i-- { s.set[i] = 0 } s.set[c-1] &= (unitMax >> (c*unitLen - s.length)) }
[ "func", "(", "s", "*", "Bitset", ")", "unsetTop", "(", ")", "{", "c", ":=", "unitCount", "(", "s", ".", "length", ")", "\n", "for", "i", ":=", "s", ".", "UnitCount", "(", ")", "-", "1", ";", "i", ">=", "c", ";", "i", "--", "{", "s", ".", ...
// unsetTop set bitset's top non-used units to 0
[ "unsetTop", "set", "bitset", "s", "top", "non", "-", "used", "units", "to", "0" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L233-L239
151,473
cosiner/gohper
ds/bitset/bitset.go
Length
func (s *Bitset) Length(l uint) uint { if l == 0 { return s.length } new := unitCount(l) if new > uint(cap(s.set)) || new <= s.UnitCount()>>1 { newSet := newUnits(new) copy(newSet, s.set) s.set = newSet } else { s.set = s.set[:new] } s.length = l return l }
go
func (s *Bitset) Length(l uint) uint { if l == 0 { return s.length } new := unitCount(l) if new > uint(cap(s.set)) || new <= s.UnitCount()>>1 { newSet := newUnits(new) copy(newSet, s.set) s.set = newSet } else { s.set = s.set[:new] } s.length = l return l }
[ "func", "(", "s", "*", "Bitset", ")", "Length", "(", "l", "uint", ")", "uint", "{", "if", "l", "==", "0", "{", "return", "s", ".", "length", "\n", "}", "\n\n", "new", ":=", "unitCount", "(", "l", ")", "\n", "if", "new", ">", "uint", "(", "cap...
// Length change the bitset's length, if zero, only return current length. // // Only when new length is larger or half less than now, the allocation will occurred
[ "Length", "change", "the", "bitset", "s", "length", "if", "zero", "only", "return", "current", "length", ".", "Only", "when", "new", "length", "is", "larger", "or", "half", "less", "than", "now", "the", "allocation", "will", "occurred" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L253-L269
151,474
cosiner/gohper
ds/bitset/bitset.go
Clone
func (s *Bitset) Clone() *Bitset { new := NewBitset(s.Length(0)) copy(new.set, s.set) return new }
go
func (s *Bitset) Clone() *Bitset { new := NewBitset(s.Length(0)) copy(new.set, s.set) return new }
[ "func", "(", "s", "*", "Bitset", ")", "Clone", "(", ")", "*", "Bitset", "{", "new", ":=", "NewBitset", "(", "s", ".", "Length", "(", "0", ")", ")", "\n", "copy", "(", "new", ".", "set", ",", "s", ".", "set", ")", "\n\n", "return", "new", "\n"...
// Clone return a new bitset same as current
[ "Clone", "return", "a", "new", "bitset", "same", "as", "current" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L292-L297
151,475
cosiner/gohper
ds/bitset/bitset.go
Bits
func (s *Bitset) Bits() []uint { res := make([]uint, s.BitCount()) index := 0 for i, l := Uint0, s.length; i < l; i++ { if s.IsSet(i) { res[index] = i index++ } } return res }
go
func (s *Bitset) Bits() []uint { res := make([]uint, s.BitCount()) index := 0 for i, l := Uint0, s.length; i < l; i++ { if s.IsSet(i) { res[index] = i index++ } } return res }
[ "func", "(", "s", "*", "Bitset", ")", "Bits", "(", ")", "[", "]", "uint", "{", "res", ":=", "make", "(", "[", "]", "uint", ",", "s", ".", "BitCount", "(", ")", ")", "\n", "index", ":=", "0", "\n", "for", "i", ",", "l", ":=", "Uint0", ",", ...
// Bits return all index of bits set to 1
[ "Bits", "return", "all", "index", "of", "bits", "set", "to", "1" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L300-L311
151,476
cosiner/gohper
ds/bitset/bitset.go
BitCount
func (s *Bitset) BitCount() int { var n int s.unsetTop() for i, l := 0, len(s.set); i < l; i++ { n += BitCount(s.set[i]) } return n }
go
func (s *Bitset) BitCount() int { var n int s.unsetTop() for i, l := 0, len(s.set); i < l; i++ { n += BitCount(s.set[i]) } return n }
[ "func", "(", "s", "*", "Bitset", ")", "BitCount", "(", ")", "int", "{", "var", "n", "int", "\n", "s", ".", "unsetTop", "(", ")", "\n", "for", "i", ",", "l", ":=", "0", ",", "len", "(", "s", ".", "set", ")", ";", "i", "<", "l", ";", "i", ...
// BitCount return 1 bits count in bitset
[ "BitCount", "return", "1", "bits", "count", "in", "bitset" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/ds/bitset/bitset.go#L314-L322
151,477
jdextraze/go-gesclient
client/package_connection.go
isClosedConnError
func isClosedConnError(err error) bool { if err == nil { return false } // TODO: remove this string search and be more like the Windows // case below. That might involve modifying the standard library // to return better error types. str := err.Error() if strings.Contains(str, "use of closed network connection") { return true } // TODO(bradfitz): x/tools/cmd/bundle doesn't really support // build tags, so I can't make an http2_windows.go file with // Windows-specific stuff. Fix that and move this, once we // have a way to bundle this into std's net/http somehow. if runtime.GOOS == "windows" { if oe, ok := err.(*net.OpError); ok && oe.Op == "read" { if se, ok := oe.Err.(*os.SyscallError); ok && se.Syscall == "wsarecv" { const WSAECONNABORTED = 10053 const WSAECONNRESET = 10054 if n := errno(se.Err); n == WSAECONNRESET || n == WSAECONNABORTED { return true } } } } return false }
go
func isClosedConnError(err error) bool { if err == nil { return false } // TODO: remove this string search and be more like the Windows // case below. That might involve modifying the standard library // to return better error types. str := err.Error() if strings.Contains(str, "use of closed network connection") { return true } // TODO(bradfitz): x/tools/cmd/bundle doesn't really support // build tags, so I can't make an http2_windows.go file with // Windows-specific stuff. Fix that and move this, once we // have a way to bundle this into std's net/http somehow. if runtime.GOOS == "windows" { if oe, ok := err.(*net.OpError); ok && oe.Op == "read" { if se, ok := oe.Err.(*os.SyscallError); ok && se.Syscall == "wsarecv" { const WSAECONNABORTED = 10053 const WSAECONNRESET = 10054 if n := errno(se.Err); n == WSAECONNRESET || n == WSAECONNABORTED { return true } } } } return false }
[ "func", "isClosedConnError", "(", "err", "error", ")", "bool", "{", "if", "err", "==", "nil", "{", "return", "false", "\n", "}", "\n\n", "// TODO: remove this string search and be more like the Windows", "// case below. That might involve modifying the standard library", "// ...
// Copied from http2\server
[ "Copied", "from", "http2", "\\", "server" ]
c7a5150d54f99bd6537ebfc51df4cbc79149a8c7
https://github.com/jdextraze/go-gesclient/blob/c7a5150d54f99bd6537ebfc51df4cbc79149a8c7/client/package_connection.go#L215-L244
151,478
cosiner/gohper
net2/url2/query.go
QueryEscape
func QueryEscape(params map[string]string, buf *bytes.Buffer) ([]byte, bool) { s, b := Query(params, buf) if len(s) == 0 { return nil, b } return []byte(url.QueryEscape(string(s))), false // TODO: remove bytes convert }
go
func QueryEscape(params map[string]string, buf *bytes.Buffer) ([]byte, bool) { s, b := Query(params, buf) if len(s) == 0 { return nil, b } return []byte(url.QueryEscape(string(s))), false // TODO: remove bytes convert }
[ "func", "QueryEscape", "(", "params", "map", "[", "string", "]", "string", ",", "buf", "*", "bytes", ".", "Buffer", ")", "(", "[", "]", "byte", ",", "bool", ")", "{", "s", ",", "b", ":=", "Query", "(", "params", ",", "buf", ")", "\n", "if", "le...
// QueryEscape is same as Query, but escape the query string
[ "QueryEscape", "is", "same", "as", "Query", "but", "escape", "the", "query", "string" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/net2/url2/query.go#L51-L58
151,479
cosiner/gohper
strings2/string.go
TrimQuote
func TrimQuote(str string) (string, bool) { str = strings.TrimSpace(str) l := len(str) if l == 0 { return "", true } if s, e := str[0], str[l-1]; s == '\'' || s == '"' || s == '`' || e == '\'' || e == '"' || e == '`' { if l != 1 && s == e { str = str[1 : l-1] } else { return "", false } } return str, true }
go
func TrimQuote(str string) (string, bool) { str = strings.TrimSpace(str) l := len(str) if l == 0 { return "", true } if s, e := str[0], str[l-1]; s == '\'' || s == '"' || s == '`' || e == '\'' || e == '"' || e == '`' { if l != 1 && s == e { str = str[1 : l-1] } else { return "", false } } return str, true }
[ "func", "TrimQuote", "(", "str", "string", ")", "(", "string", ",", "bool", ")", "{", "str", "=", "strings", ".", "TrimSpace", "(", "str", ")", "\n", "l", ":=", "len", "(", "str", ")", "\n", "if", "l", "==", "0", "{", "return", "\"", "\"", ",",...
// TrimQuote trim quote for string, return error if quote don't match
[ "TrimQuote", "trim", "quote", "for", "string", "return", "error", "if", "quote", "don", "t", "match" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L12-L28
151,480
cosiner/gohper
strings2/string.go
SplitAndTrim
func SplitAndTrim(s, sep string) []string { sp := strings.Split(s, sep) for i, n := 0, len(sp); i < n; i++ { sp[i] = strings.TrimSpace(sp[i]) } return sp }
go
func SplitAndTrim(s, sep string) []string { sp := strings.Split(s, sep) for i, n := 0, len(sp); i < n; i++ { sp[i] = strings.TrimSpace(sp[i]) } return sp }
[ "func", "SplitAndTrim", "(", "s", ",", "sep", "string", ")", "[", "]", "string", "{", "sp", ":=", "strings", ".", "Split", "(", "s", ",", "sep", ")", "\n", "for", "i", ",", "n", ":=", "0", ",", "len", "(", "sp", ")", ";", "i", "<", "n", ";"...
// TrimSplit split string and return trim space string
[ "TrimSplit", "split", "string", "and", "return", "trim", "space", "string" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L64-L71
151,481
cosiner/gohper
strings2/string.go
TrimAfter
func TrimAfter(s, delimiter string) string { if idx := strings.Index(s, delimiter); idx >= 0 { s = s[:idx] } return strings.TrimSpace(s) }
go
func TrimAfter(s, delimiter string) string { if idx := strings.Index(s, delimiter); idx >= 0 { s = s[:idx] } return strings.TrimSpace(s) }
[ "func", "TrimAfter", "(", "s", ",", "delimiter", "string", ")", "string", "{", "if", "idx", ":=", "strings", ".", "Index", "(", "s", ",", "delimiter", ")", ";", "idx", ">=", "0", "{", "s", "=", "s", "[", ":", "idx", "]", "\n", "}", "\n\n", "ret...
// TrimAfter trim string and remove the section after delimiter and delimiter itself
[ "TrimAfter", "trim", "string", "and", "remove", "the", "section", "after", "delimiter", "and", "delimiter", "itself" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L74-L80
151,482
cosiner/gohper
strings2/string.go
IndexN
func IndexN(str, sep string, n int) (index int) { index, idx, sepLen := 0, -1, len(sep) for i := 0; i < n; i++ { if idx = strings.Index(str, sep); idx == -1 { break } str = str[idx+sepLen:] index += idx } if idx == -1 { index = -1 } else { index += (n - 1) * sepLen } return }
go
func IndexN(str, sep string, n int) (index int) { index, idx, sepLen := 0, -1, len(sep) for i := 0; i < n; i++ { if idx = strings.Index(str, sep); idx == -1 { break } str = str[idx+sepLen:] index += idx } if idx == -1 { index = -1 } else { index += (n - 1) * sepLen } return }
[ "func", "IndexN", "(", "str", ",", "sep", "string", ",", "n", "int", ")", "(", "index", "int", ")", "{", "index", ",", "idx", ",", "sepLen", ":=", "0", ",", "-", "1", ",", "len", "(", "sep", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", ...
// IndexN find index of n-th sep string
[ "IndexN", "find", "index", "of", "n", "-", "th", "sep", "string" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L91-L108
151,483
cosiner/gohper
strings2/string.go
LastIndexN
func LastIndexN(str, sep string, n int) (index int) { for i := 0; i < n; i++ { if index = strings.LastIndex(str, sep); index == -1 { break } str = str[:index] } return }
go
func LastIndexN(str, sep string, n int) (index int) { for i := 0; i < n; i++ { if index = strings.LastIndex(str, sep); index == -1 { break } str = str[:index] } return }
[ "func", "LastIndexN", "(", "str", ",", "sep", "string", ",", "n", "int", ")", "(", "index", "int", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "n", ";", "i", "++", "{", "if", "index", "=", "strings", ".", "LastIndex", "(", "str", ",", "se...
// LastIndexN find last index of n-th sep string
[ "LastIndexN", "find", "last", "index", "of", "n", "-", "th", "sep", "string" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L111-L120
151,484
cosiner/gohper
strings2/string.go
Separate
func Separate(s string, sep byte) (string, string) { i := MidIndex(s, sep) if i < 0 { return "", "" } return s[:i], s[i+1:] }
go
func Separate(s string, sep byte) (string, string) { i := MidIndex(s, sep) if i < 0 { return "", "" } return s[:i], s[i+1:] }
[ "func", "Separate", "(", "s", "string", ",", "sep", "byte", ")", "(", "string", ",", "string", ")", "{", "i", ":=", "MidIndex", "(", "s", ",", "sep", ")", "\n", "if", "i", "<", "0", "{", "return", "\"", "\"", ",", "\"", "\"", "\n", "}", "\n\n...
// Separate string by separator, the separator must in the middle of string, // not first and last
[ "Separate", "string", "by", "separator", "the", "separator", "must", "in", "the", "middle", "of", "string", "not", "first", "and", "last" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L124-L131
151,485
cosiner/gohper
strings2/string.go
IsAllCharsIn
func IsAllCharsIn(s, encoding string) bool { var is = true for i := 0; i < len(s) && is; i++ { is = index.CharIn(s[i], encoding) >= 0 } return is }
go
func IsAllCharsIn(s, encoding string) bool { var is = true for i := 0; i < len(s) && is; i++ { is = index.CharIn(s[i], encoding) >= 0 } return is }
[ "func", "IsAllCharsIn", "(", "s", ",", "encoding", "string", ")", "bool", "{", "var", "is", "=", "true", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "s", ")", "&&", "is", ";", "i", "++", "{", "is", "=", "index", ".", "CharIn", "("...
// IsAllCharsIn check whether all chars of string is in encoding string
[ "IsAllCharsIn", "check", "whether", "all", "chars", "of", "string", "is", "in", "encoding", "string" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L144-L151
151,486
cosiner/gohper
strings2/string.go
MidIndex
func MidIndex(s string, sep byte) int { i := strings.IndexByte(s, sep) if i <= 0 || i == len(s)-1 { return -1 } return i }
go
func MidIndex(s string, sep byte) int { i := strings.IndexByte(s, sep) if i <= 0 || i == len(s)-1 { return -1 } return i }
[ "func", "MidIndex", "(", "s", "string", ",", "sep", "byte", ")", "int", "{", "i", ":=", "strings", ".", "IndexByte", "(", "s", ",", "sep", ")", "\n", "if", "i", "<=", "0", "||", "i", "==", "len", "(", "s", ")", "-", "1", "{", "return", "-", ...
// MidIndex find middle separator index of string, not first and last
[ "MidIndex", "find", "middle", "separator", "index", "of", "string", "not", "first", "and", "last" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L154-L161
151,487
cosiner/gohper
strings2/string.go
RemoveSpace
func RemoveSpace(s string) string { idx, end := 0, len(s) bs := make([]byte, end) for i := 0; i < end; i++ { if !unibyte.IsSpace(s[i]) { bs[idx] = s[i] idx++ } } return string(bs[:idx]) }
go
func RemoveSpace(s string) string { idx, end := 0, len(s) bs := make([]byte, end) for i := 0; i < end; i++ { if !unibyte.IsSpace(s[i]) { bs[idx] = s[i] idx++ } } return string(bs[:idx]) }
[ "func", "RemoveSpace", "(", "s", "string", ")", "string", "{", "idx", ",", "end", ":=", "0", ",", "len", "(", "s", ")", "\n", "bs", ":=", "make", "(", "[", "]", "byte", ",", "end", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "end", ";"...
// RemoveSpace remove all space characters from string by unibyte.IsSpace
[ "RemoveSpace", "remove", "all", "space", "characters", "from", "string", "by", "unibyte", ".", "IsSpace" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L164-L175
151,488
cosiner/gohper
strings2/string.go
MergeSpace
func MergeSpace(s string, trim bool) string { space := false idx, end := 0, len(s) bs := make([]byte, end) for i := 0; i < end; i++ { if unibyte.IsSpace(s[i]) { space = true } else { if space && (!trim || idx != 0) { bs[idx] = ' ' idx++ } bs[idx] = s[i] idx++ space = false } } if space && !trim { bs[idx] = ' ' idx++ } return string(bs[:idx]) }
go
func MergeSpace(s string, trim bool) string { space := false idx, end := 0, len(s) bs := make([]byte, end) for i := 0; i < end; i++ { if unibyte.IsSpace(s[i]) { space = true } else { if space && (!trim || idx != 0) { bs[idx] = ' ' idx++ } bs[idx] = s[i] idx++ space = false } } if space && !trim { bs[idx] = ' ' idx++ } return string(bs[:idx]) }
[ "func", "MergeSpace", "(", "s", "string", ",", "trim", "bool", ")", "string", "{", "space", ":=", "false", "\n\n", "idx", ",", "end", ":=", "0", ",", "len", "(", "s", ")", "\n", "bs", ":=", "make", "(", "[", "]", "byte", ",", "end", ")", "\n", ...
// MergeSpace merge multiple space to one, trim determine whether remove space at prefix and suffix
[ "MergeSpace", "merge", "multiple", "space", "to", "one", "trim", "determine", "whether", "remove", "space", "at", "prefix", "and", "suffix" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L178-L205
151,489
cosiner/gohper
strings2/string.go
IndexNonSpace
func IndexNonSpace(s string) int { for i := range s { if !unibyte.IsSpace(s[i]) { return i } } return -1 }
go
func IndexNonSpace(s string) int { for i := range s { if !unibyte.IsSpace(s[i]) { return i } } return -1 }
[ "func", "IndexNonSpace", "(", "s", "string", ")", "int", "{", "for", "i", ":=", "range", "s", "{", "if", "!", "unibyte", ".", "IsSpace", "(", "s", "[", "i", "]", ")", "{", "return", "i", "\n", "}", "\n", "}", "\n\n", "return", "-", "1", "\n", ...
// IndexNonSpace find index of first non-space character, if not exist, -1 was returned
[ "IndexNonSpace", "find", "index", "of", "first", "non", "-", "space", "character", "if", "not", "exist", "-", "1", "was", "returned" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L208-L216
151,490
cosiner/gohper
strings2/string.go
LastIndexNonSpace
func LastIndexNonSpace(s string) int { for i := len(s) - 1; i >= 0; i-- { if !unibyte.IsSpace(s[i]) { return i } } return -1 }
go
func LastIndexNonSpace(s string) int { for i := len(s) - 1; i >= 0; i-- { if !unibyte.IsSpace(s[i]) { return i } } return -1 }
[ "func", "LastIndexNonSpace", "(", "s", "string", ")", "int", "{", "for", "i", ":=", "len", "(", "s", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "if", "!", "unibyte", ".", "IsSpace", "(", "s", "[", "i", "]", ")", "{", "return", ...
// LastIndexNonSpace find index of last non-space character, if not exist, -1 was returned
[ "LastIndexNonSpace", "find", "index", "of", "last", "non", "-", "space", "character", "if", "not", "exist", "-", "1", "was", "returned" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L219-L227
151,491
cosiner/gohper
strings2/string.go
WriteStringsToBuffer
func WriteStringsToBuffer(buffer *bytes.Buffer, strings []string, sep string) { i, last := 0, len(strings)-1 for ; i < last; i++ { buffer.WriteString(strings[i]) buffer.WriteString(sep) } if last != -1 { buffer.WriteString(strings[last]) } }
go
func WriteStringsToBuffer(buffer *bytes.Buffer, strings []string, sep string) { i, last := 0, len(strings)-1 for ; i < last; i++ { buffer.WriteString(strings[i]) buffer.WriteString(sep) } if last != -1 { buffer.WriteString(strings[last]) } }
[ "func", "WriteStringsToBuffer", "(", "buffer", "*", "bytes", ".", "Buffer", ",", "strings", "[", "]", "string", ",", "sep", "string", ")", "{", "i", ",", "last", ":=", "0", ",", "len", "(", "strings", ")", "-", "1", "\n", "for", ";", "i", "<", "l...
// WriteStringsToBuffer write strings to buffer, it avoid memory allocation of join // strings
[ "WriteStringsToBuffer", "write", "strings", "to", "buffer", "it", "avoid", "memory", "allocation", "of", "join", "strings" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/strings2/string.go#L231-L241
151,492
cosiner/gohper
os2/args/args.go
Int
func Int(args []string, index int, def int) (int, error) { if len(args) <= index { return def, nil } return strconv.Atoi(args[index]) }
go
func Int(args []string, index int, def int) (int, error) { if len(args) <= index { return def, nil } return strconv.Atoi(args[index]) }
[ "func", "Int", "(", "args", "[", "]", "string", ",", "index", "int", ",", "def", "int", ")", "(", "int", ",", "error", ")", "{", "if", "len", "(", "args", ")", "<=", "index", "{", "return", "def", ",", "nil", "\n", "}", "\n\n", "return", "strco...
// Int get arguments at given index, if not exists, use default value, // otherwise, convert it to inteeger
[ "Int", "get", "arguments", "at", "given", "index", "if", "not", "exists", "use", "default", "value", "otherwise", "convert", "it", "to", "inteeger" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/args/args.go#L7-L13
151,493
cosiner/gohper
os2/args/args.go
String
func String(args []string, index int, def string) string { if len(args) <= index { return def } return args[index] }
go
func String(args []string, index int, def string) string { if len(args) <= index { return def } return args[index] }
[ "func", "String", "(", "args", "[", "]", "string", ",", "index", "int", ",", "def", "string", ")", "string", "{", "if", "len", "(", "args", ")", "<=", "index", "{", "return", "def", "\n", "}", "\n\n", "return", "args", "[", "index", "]", "\n", "}...
// String get argument at given index, if not exists, use default value
[ "String", "get", "argument", "at", "given", "index", "if", "not", "exists", "use", "default", "value" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/os2/args/args.go#L16-L22
151,494
cosiner/gohper
goutil/field.go
ToSameExported
func ToSameExported(example, str string) string { if IsExported(example) { return ToExported(str) } return ToUnexported(str) }
go
func ToSameExported(example, str string) string { if IsExported(example) { return ToExported(str) } return ToUnexported(str) }
[ "func", "ToSameExported", "(", "example", ",", "str", "string", ")", "string", "{", "if", "IsExported", "(", "example", ")", "{", "return", "ToExported", "(", "str", ")", "\n", "}", "\n\n", "return", "ToUnexported", "(", "str", ")", "\n", "}" ]
// ToSameExported return the same exported case with example string of a string
[ "ToSameExported", "return", "the", "same", "exported", "case", "with", "example", "string", "of", "a", "string" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/goutil/field.go#L16-L22
151,495
cosiner/gohper
conv/convert.go
Hex2Uint
func Hex2Uint(str string) (uint64, error) { if len(str) > 2 { if head := str[:2]; head == "0x" || head == "0X" { str = str[2:] } } var n uint64 for _, c := range str { if c >= '0' && c <= '9' { c = c - '0' } else if c >= 'a' && c <= 'f' { c = c - 'a' + 10 } else if c >= 'A' && c <= 'F' { c = c - 'A' + 10 } else { return 0, errors.Newf("Invalid hexadecimal string %s", str) } n = n << 4 n |= uint64(c) } return n, nil }
go
func Hex2Uint(str string) (uint64, error) { if len(str) > 2 { if head := str[:2]; head == "0x" || head == "0X" { str = str[2:] } } var n uint64 for _, c := range str { if c >= '0' && c <= '9' { c = c - '0' } else if c >= 'a' && c <= 'f' { c = c - 'a' + 10 } else if c >= 'A' && c <= 'F' { c = c - 'A' + 10 } else { return 0, errors.Newf("Invalid hexadecimal string %s", str) } n = n << 4 n |= uint64(c) } return n, nil }
[ "func", "Hex2Uint", "(", "str", "string", ")", "(", "uint64", ",", "error", ")", "{", "if", "len", "(", "str", ")", ">", "2", "{", "if", "head", ":=", "str", "[", ":", "2", "]", ";", "head", "==", "\"", "\"", "||", "head", "==", "\"", "\"", ...
// Hex2Uint convert a hexadecimal string to uint // if string is invalid, return an error
[ "Hex2Uint", "convert", "a", "hexadecimal", "string", "to", "uint", "if", "string", "is", "invalid", "return", "an", "error" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/conv/convert.go#L42-L65
151,496
cosiner/gohper
conv/convert.go
Bytes2Hex
func Bytes2Hex(src []byte) []byte { dst := make([]byte, 2*len(src)) hex.Encode(dst, src) return dst }
go
func Bytes2Hex(src []byte) []byte { dst := make([]byte, 2*len(src)) hex.Encode(dst, src) return dst }
[ "func", "Bytes2Hex", "(", "src", "[", "]", "byte", ")", "[", "]", "byte", "{", "dst", ":=", "make", "(", "[", "]", "byte", ",", "2", "*", "len", "(", "src", ")", ")", "\n", "hex", ".", "Encode", "(", "dst", ",", "src", ")", "\n\n", "return", ...
// BytesToHex transfer binary to hex bytes
[ "BytesToHex", "transfer", "binary", "to", "hex", "bytes" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/conv/convert.go#L68-L73
151,497
cosiner/gohper
conv/convert.go
Hex2Bytes
func Hex2Bytes(src []byte) []byte { dst := make([]byte, len(src)/2) hex.Decode(dst, src) return dst }
go
func Hex2Bytes(src []byte) []byte { dst := make([]byte, len(src)/2) hex.Decode(dst, src) return dst }
[ "func", "Hex2Bytes", "(", "src", "[", "]", "byte", ")", "[", "]", "byte", "{", "dst", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "src", ")", "/", "2", ")", "\n", "hex", ".", "Decode", "(", "dst", ",", "src", ")", "\n\n", "return", ...
// HexToBytes transfer hex bytes to binary
[ "HexToBytes", "transfer", "hex", "bytes", "to", "binary" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/conv/convert.go#L76-L81
151,498
cosiner/gohper
conv/convert.go
ReverseBits
func ReverseBits(num uint) uint { var n uint size := uint(unsafe.Sizeof(num)) for s := size * 8; s > 0; s-- { n = n << 1 n |= (num & 1) num = num >> 1 } return n }
go
func ReverseBits(num uint) uint { var n uint size := uint(unsafe.Sizeof(num)) for s := size * 8; s > 0; s-- { n = n << 1 n |= (num & 1) num = num >> 1 } return n }
[ "func", "ReverseBits", "(", "num", "uint", ")", "uint", "{", "var", "n", "uint", "\n", "size", ":=", "uint", "(", "unsafe", ".", "Sizeof", "(", "num", ")", ")", "\n", "for", "s", ":=", "size", "*", "8", ";", "s", ">", "0", ";", "s", "--", "{"...
// ReverseBits reverse all bits in number
[ "ReverseBits", "reverse", "all", "bits", "in", "number" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/conv/convert.go#L84-L94
151,499
cosiner/gohper
conv/convert.go
ReverseByte
func ReverseByte(num byte) byte { var n byte for s := 8; s > 0; s-- { n = n << 1 n |= (num & 1) num = num >> 1 } return n }
go
func ReverseByte(num byte) byte { var n byte for s := 8; s > 0; s-- { n = n << 1 n |= (num & 1) num = num >> 1 } return n }
[ "func", "ReverseByte", "(", "num", "byte", ")", "byte", "{", "var", "n", "byte", "\n", "for", "s", ":=", "8", ";", "s", ">", "0", ";", "s", "--", "{", "n", "=", "n", "<<", "1", "\n", "n", "|=", "(", "num", "&", "1", ")", "\n", "num", "=",...
// ReverseByte reverse all bits for a byte
[ "ReverseByte", "reverse", "all", "bits", "for", "a", "byte" ]
700f92d01d8a55070e4db9cf57bc3d346d65c9e8
https://github.com/cosiner/gohper/blob/700f92d01d8a55070e4db9cf57bc3d346d65c9e8/conv/convert.go#L97-L106