gitlab.com/evatix-go/core@v1.3.55/coreutils/stringutil/IsEndsWith.go (about) 1 package stringutil 2 3 import "strings" 4 5 func IsEndsWith( 6 baseStr, 7 endsWith string, 8 isIgnoreCase bool, 9 ) bool { 10 if endsWith == "" { 11 return true 12 } 13 14 if baseStr == "" { 15 return endsWith == "" 16 } 17 18 if baseStr == endsWith { 19 return true 20 } 21 22 basePathLength := len(baseStr) 23 endsWithLength := len(endsWith) 24 25 if endsWithLength > basePathLength { 26 return false 27 } 28 29 if isIgnoreCase && 30 basePathLength == endsWithLength && 31 strings.EqualFold(baseStr, endsWith) { 32 return true 33 } 34 35 remainingLength := basePathLength - endsWithLength 36 37 if remainingLength < 0 { 38 return false 39 } 40 41 remainingText := baseStr[remainingLength:] 42 43 if !isIgnoreCase { 44 return endsWith == remainingText 45 } 46 47 return strings.EqualFold(endsWith, remainingText) 48 }