import re


def to_sbp_struct(identifier):
    """
    Convert identifier to c struct name.
    """
    if identifier.isupper():
        identifier = identifier.lower() + '_t'
    else:
        # https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
        identifier = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', identifier)
        identifier = re.sub('([a-z0-9])([A-Z])', r'\1_\2', identifier).lower() + '_t'
    # Handle these to cases individually.
    if identifier == 'gnss_signal_t' or identifier == 'gps_time_t':
        identifier = 'sbp_' + identifier
    return identifier