def resolve_neutral_types(storage, debug):
for run in storage['<STR_LIT>']:<EOL><INDENT>start, length = run['<STR_LIT:start>'], run['<STR_LIT>']<EOL>chars = [{'<STR_LIT:type>': run['<STR_LIT>']}] + storage['<STR_LIT>'][start:start+length] +[{'<STR_LIT:type>': run['<STR_LIT>']}]<EOL>total_chars = len(chars)<EOL>seq_start = None<EOL>for idx in range(total_chars):<EOL><INDENT>_ch = chars[idx]<EOL>if _ch['<STR_LIT:type>'] in ('<STR_LIT:B>', '<STR_LIT:S>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if seq_start is None:<EOL><INDENT>seq_start = idx<EOL>prev_bidi_type = chars[idx-<NUM_LIT:1>]['<STR_LIT:type>']<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if seq_start is not None:<EOL><INDENT>next_bidi_type = chars[idx]['<STR_LIT:type>']<EOL>if prev_bidi_type in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>prev_bidi_type = '<STR_LIT:R>'<EOL><DEDENT>if next_bidi_type in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>next_bidi_type = '<STR_LIT:R>'<EOL><DEDENT>for seq_idx in range(seq_start, idx):<EOL><INDENT>if prev_bidi_type == next_bidi_type:<EOL><INDENT>chars[seq_idx]['<STR_LIT:type>'] = prev_bidi_type<EOL><DEDENT>else:<EOL><INDENT>chars[seq_idx]['<STR_LIT:type>'] =_embedding_direction(chars[seq_idx]['<STR_LIT>'])<EOL><DEDENT><DEDENT>seq_start = None<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if debug:<EOL><INDENT>debug_storage(storage)<EOL><DEDENT>
Resolving neutral types. Implements N1 and N2

    See: http://unicode.org/reports/tr9/#Resolving_Neutral_Types