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