}
// StringWidth returns the width of a string where tabs count as `tabsize` width
-func StringWidth(str string) int {
+func StringWidth(str string, tabsize int) int {
sw := runewidth.StringWidth(str)
- sw += NumOccurences(str, '\t') * (int(settings["tabsize"].(float64)) - 1)
+ sw += NumOccurences(str, '\t') * (tabsize - 1)
return sw
}
// WidthOfLargeRunes searches all the runes in a string and counts up all the widths of runes
// that have a width larger than 1 (this also counts tabs as `tabsize` width)
-func WidthOfLargeRunes(str string) int {
+func WidthOfLargeRunes(str string, tabsize int) int {
count := 0
for _, ch := range str {
var w int
if ch == '\t' {
- w = int(settings["tabsize"].(float64))
+ w = tabsize
} else {
w = runewidth.RuneWidth(ch)
}
return utf8.RuneCountInString(str[:p])
}
+func lcs(a, b string) string {
+ arunes := []rune(a)
+ brunes := []rune(b)
+
+ lcs := ""
+ for i, r := range arunes {
+ if i >= len(brunes) {
+ break
+ }
+ if r == brunes[i] {
+ lcs += string(r)
+ } else {
+ break
+ }
+ }
+ return lcs
+}
+
+func CommonSubstring(arr ...string) string {
+ commonStr := arr[0]
+
+ for _, str := range arr[1:] {
+ commonStr = lcs(commonStr, str)
+ }
+
+ return commonStr
+}
+
// Abs is a simple absolute value function for ints
func Abs(n int) int {
if n < 0 {