def HyphenateWord(original_word, max_length, join_str='-'):
  """Breaks a word at max_length with hyphens.

  If the word is still too long (i.e., length > 2*max_length), the word will
  be split again. The word will be split at word breaks defined by a
  switch from lowercase to uppercase. The function will attempt to break at
  the closest switch before the max_length number of letters. If there is no
  upper case letter before the max_length, the original word will be returned.
  If max_length is 0 the original word will be returned.

  Args:
    original_word: the word to break.
    max_length: maximum length in chars for any piece of the word.
    join_str: characters to join the hyphenated parts with, defaults to '-'
  Returns:
    the hyphenated word.
  """
  word_list = []
  while len(original_word) > max_length:
    for i in range(max_length, -1, -1):
      if original_word[i].isupper():
        word_list += [original_word[:i]]
        original_word = original_word[i:]
        break
      if i == 0:
        # There was no uppercase letter found so we don't break and just
        # return the original word
        return original_word

  word_list += [original_word]

  return join_str.join(word_list)