| 1 | package catscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/ |
| 2 | |
| 3 | import ( |
| 4 | "reflectscip-go gomod github.com/golang/go/src go1.21 reflect/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.21 strings/" |
| 6 | ) |
| 7 | |
| 8 | // Append appends args to dst and returns the grown slice. |
| 9 | // Callers can reuse dst across calls to amortize allocs. |
| 10 | // It uses an internal Builder for efficient concatenation of the args (no separators), |
| 11 | // then appends the result to the dst byte slice. |
| 12 | // Preallocates based on a size estimate to minimize reallocations. |
| 13 | // Benefits from Builder pooling if enabled. |
| 14 | // Useful for building byte slices incrementally without separators. |
| 15 | func Appendscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Append().(dst []byte, args ...any) []byte { |
| 16 | return AppendWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/AppendWith().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., dst, args...) |
| 17 | } |
| 18 | |
| 19 | // AppendWith appends args to dst and returns the grown slice. |
| 20 | // Callers can reuse dst across calls to amortize allocs. |
| 21 | // Similar to Append, but inserts the specified sep between each arg. |
| 22 | // Preallocates based on a size estimate including separators. |
| 23 | // Benefits from Builder pooling if enabled. |
| 24 | // Useful for building byte slices incrementally with custom separators. |
| 25 | func AppendWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/AppendWith().(sep string, dst []byte, args ...any) []byte { |
| 26 | if len(args) == 0 { |
| 27 | return dst |
| 28 | } |
| 29 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(sep) |
| 30 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(estimateWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimateWith().(sep, args)) |
| 31 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(args...) |
| 32 | out := b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 33 | return append(dst, out...) |
| 34 | } |
| 35 | |
| 36 | // AppendBytes joins byte slices without separators. |
| 37 | // Only for compatibility with low-level byte processing. |
| 38 | // Directly appends each []byte arg to dst without any conversion or separators. |
| 39 | // Efficient for pure byte concatenation; no allocations if dst has capacity. |
| 40 | // Returns the extended dst slice. |
| 41 | // Does not use Builder, as it's simple append operations. |
| 42 | func AppendBytesscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/AppendBytes().(dst []byte, args ...[]byte) []byte { |
| 43 | if len(args) == 0 { |
| 44 | return dst |
| 45 | } |
| 46 | for _, b := range args { |
| 47 | dst = append(dst, b...) |
| 48 | } |
| 49 | return dst |
| 50 | } |
| 51 | |
| 52 | // AppendTo writes arguments to an existing strings.Builder. |
| 53 | // More efficient than creating new builders. |
| 54 | // Appends each arg to the provided strings.Builder using the optimized write function. |
| 55 | // No separators are added; for direct concatenation. |
| 56 | // Useful when you already have a strings.Builder and want to add more values efficiently. |
| 57 | // Does not use cat.Builder, as it appends to an existing strings.Builder. |
| 58 | func AppendToscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/AppendTo().(b *stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Builderscip-go gomod github.com/golang/go/src go1.21 strings/Builder#, args ...any) { |
| 59 | for _, arg := range args { |
| 60 | writescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/write().(b, arg) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // AppendStrings writes strings to an existing strings.Builder. |
| 65 | // Directly writes each string arg to the provided strings.Builder. |
| 66 | // No type checks or conversions; assumes all args are strings. |
| 67 | // Efficient for appending known strings without separators. |
| 68 | // Does not use cat.Builder, as it appends to an existing strings.Builder. |
| 69 | func AppendStringsscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/AppendStrings().(b *stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Builderscip-go gomod github.com/golang/go/src go1.21 strings/Builder#, ss ...string) { |
| 70 | for _, s := range ss { |
| 71 | b.WriteStringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#WriteString().(s) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Between concatenates values wrapped between x and y (no separator between args). |
| 76 | // Equivalent to BetweenWith with an empty separator. |
| 77 | func Betweenscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Between().(x, y any, args ...any) string { |
| 78 | return BetweenWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/BetweenWith().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., x, y, args...) |
| 79 | } |
| 80 | |
| 81 | // BetweenWith concatenates values wrapped between x and y, using sep between x, args, and y. |
| 82 | // Uses a pooled Builder if enabled; releases it after use. |
| 83 | // Equivalent to With(sep, x, args..., y). |
| 84 | func BetweenWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/BetweenWith().(sep string, x, y any, args ...any) string { |
| 85 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(sep) |
| 86 | // Estimate size for all parts to avoid re-allocation. |
| 87 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().([]any{x, y}) + estimateWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimateWith().(sep, args)) |
| 88 | |
| 89 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(x) |
| 90 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(args...) |
| 91 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(y) |
| 92 | |
| 93 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 94 | } |
| 95 | |
| 96 | // CSV joins arguments with "," separators (no space). |
| 97 | // Convenience wrapper for With using a comma as separator. |
| 98 | // Useful for simple CSV string generation without spaces. |
| 99 | func CSVscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/CSV().(args ...any) string { return Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(commascip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/comma., args...) } |
| 100 | |
| 101 | // Comma joins arguments with ", " separators. |
| 102 | // Convenience wrapper for With using ", " as separator. |
| 103 | // Useful for human-readable lists with comma and space. |
| 104 | func Commascip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Comma().(args ...any) string { return Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(commascip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/comma.+spacescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/space., args...) } |
| 105 | |
| 106 | // Concat concatenates any values (no separators). |
| 107 | // Usage: cat.Concat("a", 1, true) → "a1true" |
| 108 | // Equivalent to With with an empty separator. |
| 109 | func Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(args ...any) string { |
| 110 | return Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., args...) |
| 111 | } |
| 112 | |
| 113 | // ConcatWith concatenates any values with separator. |
| 114 | // Alias for With; joins args with the provided sep. |
| 115 | func ConcatWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/ConcatWith().(sep string, args ...any) string { |
| 116 | return Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(sep, args...) |
| 117 | } |
| 118 | |
| 119 | // Flatten joins nested values into a single concatenation using empty. |
| 120 | // Convenience for FlattenWith using empty. |
| 121 | func Flattenscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Flatten().(args ...any) string { |
| 122 | return FlattenWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/FlattenWith().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., args...) |
| 123 | } |
| 124 | |
| 125 | // FlattenWith joins nested values into a single concatenation with sep, avoiding |
| 126 | // intermediate slice allocations where possible. |
| 127 | // It recursively flattens any nested []any arguments, concatenating all leaf items |
| 128 | // with sep between them. Skips empty nested slices to avoid extra separators. |
| 129 | // Leaf items (non-slices) are converted using the optimized write function. |
| 130 | // Uses a pooled Builder if enabled; releases it after use. |
| 131 | // Preallocates based on a recursive estimate for efficiency. |
| 132 | // Example: FlattenWith(",", 1, []any{2, []any{3,4}}, 5) → "1,2,3,4,5" |
| 133 | func FlattenWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/FlattenWith().(sep string, args ...any) string { |
| 134 | if len(args) == 0 { |
| 135 | return emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. |
| 136 | } |
| 137 | |
| 138 | // Recursive estimate for preallocation. |
| 139 | totalSize := recursiveEstimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/recursiveEstimate().(sep, args) |
| 140 | |
| 141 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(sep) |
| 142 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(totalSize) |
| 143 | recursiveAddscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/recursiveAdd().(b, args) |
| 144 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 145 | } |
| 146 | |
| 147 | // Group joins multiple groups with empty between groups (no intra-group separators). |
| 148 | // Convenience for GroupWith using empty. |
| 149 | func Groupscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Group().(groups ...[]any) string { |
| 150 | return GroupWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/GroupWith().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., groups...) |
| 151 | } |
| 152 | |
| 153 | // GroupWith joins multiple groups with a separator between groups (no intra-group separators). |
| 154 | // Concatenates each group internally without separators, then joins non-empty groups with sep. |
| 155 | // Preestimates total size for allocation; uses pooled Builder if enabled. |
| 156 | // Optimized for single group: direct Concat. |
| 157 | // Useful for grouping related items with inter-group separation. |
| 158 | func GroupWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/GroupWith().(sep string, groups ...[]any) string { |
| 159 | if len(groups) == 0 { |
| 160 | return emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. |
| 161 | } |
| 162 | if len(groups) == 1 { |
| 163 | return Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(groups[0]...) |
| 164 | } |
| 165 | |
| 166 | total := 0 |
| 167 | nonEmpty := 0 |
| 168 | for _, g := range groups { |
| 169 | if len(g) == 0 { |
| 170 | continue |
| 171 | } |
| 172 | if nonEmpty > 0 { |
| 173 | total += len(sep) |
| 174 | } |
| 175 | total += estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().(g) |
| 176 | nonEmpty++ |
| 177 | } |
| 178 | |
| 179 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty.) |
| 180 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(total) |
| 181 | first := true |
| 182 | for _, g := range groups { |
| 183 | if len(g) == 0 { |
| 184 | continue |
| 185 | } |
| 186 | if !first && sep != emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. { |
| 187 | b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf..WriteStringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#WriteString().(sep) |
| 188 | } |
| 189 | first = false |
| 190 | for _, a := range g { |
| 191 | writescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/write().(&b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf., a) |
| 192 | } |
| 193 | } |
| 194 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 195 | } |
| 196 | |
| 197 | // Indent prefixes the concatenation of args with depth levels of two spaces per level. |
| 198 | // Example: Indent(2, "hello") => " hello" |
| 199 | // If depth <= 0, equivalent to Concat(args...). |
| 200 | // Uses " " repeated depth times as prefix, followed by concatenated args (no separators). |
| 201 | // Benefits from pooling via Concat. |
| 202 | func Indentscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Indent().(depth int, args ...any) string { |
| 203 | if depth <= 0 { |
| 204 | return Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(args...) |
| 205 | } |
| 206 | prefix := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21 strings/Repeat().(" ", depth) |
| 207 | return Prefixscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Prefix().(prefix, args...) |
| 208 | } |
| 209 | |
| 210 | // Join joins strings (matches stdlib strings.Join behavior). |
| 211 | // Usage: cat.Join("a", "b") → "a b" (using empty) |
| 212 | // Joins the variadic string args with the current empty. |
| 213 | // Useful for compatibility with stdlib but using package default sep. |
| 214 | func Joinscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Join().(elems ...string) string { |
| 215 | return stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Joinscip-go gomod github.com/golang/go/src go1.21 strings/Join().(elems, emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty.) |
| 216 | } |
| 217 | |
| 218 | // JoinWith joins strings with separator (variadic version). |
| 219 | // Directly uses strings.Join on the variadic string args with sep. |
| 220 | // Efficient for known strings; no conversions needed. |
| 221 | func JoinWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/JoinWith().(sep string, elems ...string) string { |
| 222 | return stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Joinscip-go gomod github.com/golang/go/src go1.21 strings/Join().(elems, sep) |
| 223 | } |
| 224 | |
| 225 | // Lines joins arguments with newline separators. |
| 226 | // Convenience for With using "\n" as separator. |
| 227 | // Useful for building multi-line strings. |
| 228 | func Linesscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Lines().(args ...any) string { return Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(newlinescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/newline., args...) } |
| 229 | |
| 230 | // Number concatenates numeric values without separators. |
| 231 | // Generic over Numeric types. |
| 232 | // Equivalent to NumberWith with empty sep. |
| 233 | func Numberscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Number().[T Numericscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Numeric#](a ...T) string { |
| 234 | return NumberWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/NumberWith().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., a...) |
| 235 | } |
| 236 | |
| 237 | // NumberWith concatenates numeric values with the provided separator. |
| 238 | // Generic over Numeric types. |
| 239 | // If no args, returns empty string. |
| 240 | // Uses pooled Builder if enabled, with rough growth estimate (8 bytes per item). |
| 241 | // Relies on valueToString for numeric conversion. |
| 242 | func NumberWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/NumberWith().[T Numericscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Numeric#](sep string, a ...T) string { |
| 243 | if len(a) == 0 { |
| 244 | return emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. |
| 245 | } |
| 246 | |
| 247 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(sep) |
| 248 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(len(a) * 8) |
| 249 | for _, v := range a { |
| 250 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(v) |
| 251 | } |
| 252 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 253 | } |
| 254 | |
| 255 | // Path joins arguments with "/" separators. |
| 256 | // Convenience for With using "/" as separator. |
| 257 | // Useful for building file paths or URLs. |
| 258 | func Pathscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Path().(args ...any) string { return Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(slashscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/slash., args...) } |
| 259 | |
| 260 | // Prefix concatenates with a prefix (no separator). |
| 261 | // Equivalent to PrefixWith with empty sep. |
| 262 | func Prefixscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Prefix().(p any, args ...any) string { |
| 263 | return PrefixWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/PrefixWith().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., p, args...) |
| 264 | } |
| 265 | |
| 266 | // PrefixWith concatenates with a prefix and separator. |
| 267 | // Adds p, then sep (if args present and sep not empty), then joins args with sep. |
| 268 | // Uses pooled Builder if enabled. |
| 269 | func PrefixWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/PrefixWith().(sep string, p any, args ...any) string { |
| 270 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(sep) |
| 271 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(estimateWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimateWith().(sep, args) + estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().([]any{p})) |
| 272 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(p) |
| 273 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(args...) |
| 274 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 275 | } |
| 276 | |
| 277 | // PrefixEach applies the same prefix to each argument and joins the pairs with sep. |
| 278 | // Example: PrefixEach("pre-", ",", "a","b") => "pre-a,pre-b" |
| 279 | // Preestimates size including prefixes and seps. |
| 280 | // Uses pooled Builder if enabled; manually adds sep between pairs, no sep between p and a. |
| 281 | // Returns empty if no args. |
| 282 | func PrefixEachscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/PrefixEach().(p any, sep string, args ...any) string { |
| 283 | if len(args) == 0 { |
| 284 | return emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. |
| 285 | } |
| 286 | pSize := estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().([]any{p}) |
| 287 | total := len(sep)*(len(args)-1) + estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().(args) + pSize*len(args) |
| 288 | |
| 289 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty.) |
| 290 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(total) |
| 291 | for i, a := range args { |
| 292 | if i > 0 && sep != emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. { |
| 293 | b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf..WriteStringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#WriteString().(sep) |
| 294 | } |
| 295 | writescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/write().(&b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf., p) |
| 296 | writescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/write().(&b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf., a) |
| 297 | } |
| 298 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 299 | } |
| 300 | |
| 301 | // Pair joins exactly two values (no separator). |
| 302 | // Equivalent to PairWith with empty sep. |
| 303 | func Pairscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Pair().(a, b any) string { |
| 304 | return PairWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/PairWith().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., a, b) |
| 305 | } |
| 306 | |
| 307 | // PairWith joins exactly two values with a separator. |
| 308 | // Optimized for two args: uses With(sep, a, b). |
| 309 | func PairWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/PairWith().(sep string, a, b any) string { |
| 310 | return Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(sep, a, b) |
| 311 | } |
| 312 | |
| 313 | // Quote wraps each argument in double quotes, separated by spaces. |
| 314 | // Equivalent to QuoteWith with '"' as quote. |
| 315 | func Quotescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Quote().(args ...any) string { |
| 316 | return QuoteWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/QuoteWith().('"', args...) |
| 317 | } |
| 318 | |
| 319 | // QuoteWith wraps each argument with the specified quote byte, separated by spaces. |
| 320 | // Wraps each arg with quote, writes arg, closes with quote; joins with space. |
| 321 | // Preestimates with quotes and spaces. |
| 322 | // Uses pooled Builder if enabled. |
| 323 | func QuoteWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/QuoteWith().(quote byte, args ...any) string { |
| 324 | if len(args) == 0 { |
| 325 | return emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. |
| 326 | } |
| 327 | total := estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().(args) + 2*len(args) + len(spacescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/space.)*(len(args)-1) |
| 328 | |
| 329 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty.) |
| 330 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(total) |
| 331 | need := false |
| 332 | for _, a := range args { |
| 333 | if need { |
| 334 | b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf..WriteStringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#WriteString().(spacescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/space.) |
| 335 | } |
| 336 | b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf..WriteBytescip-go gomod github.com/golang/go/src go1.21 strings/Builder#WriteByte().(quote) |
| 337 | writescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/write().(&b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf., a) |
| 338 | b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf..WriteBytescip-go gomod github.com/golang/go/src go1.21 strings/Builder#WriteByte().(quote) |
| 339 | need = true |
| 340 | } |
| 341 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 342 | } |
| 343 | |
| 344 | // Repeat concatenates val n times (no sep between instances). |
| 345 | // Equivalent to RepeatWith with empty sep. |
| 346 | func Repeatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Repeat().(val any, n int) string { |
| 347 | return RepeatWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/RepeatWith().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., val, n) |
| 348 | } |
| 349 | |
| 350 | // RepeatWith concatenates val n times with sep between each instance. |
| 351 | // If n <= 0, returns an empty string. |
| 352 | // Optimized to make exactly one allocation; converts val once. |
| 353 | // Uses pooled Builder if enabled. |
| 354 | func RepeatWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/RepeatWith().(sep string, val any, n int) string { |
| 355 | if n <= 0 { |
| 356 | return emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. |
| 357 | } |
| 358 | if n == 1 { |
| 359 | return valueToStringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/valueToString().(val) |
| 360 | } |
| 361 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(sep) |
| 362 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(n*estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().([]any{val}) + (n-1)*len(sep)) |
| 363 | for i := 0; i < n; i++ { |
| 364 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(val) |
| 365 | } |
| 366 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 367 | } |
| 368 | |
| 369 | // Reflect converts a reflect.Value to its string representation. |
| 370 | // It handles all kinds of reflected values including primitives, structs, slices, maps, etc. |
| 371 | // For nil values, it returns the nilString constant ("<nil>"). |
| 372 | // For unexported or inaccessible fields, it returns unexportedString ("<?>"). |
| 373 | // The output follows Go's syntax conventions where applicable (e.g., slices as [a, b], maps as {k:v}). |
| 374 | func Reflectscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Reflect().(r reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.Valuescip-go gomod github.com/golang/go/src go1.21 reflect/Value#) string { |
| 375 | if !r.IsValidscip-go gomod github.com/golang/go/src go1.21 reflect/Value#IsValid().() { |
| 376 | return nilStringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/nilString. |
| 377 | } |
| 378 | |
| 379 | var b stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Builderscip-go gomod github.com/golang/go/src go1.21 strings/Builder# |
| 380 | writeReflectscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/writeReflect().(&b, r.Interfacescip-go gomod github.com/golang/go/src go1.21 reflect/Value#Interface().(), 0) |
| 381 | return b.Stringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#String().() |
| 382 | } |
| 383 | |
| 384 | // Space concatenates arguments with space separators. |
| 385 | // Convenience for With using " " as separator. |
| 386 | func Spacescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Space().(args ...any) string { return Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(spacescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/space., args...) } |
| 387 | |
| 388 | // Dot concatenates arguments with dot separators. |
| 389 | // Convenience for With using " " as separator. |
| 390 | func Dotscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Dot().(args ...any) string { return Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(dotscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/dot., args...) } |
| 391 | |
| 392 | // Suffix concatenates with a suffix (no separator). |
| 393 | // Equivalent to SuffixWith with empty sep. |
| 394 | func Suffixscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Suffix().(s any, args ...any) string { |
| 395 | return SuffixWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/SuffixWith().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., s, args...) |
| 396 | } |
| 397 | |
| 398 | // SuffixWith concatenates with a suffix and separator. |
| 399 | // Joins args with sep, then adds sep (if args present and sep not empty), then s. |
| 400 | // Uses pooled Builder if enabled. |
| 401 | func SuffixWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/SuffixWith().(sep string, s any, args ...any) string { |
| 402 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(sep) |
| 403 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(estimateWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimateWith().(sep, args) + estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().([]any{s})) |
| 404 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(args...) |
| 405 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(s) |
| 406 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 407 | } |
| 408 | |
| 409 | // SuffixEach applies the same suffix to each argument and joins the pairs with sep. |
| 410 | // Example: SuffixEach("-suf", " | ", "a","b") => "a-suf | b-suf" |
| 411 | // Preestimates size including suffixes and seps. |
| 412 | // Uses pooled Builder if enabled; manually adds sep between pairs, no sep between a and s. |
| 413 | // Returns empty if no args. |
| 414 | func SuffixEachscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/SuffixEach().(s any, sep string, args ...any) string { |
| 415 | if len(args) == 0 { |
| 416 | return emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. |
| 417 | } |
| 418 | sSize := estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().([]any{s}) |
| 419 | total := len(sep)*(len(args)-1) + estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().(args) + sSize*len(args) |
| 420 | |
| 421 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty.) |
| 422 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(total) |
| 423 | for i, a := range args { |
| 424 | if i > 0 && sep != emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. { |
| 425 | b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf..WriteStringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#WriteString().(sep) |
| 426 | } |
| 427 | writescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/write().(&b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf., a) |
| 428 | writescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/write().(&b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf., s) |
| 429 | } |
| 430 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 431 | } |
| 432 | |
| 433 | // Sprint concatenates any values (no separators). |
| 434 | // Usage: Sprint("a", 1, true) → "a1true" |
| 435 | // Equivalent to Concat or With with an empty separator. |
| 436 | func Sprintscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Sprint().(args ...any) string { |
| 437 | if len(args) == 0 { |
| 438 | return emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. |
| 439 | } |
| 440 | if len(args) == 1 { |
| 441 | return valueToStringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/valueToString().(args[0]) |
| 442 | } |
| 443 | |
| 444 | // For multiple args, use the existing Concat functionality |
| 445 | return Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(args...) |
| 446 | } |
| 447 | |
| 448 | // Trio joins exactly three values (no separator). |
| 449 | // Equivalent to TrioWith with empty sep |
| 450 | func Trioscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Trio().(a, b, c any) string { |
| 451 | return TrioWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TrioWith().(emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty., a, b, c) |
| 452 | } |
| 453 | |
| 454 | // TrioWith joins exactly three values with a separator. |
| 455 | // Optimized for three args: uses With(sep, a, b, c). |
| 456 | func TrioWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TrioWith().(sep string, a, b, c any) string { |
| 457 | return Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(sep, a, b, c) |
| 458 | } |
| 459 | |
| 460 | // With concatenates arguments with the specified separator. |
| 461 | // Core concatenation function with sep. |
| 462 | // Optimized for zero or one arg: empty or direct valueToString. |
| 463 | // Fast path for all strings: exact preallocation, direct writes via raw strings.Builder (minimal branches/allocs). |
| 464 | // Fallback: pooled Builder with estimateWith, adds args with sep. |
| 465 | // Benefits from pooling if enabled for mixed types. |
| 466 | func Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(sep string, args ...any) string { |
| 467 | switch len(args) { |
| 468 | case 0: |
| 469 | return emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. |
| 470 | case 1: |
| 471 | return valueToStringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/valueToString().(args[0]) |
| 472 | } |
| 473 | |
| 474 | // Fast path for all strings: use raw strings.Builder for speed, no pooling needed. |
| 475 | allStrings := true |
| 476 | totalLen := len(sep) * (len(args) - 1) |
| 477 | for _, a := range args { |
| 478 | if s, ok := a.(string); ok { |
| 479 | totalLen += len(s) |
| 480 | } else { |
| 481 | allStrings = false |
| 482 | break |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | if allStrings { |
| 487 | var b stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Builderscip-go gomod github.com/golang/go/src go1.21 strings/Builder# |
| 488 | b.Growscip-go gomod github.com/golang/go/src go1.21 strings/Builder#Grow().(totalLen) |
| 489 | b.WriteStringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#WriteString().(args[0].(string)) |
| 490 | for i := 1; i < len(args); i++ { |
| 491 | if sep != emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. { |
| 492 | b.WriteStringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#WriteString().(sep) |
| 493 | } |
| 494 | b.WriteStringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#WriteString().(args[i].(string)) |
| 495 | } |
| 496 | return b.Stringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#String().() |
| 497 | } |
| 498 | |
| 499 | // Fallback for mixed types: use pooled Builder. |
| 500 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(sep) |
| 501 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(estimateWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimateWith().(sep, args)) |
| 502 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(args...) |
| 503 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 504 | } |
| 505 | |
| 506 | // Wrap encloses concatenated args between before and after strings (no inner separator). |
| 507 | // Equivalent to Concat(before, args..., after). |
| 508 | func Wrapscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Wrap().(before, after string, args ...any) string { |
| 509 | b := Startscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Start().() |
| 510 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(len(before) + len(after) + estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().(args)) |
| 511 | |
| 512 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(before) |
| 513 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(args...) |
| 514 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(after) |
| 515 | |
| 516 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 517 | } |
| 518 | |
| 519 | // WrapEach wraps each argument individually with before/after, concatenated without separators. |
| 520 | // Applies before + arg + after to each arg. |
| 521 | // Preestimates size; uses pooled Builder if enabled. |
| 522 | // Returns empty if no args. |
| 523 | // Useful for wrapping multiple items identically without joins. |
| 524 | func WrapEachscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/WrapEach().(before, after string, args ...any) string { |
| 525 | if len(args) == 0 { |
| 526 | return emptyscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/empty. |
| 527 | } |
| 528 | total := (len(before)+len(after))*len(args) + estimatescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/estimate().(args) |
| 529 | |
| 530 | b := Startscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Start().() // Use pooled builder, but we will write manually. |
| 531 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(total) |
| 532 | for _, a := range args { |
| 533 | writescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/write().(&b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf., before) |
| 534 | writescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/write().(&b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf., a) |
| 535 | writescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/write().(&b.bufscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#buf., after) |
| 536 | } |
| 537 | // No separators were ever added, so this is safe. |
| 538 | b.needsSepscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#needsSep. = true // Correctly set state in case of reuse. |
| 539 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 540 | } |
| 541 | |
| 542 | // WrapWith encloses concatenated args between before and after strings, |
| 543 | // joining the arguments with the provided separator. |
| 544 | // If no args, returns before + after. |
| 545 | // Builds inner with With(sep, args...), then Concat(before, inner, after). |
| 546 | // Benefits from pooling via With and Concat. |
| 547 | func WrapWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/WrapWith().(sep, before, after string, args ...any) string { |
| 548 | if len(args) == 0 { |
| 549 | return before + after |
| 550 | } |
| 551 | // First, efficiently build the inner part. |
| 552 | inner := Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(sep, args...) |
| 553 | |
| 554 | // Then, wrap it without allocating another slice. |
| 555 | b := Startscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Start().() |
| 556 | b.Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(len(before) + len(inner) + len(after)) |
| 557 | |
| 558 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(before) |
| 559 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(inner) |
| 560 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(after) |
| 561 | |
| 562 | return b.Outputscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Output().() |
| 563 | } |
| 564 | |
| 565 | // Pad surrounds a string with spaces on both sides. |
| 566 | // Ensures proper spacing for SQL operators like "=", "AND", etc. |
| 567 | // Example: Pad("=") returns " = " for cleaner formatting. |
| 568 | func Padscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Pad().(s string) string { |
| 569 | return Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(spacescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/space., s, spacescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/space.) |
| 570 | } |
| 571 | |
| 572 | // PadWith adds a separator before the string and a space after it. |
| 573 | // Useful for formatting SQL parts with custom leading separators. |
| 574 | // Example: PadWith(",", "column") returns ",column ". |
| 575 | func PadWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/PadWith().(sep, s string) string { |
| 576 | return Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(sep, s, spacescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/space.) |
| 577 | } |
| 578 | |
| 579 | // Parens wraps content in parentheses |
| 580 | // Useful for grouping SQL conditions or expressions |
| 581 | // Example: Parens("a = b AND c = d") → "(a = b AND c = d)" |
| 582 | func Parensscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Parens().(content string) string { |
| 583 | return Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(parenOpenscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/parenOpen., content, parenClosescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/parenClose.) |
| 584 | } |
| 585 | |
| 586 | // ParensWith wraps multiple arguments in parentheses with a separator |
| 587 | // Example: ParensWith(" AND ", "a = b", "c = d") → "(a = b AND c = d)" |
| 588 | func ParensWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/ParensWith().(sep string, args ...any) string { |
| 589 | return Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(parenOpenscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/parenOpen., Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(sep, args...), parenClosescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/parenClose.) |
| 590 | } |