gitlab.com/evatix-go/core@v1.3.55/coredata/corestr/newCollectionPtrCreator.go (about) 1 package corestr 2 3 import ( 4 "strings" 5 6 "gitlab.com/evatix-go/core/constants" 7 "gitlab.com/evatix-go/core/converters" 8 ) 9 10 type newCollectionPtrCreator struct{} 11 12 func (it *newCollectionPtrCreator) Empty() *CollectionPtr { 13 return &CollectionPtr{ 14 items: []*string{}, 15 } 16 } 17 18 func (it *newCollectionPtrCreator) Cap(capacity int) *CollectionPtr { 19 collection := make([]*string, constants.Zero, capacity) 20 21 return &CollectionPtr{ 22 items: collection, 23 } 24 } 25 26 func (it *newCollectionPtrCreator) StringsOptions( 27 capacity int, 28 stringItems []string, 29 ) *CollectionPtr { 30 length := len(stringItems) 31 slice := make([]*string, 0, length+capacity) 32 33 collection := &CollectionPtr{ 34 items: slice, 35 } 36 37 return collection.AddStringsPtr(&stringItems) 38 } 39 40 func (it *newCollectionPtrCreator) Strings( 41 stringItems []string, 42 ) *CollectionPtr { 43 return &CollectionPtr{ 44 items: *converters.StringsTo.PointerStrings(&stringItems), 45 } 46 } 47 48 func (it *newCollectionPtrCreator) Default( 49 stringItems []*string, 50 ) *CollectionPtr { 51 return &CollectionPtr{ 52 items: stringItems, 53 } 54 } 55 56 func (it *newCollectionPtrCreator) StringsPtr( 57 stringItems *[]string, 58 ) *CollectionPtr { 59 if stringItems == nil { 60 return it.Empty() 61 } 62 63 collection := &CollectionPtr{ 64 items: *converters.StringsTo.PointerStrings(stringItems), 65 } 66 67 return collection.AddStringsPtr(stringItems) 68 } 69 70 func (it *newCollectionPtrCreator) LineUsingSep(sep, line string) *CollectionPtr { 71 lines := strings.Split(line, sep) 72 73 return &CollectionPtr{ 74 items: *converters.StringsTo.PointerStrings(&lines), 75 } 76 } 77 78 func (it *newCollectionPtrCreator) LineDefault(compiledLine string) *CollectionPtr { 79 lines := strings.Split( 80 compiledLine, 81 constants.DefaultLine) 82 83 return &CollectionPtr{ 84 items: *converters.StringsTo.PointerStrings(&lines), 85 } 86 } 87 88 func (it *newCollectionPtrCreator) StringsPlusCap( 89 additionalCapacity int, 90 stringItems []string, 91 ) *CollectionPtr { 92 if additionalCapacity == 0 { 93 return it.Strings(stringItems) 94 } 95 96 length := len(stringItems) 97 collection := it.Cap(length + additionalCapacity) 98 99 return collection.Adds(stringItems...) 100 } 101 102 func (it *newCollectionPtrCreator) StringsPtrPlusCap( 103 additionalCap int, 104 stringItems *[]string, 105 ) *CollectionPtr { 106 if additionalCap == 0 { 107 return it.StringsPtr( 108 stringItems) 109 } 110 111 length := LengthOfStringsPtr(stringItems) 112 collection := it.Cap(length + additionalCap) 113 114 return collection.AddStringsPtr(stringItems) 115 } 116 117 func (it *newCollectionPtrCreator) PointerStrings( 118 stringItems []*string, 119 ) *CollectionPtr { 120 length := len(stringItems) 121 collection := it.Cap(length) 122 123 return collection.AddPointerStrings(stringItems...) 124 } 125 126 func (it *newCollectionPtrCreator) PointerStringsPtrUsingCap( 127 capacity int, 128 stringItems *[]*string, 129 ) *CollectionPtr { 130 length := LengthOfPointerStrings(stringItems) 131 collection := it.Cap(length + capacity) 132 133 return collection.AddPointerStrings(*stringItems...) 134 } 135 136 func (it *newCollectionPtrCreator) LenCap(length, capacity int) *CollectionPtr { 137 collection := make([]*string, length, capacity) 138 139 return &CollectionPtr{ 140 items: collection, 141 } 142 }