It's surprisingly hard to get the first line from a string, so let's
have our own function in stringutil for it.
Details
Details
- Reviewers
Alphare - Group Reviewers
hg-reviewers - Commits
- rHG51aed118f9dc: templates: extract function to `stringutil` for getting first line of text
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Event Timeline
Comment Actions
I wonder if we shouldn't optimize for the common case of multiple lines by using find() instead. Searching for \n first and \r second (in the substring if the first got a hit) and only then slicing the result.
Comment Actions
I was wondering the same, but it's easier said than done because Python doesn't seem to give access to the bytes used for splitting in splitlines(). I was thinking of using split() as you said, but I didn't think of using splitlines()` on the first part of the result, so thanks for the tip! I'll add a commit to the end of this stack.