private static IEnumerable <IRecordedMessage> InRelativeTopic(IEnumerable <IRecordedMessage> messages, string relativeTopicNamePattern) { using (var regexCache = new RosNameRegexCache()) { foreach (var message in messages) { if (message.IsInRelativeTopic(relativeTopicNamePattern, regexCache)) { yield return(message); } } } }
private static bool IsInRelativeTopic(this IRecordedMessage message, string relativeTopicNamePattern, RosNameRegexCache regexCache = null) { var scopedMessage = message as INamespaceScopedTopicMessage <IRecordedMessage>; if (scopedMessage == null) { throw new InvalidRosNamePatternException( "Relative topic name patterns are only supported if messages were filtered by namespace before."); } var globalName = scopedMessage.NamespacePattern + "/" + relativeTopicNamePattern; var regex = regexCache != null ? regexCache.GetOrCreate(globalName) : RosNameRegex.Create(globalName); return(regex.IsMatch(message.Topic)); }