Documentation
¶
Overview ¶
Package replace provides text replacement utilities
Index ¶
- func ProcessFile(target string, fn func(original string) (modified string, count int)) (original, modified string, count int, delta *diff.Diff, err error)
- func ProfileCase(input string) (lower, upper, space, kebab, underscore bool)
- func Regex(search *regexp.Regexp, replace, contents string) (modified string, count int)
- func RegexFile(search *regexp.Regexp, replace, target string) (original, modified string, count int, delta *diff.Diff, err error)
- func RegexPreserve(search *regexp.Regexp, replace, contents string) (modified string, count int)
- func RegexPreserveFile(search *regexp.Regexp, replace, target string) (original, modified string, count int, delta *diff.Diff, err error)
- func String(search, replace, contents string) (modified string, count int)
- func StringFile(search, replace, target string) (original, modified string, count int, delta *diff.Diff, err error)
- func StringInsensitive(search, replace, contents string) (modified string, count int)
- func StringInsensitiveFile(search, replace, target string) (original, modified string, count int, delta *diff.Diff, err error)
- func StringPreserve(search, replace, contents string) (modified string, count int)
- func StringPreserveFile(search, replace, target string) (original, modified string, count int, delta *diff.Diff, err error)
- type Case
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProcessFile ¶
func ProcessFile(target string, fn func(original string) (modified string, count int)) (original, modified string, count int, delta *diff.Diff, err error)
ProcessFile is a convenience function which calls os.ReadFile on the target and runs the given `fn` with the string contents and creates a Diff of the changes between the original and the modified output
func ProfileCase ¶
ProfileCase scans through each rune in the given input and checks for a number of interesting hints about the string case of the input
func Regex ¶
Regex counts the number of matches and runs ReplaceAllString on the given contents, if there are no matches, `modified` will be the same as `contents`
func RegexFile ¶
func RegexFile(search *regexp.Regexp, replace, target string) (original, modified string, count int, delta *diff.Diff, err error)
RegexFile uses Regex to ProcessFile
func RegexPreserve ¶
func RegexPreserveFile ¶
func RegexPreserveFile(search *regexp.Regexp, replace, target string) (original, modified string, count int, delta *diff.Diff, err error)
RegexPreserveFile uses StringPreserve to ProcessFile
func String ¶
String counts the number of matches and runs strings.ReplaceAll on the given contents, if there are no matches, `modified` will be the same as `contents`
func StringFile ¶
func StringFile(search, replace, target string) (original, modified string, count int, delta *diff.Diff, err error)
StringFile uses String to ProcessFile
func StringInsensitive ¶
StringInsensitive counts the number of case-insensitive matches and replaces each instance with the `replace` value, if there are no matches `modified` will be the same as `contents`
func StringInsensitiveFile ¶
func StringInsensitiveFile(search, replace, target string) (original, modified string, count int, delta *diff.Diff, err error)
StringInsensitiveFile uses StringInsensitive to ProcessFile
func StringPreserve ¶
StringPreserve is like StringInsensitive except that StringPreserve attempts to preserve the per-instance case when doing replacements. If `search` or `replace` have any spaces, StringPreserve is wraps String.
To preserve the per-instance cases, each instance has DetectCase run and uses Case.Apply to derive the `replace` value actually used
See the Case constants for the list of string cases supported
Types ¶
type Case ¶
type Case uint8
Case is a simple type for indicating a detected string case
func DetectCase ¶
DetectCase uses ProfileCase and some extra efforts to reliably discern the obvious string case of the given input