Refactor truncation logic into a _truncate helper function.