# File lib/dbd/pg/type.rb, line 125
125:         def convert_array(str)
126: 
127:             array_nesting = 0         # nesting level of the array
128:             in_string = false         # currently inside a quoted string ?
129:             escaped = false           # if the character is escaped
130:             sbuffer = ''              # buffer for the current element
131:             result_array = ::Array.new  # the resulting Array
132: 
133:             str.each_byte { |char|    # parse character by character
134:                 char = char.chr         # we need the Character, not it's Integer
135: 
136:                 if escaped then         # if this character is escaped, just add it to the buffer
137:                     sbuffer += char
138:                     escaped = false
139:                     next
140:                 end
141: 
142:                 case char               # let's see what kind of character we have
143:                     #------------- {: beginning of an array ----#
144:                 when '{'
145:                     if in_string then     # ignore inside a string
146:                         sbuffer += char
147:                         next
148:                     end
149: 
150:                 if array_nesting >= 1 then  # if it's an nested array, defer for recursion
151:                     sbuffer += char
152:                 end
153:                 array_nesting += 1          # inside another array
154: 
155:                 #------------- ": string deliminator --------#
156:                 when '"'
157:                     in_string = !in_string      
158: 
159:                     #------------- \: escape character, next is regular character #
160:                 when "\\"     # single \, must be extra escaped in Ruby
161:                     if array_nesting > 1
162:                         sbuffer += char
163:                     else
164:                         escaped = true
165:                     end
166: 
167:                     #------------- ,: element separator ---------#
168:                 when ','
169:                     if in_string or array_nesting > 1 then  # don't care if inside string or
170:                         sbuffer += char                       # nested array
171:                     else
172:                         if !sbuffer.is_a? ::Array then
173:                             sbuffer = @base_type.parse(sbuffer)
174:                         end
175:                         result_array << sbuffer               # otherwise, here ends an element
176:                         sbuffer = ''
177:                     end
178: 
179:                 #------------- }: End of Array --------------#
180:                 when '}' 
181:                     if in_string then                # ignore if inside quoted string
182:                         sbuffer += char
183:                         next
184:                     end
185: 
186:                     array_nesting -=1                # decrease nesting level
187: 
188:                     if array_nesting == 1            # must be the end of a nested array 
189:                         sbuffer += char
190:                         sbuffer = convert_array( sbuffer )  # recurse, using the whole nested array
191:                     elsif array_nesting > 1          # inside nested array, keep it for later
192:                         sbuffer += char
193:                     else                             # array_nesting = 0, must be the last }
194:                         if !sbuffer.is_a? ::Array then
195:                             sbuffer = @base_type.parse( sbuffer )
196:                         end
197: 
198:                         result_array << sbuffer unless sbuffer.nil? # upto here was the last element
199:                     end
200: 
201:                     #------------- all other characters ---------#
202:                 else
203:                     sbuffer += char                 # simply append
204:                 end
205:             } 
206:             return result_array
207:         end