import re


def as_fuse_id(shader_name,shader_id):
  """
  Derive an identifier from shader_name.

  Remove whitespace, leading digits, special characters, etc to make something that can be used as an identifier out of `shader_name`.
  Such an identifier is in particular what's needed as the first parametert to `FuRegisterClass()`.
  """

  name = shader_name

  # Example: "Fork Who cares? nmbr73 321" -> "Who cares"
  name = re.sub(r'^Fork (.+) ([^ ]+) \d+$',r'\1',name)

  # Replace all invalid characters with a ' '
  name = re.sub(r'[^A-Za-z0-9 ]+',' ', name)

  # Put 'D' in front if first character is a digit
  name = re.sub(r'^(\d.*)$',r'D\1', name)

  # Transform leading characters to upper case
  name = name.title()

  # Eliminate all spaces
  name = ''.join(x for x in name if not x.isspace())

  return name