def fields_match(string_1,
                 string_2,
                 field_separator=':',
                 allow_empty_fields=True):
  """Match fields of two strings, separated by a |field_separator|. Empty fields
  can be ignored via |allow_empty_fields| flag."""
  if string_1 is None or string_2 is None:
    return False
  if string_1 == string_2:
    return True

  string_1_fields = string_1.split(field_separator)
  string_2_fields = string_2.split(field_separator)

  if not allow_empty_fields and len(string_1_fields) != len(string_2_fields):
    return False

  min_fields_length = min(len(string_1_fields), len(string_2_fields))
  for i in range(min_fields_length):
    if string_1_fields[i] != string_2_fields[i]:
      return False

  return True