MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / Parse

Function Parse

pkg/util/bitarray/bitarray.go:323–357  ·  view source on GitHub ↗

Parse parses a bit array from the specified string.

(s string)

Source from the content-addressed store, hash-verified

321
322// Parse parses a bit array from the specified string.
323func Parse(s string) (res BitArray, err error) {
324 if len(s) == 0 {
325 return res, nil
326 }
327
328 words, lastBitsUsed := EncodingPartsForBitLen(uint(len(s)))
329
330 // Parse the bits.
331 wordIdx := 0
332 bitIdx := uint(0)
333 curWord := word(0)
334 for _, c := range s {
335 val := word(c - '0')
336 bitVal := val & 1
337 if bitVal != val {
338 // Note: the prefix "could not parse" is important as it is used
339 // to detect parsing errors in tests.
340 err := fmt.Errorf(`could not parse string as bit array: "%c" is not a valid binary digit`, c)
341 return res, pgerror.WithCandidateCode(err, pgcode.InvalidTextRepresentation)
342 }
343 curWord |= bitVal << (63 - bitIdx)
344 bitIdx = (bitIdx + 1) % numBitsPerWord
345 if bitIdx == 0 {
346 words[wordIdx] = curWord
347 curWord = 0
348 wordIdx++
349 }
350 }
351 if bitIdx > 0 {
352 // Ensure the last word is stored.
353 words[wordIdx] = curWord
354 }
355
356 return FromEncodingParts(words, lastBitsUsed)
357}
358
359// Concat concatenates two bit arrays.
360func Concat(lhs, rhs BitArray) BitArray {

Callers 2

ParseDBitArrayFunction · 0.92
PerformCastFunction · 0.92

Calls 3

WithCandidateCodeFunction · 0.92
EncodingPartsForBitLenFunction · 0.85
FromEncodingPartsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…