def _position_is_bracketed(string, position):
 position = len(string[:position])
 (index, length) = (0, len(string))
 while (index < position):
  char = string[index]
  index += 1
  if (char == '['):
   closing_index = _end_of_set_index(string, index)
   if (closing_index < length):
    if (index <= position < closing_index):
     return True
    index = (closing_index + 1)
   else:
    return False
 return False

def _position_is_bracketed ( string , position ) : position = len ( string [ : position ] ) ( index , length ) = ( 0 , len ( string ) ) while ( index < position ) : char = string [ index ] index += 1 if ( char == '[' ) : closing_index = _end_of_set_index ( string , index ) if ( closing_index < length ) : if ( index <= position < closing_index ) : return True index = ( closing_index + 1 ) else : return False return False
tests whether the char at string[position] is inside a valid pair of brackets .