Utility to clean trailing empty segments from texts