# Path: snaked/core/titler.py
# def create_fsm(format):
#     import re
# 
#     alt_matcher = re.compile('\{(.+?)\}')
#     handler_matcher = re.compile('%([_a-zA-Z0-9]+)')
#     handlers = {}
#     hid = [0]
# 
#     def replace_alt(match):
#         hlist = []
#         for m in match.group(1).split('|'):
#             hm = handler_matcher.search(m)
#             if hm:
#                 hlist.append((title_handlers.get(hm.group(1), empty_handler),
#                     handler_matcher.sub('%s', m)))
#             else:
#                 hlist.append((None, m))
# 
#         hid[0] += 1
#         hid_name = 'alt_%d' % hid[0]
#         handlers[hid_name] = create_alternative_handler(hlist)
#         return '%%(%s)s' % hid_name
# 
#     def replace_handlers(match):
#         hname = match.group(1)
#         handlers[hname] = title_handlers.get(hname, empty_handler)
#         return '%%(%s)s' % hname
# 
#     result = alt_matcher.sub(replace_alt, format)
#     result = handler_matcher.sub(replace_handlers, result)
# 
#     def root(editor):
#         rdict = {}
#         for k, h in handlers.items():
#             value = h(editor)
#             if value is None:
#                 value = ''
#             rdict[k] = value
# 
#         return result % rdict
# 
#     return root
# 
# def add_title_handler(name, callback):
#     title_handlers[name] = callback


from snaked.core.titler import create_fsm, add_title_handler

def hempty(name):
    return None

def hid(name):
    return name

def hq(name):
    return '"%s"' % ( name if name else None)

add_title_handler('hid', hid)
add_title_handler('hq', hq)

# Path: snaked/core/titler.py
# def create_fsm(format):
#     import re
# 
#     alt_matcher = re.compile('\{(.+?)\}')
#     handler_matcher = re.compile('%([_a-zA-Z0-9]+)')
#     handlers = {}
#     hid = [0]
# 
#     def replace_alt(match):
#         hlist = []
#         for m in match.group(1).split('|'):
#             hm = handler_matcher.search(m)
#             if hm:
#                 hlist.append((title_handlers.get(hm.group(1), empty_handler),
#                     handler_matcher.sub('%s', m)))
#             else:
#                 hlist.append((None, m))
# 
#         hid[0] += 1
#         hid_name = 'alt_%d' % hid[0]
#         handlers[hid_name] = create_alternative_handler(hlist)
#         return '%%(%s)s' % hid_name
# 
#     def replace_handlers(match):
#         hname = match.group(1)
#         handlers[hname] = title_handlers.get(hname, empty_handler)
#         return '%%(%s)s' % hname
# 
#     result = alt_matcher.sub(replace_alt, format)
#     result = handler_matcher.sub(replace_handlers, result)
# 
#     def root(editor):
#         rdict = {}
#         for k, h in handlers.items():
#             value = h(editor)
#             if value is None:
#                 value = ''
#             rdict[k] = value
# 
#         return result % rdict
# 
#     return root
# 
# def add_title_handler(name, callback):
#     title_handlers[name] = callback


# Path: tests/test_titler.py
from snaked.core.titler import create_fsm, add_title_handler


def hempty(name):
    return None

def hid(name):
    return name

def hq(name):
    return '"%s"' % ( name if name else None)

add_title_handler('hid', hid)
add_title_handler('hq', hq)

add_title_handler('hempty', hempty)