-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
templater: make .substr() be byte-index based, round towards origin
I'm going to add string.len() method which will return a length in bytes. The number of the UTF-8 code points is useless metrics, and strings here are often ASCII bytes, so let's simply use byte indices in substr(). If the given index is not at a char boundary, it will be rounded. I considered making it an error, but that would be annoying. I would want to see something printed by author.name().substr() even if it contained latin characters. I've extracted index normalization function which might be used by other string methods. The remaining part of substr() is trivial, so inlined it.
- Loading branch information
Showing
2 changed files
with
37 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters