code: func Parse(topic string, allowWildcards bool) (string, error) {
  	// check for zero length
  	if topic == "" {
  		return "", ErrZeroLength
  	}
  
  	// normalize topic
  	topic = multiSlashRegex.ReplaceAllString(topic, "/")
  
  	// remove trailing slashes
  	topic = strings.TrimRight(topic, "/")
  
  	// check again for zero length
  	if topic == "" {
  		return "", ErrZeroLength
  	}
  
  	// split to segments
  	segments := strings.Split(topic, "/")
  
  	// check all segments
  	for i, s := range segments {
  		// check use of wildcards
  		if (strings.Contains(s, "+") || strings.Contains(s, "#")) && len(s) > 1 {
  			return "", ErrWildcards
  		}
  
  		// check if wildcards are allowed
  		if !allowWildcards && (s == "#" || s == "+") {
  			return "", ErrWildcards
  		}
  
  		// check if hash is the last character
  		if s == "#" && i != len(segments)-1 {
  			return "", ErrWildcards
  		}
  	}
  
  	return topic, nil
  }
docs: // Parse removes duplicate and trailing slashes from the supplied
  // string and returns the normalized topic.