summaryrefslogtreecommitdiff
path: root/pkgtools/pkglint/files/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkgtools/pkglint/files/util.go')
-rw-r--r--pkgtools/pkglint/files/util.go34
1 files changed, 27 insertions, 7 deletions
diff --git a/pkgtools/pkglint/files/util.go b/pkgtools/pkglint/files/util.go
index 39ae8dcc902..61b586bf202 100644
--- a/pkgtools/pkglint/files/util.go
+++ b/pkgtools/pkglint/files/util.go
@@ -88,6 +88,22 @@ func mapStr(slice []string, fn func(s string) string) []string {
return result
}
+func invalidCharacters(s string, valid *textproc.ByteSet) string {
+ var unis strings.Builder
+
+ for _, r := range s {
+ if r == rune(byte(r)) && valid.Contains(byte(r)) {
+ continue
+ }
+ _, _ = fmt.Fprintf(&unis, " %U", r)
+ }
+
+ if unis.Len() == 0 {
+ return ""
+ }
+ return unis.String()[1:]
+}
+
// intern returns an independent copy of the given string.
//
// It should be called when only a small substring of a large string
@@ -367,13 +383,19 @@ func detab(s string) string {
return detabbed.String()
}
-// alignWith extends str with as many tabs as needed to reach
+// alignWith extends str with as many tabs and spaces as needed to reach
// the same screen width as the other string.
func alignWith(str, other string) string {
- alignBefore := (tabWidth(other) + 7) & -8
- alignAfter := tabWidth(str) & -8
- tabsNeeded := imax((alignBefore-alignAfter)/8, 1)
- return str + strings.Repeat("\t", tabsNeeded)
+ strWidth := tabWidth(str)
+ otherWidth := tabWidth(other)
+ if otherWidth <= strWidth {
+ return str + "\t"
+ }
+ if strWidth&-8 != otherWidth&-8 {
+ strWidth &= -8
+ }
+ alignment := indent(otherWidth - strWidth)
+ return str + alignment
}
func indent(width int) string {
@@ -462,8 +484,6 @@ func containsVarRef(s string) bool {
return false
}
-func hasAlnumPrefix(s string) bool { return s != "" && textproc.AlnumU.Contains(s[0]) }
-
// Once remembers with which arguments its FirstTime method has been called
// and only returns true on each first call.
type Once struct {