gitlab.com/evatix-go/core@v1.3.55/coredata/corerange/StartEndString.go (about) 1 package corerange 2 3 import ( 4 "strings" 5 6 "gitlab.com/evatix-go/core/constants" 7 "gitlab.com/evatix-go/core/coreindexes" 8 ) 9 10 type StartEndString struct { 11 *BaseRange 12 Start, End string 13 } 14 15 func NewStartEndString(raw, sep string) *StartEndString { 16 ranges := strings.Split(raw, sep) 17 length := len(ranges) 18 hasStart := length >= 1 19 hasEnd := length >= 2 20 isValid := false 21 isValid = isValid && 22 length == 2 && 23 hasStart && 24 hasEnd 25 26 var start, end string 27 28 if hasStart { 29 start = ranges[coreindexes.First] 30 } 31 32 if hasEnd { 33 end = ranges[coreindexes.Second] 34 } 35 36 return &StartEndString{ 37 BaseRange: &BaseRange{ 38 RawInput: raw, 39 Separator: sep, 40 IsValid: isValid, 41 HasStart: hasStart, 42 HasEnd: hasEnd, 43 }, 44 Start: start, 45 End: end, 46 } 47 } 48 49 // NewStartEndStringUsingLines using first, last index 50 func NewStartEndStringUsingLines(lines []string) *StartEndString { 51 length := len(lines) 52 hasStart := length >= 1 53 hasEnd := length >= 2 54 isValid := false 55 isValid = isValid && 56 length == 2 && 57 hasStart && 58 hasEnd 59 60 var start, end string 61 62 if hasStart { 63 start = lines[coreindexes.First] 64 } 65 66 if hasEnd { 67 end = lines[length-1] 68 } 69 70 return &StartEndString{ 71 BaseRange: &BaseRange{ 72 RawInput: constants.EmptyString, 73 Separator: constants.EmptyString, 74 IsValid: isValid, 75 HasStart: hasStart, 76 HasEnd: hasEnd, 77 }, 78 Start: start, 79 End: end, 80 } 81 } 82 83 func (r *StartEndString) CreateRangeString() *RangeString { 84 return &RangeString{ 85 StartEndString: NewStartEndString( 86 r.RawInput, 87 r.Separator), 88 } 89 } 90 91 func (r *StartEndString) String() string { 92 return r.BaseRange.String(r.Start, r.End) 93 }