MCPcopy Create free account
hub / github.com/coregx/coregex / stringToBytes

Function stringToBytes

regex.go:63–69  ·  view source on GitHub ↗

stringToBytes converts string to []byte without allocation. This is the Go equivalent of Rust's str.as_bytes() - a zero-cost reinterpret cast. The returned slice MUST NOT be modified (same as Rust's immutable &[u8]). go:inline

(s string)

Source from the content-addressed store, hash-verified

61//
62//go:inline
63func stringToBytes(s string) []byte {
64 if s == "" {
65 return nil
66 }
67 // G103: Safe - read-only view of immutable string data (like Rust's as_bytes)
68 return unsafe.Slice(unsafe.StringData(s), len(s)) //nolint:gosec
69}
70
71// Regex represents a compiled regular expression.
72//

Callers 14

MatchStringMethod · 0.85
FindStringMethod · 0.85
FindStringIndexMethod · 0.85
FindAllStringMethod · 0.85
FindStringSubmatchMethod · 0.85
AppendAllStringIndexMethod · 0.85
FindAllStringIndexMethod · 0.85
ReplaceAllStringFuncMethod · 0.85
CountStringMethod · 0.85
FindAllStringSubmatchMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected