<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_tag(self, p_key, p_value="", p_force_add=False, p_old_value=""):
 """ Sets a occurrence of the tag identified by p_key. Sets an arbitrary instance of the tag when the todo contains multiple tags with this key. When p_key does not exist, the tag is added. When p_value is not set, the tag will be removed. When p_force_add is true, a tag will always be added to the todo, in case there is already a tag with the given key. When p_old_value is set, all tags having this value will be set to the new value. """

        if p_value == "":
            self.remove_tag(p_key, p_old_value)
            return

        tags = self.fields['tags']
        value = p_old_value if p_old_value else self.tag_value(p_key)

        if not p_force_add and value:
            self._remove_tag_helper(p_key, value)

            self.src = re.sub(
                r'\b' + p_key + ':' + value + r'\b',
                p_key + ':' + p_value,
                self.src
            )
        else:
            self.src += ' ' + p_key + ':' + p_value

        try:
            tags[p_key].append(p_value)
        except KeyError:
            tags[p_key] = [p_value]