aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric Huss <eric@huss.org>2019-08-13 14:51:03 -0700
committerGitHub <noreply@github.com>2019-08-13 14:51:03 -0700
commit801188700fbabf9bb0fea11b88e0720fadb8cd36 (patch)
tree7c401dc26a6cdb947a279fe964f72d06f275d5bb /src
parentd03b251af5f935ea8363ebc59f1caddf99feb790 (diff)
parentf4dd4a2438c0000846a6bfd21d8b18dc47f280cf (diff)
downloadmilf-rs-801188700fbabf9bb0fea11b88e0720fadb8cd36.tar.gz
milf-rs-801188700fbabf9bb0fea11b88e0720fadb8cd36.zip
Merge pull request #320 from ehuss/crlf-error-index
Fix error line/column when using CRLF line endings.
Diffstat (limited to 'src')
-rw-r--r--src/de.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/de.rs b/src/de.rs
index 234fa50..e71cd0c 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -1775,7 +1775,10 @@ impl<'a> Deserializer<'a> {
/// All indexes are 0-based.
fn to_linecol(&self, offset: usize) -> (usize, usize) {
let mut cur = 0;
- for (i, line) in self.input.lines().enumerate() {
+ // Use split_terminator instead of lines so that if there is a `\r`,
+ // it is included in the offset calculation. The `+1` values below
+ // account for the `\n`.
+ for (i, line) in self.input.split_terminator('\n').enumerate() {
if cur + line.len() + 1 > offset {
return (i, offset - cur);
}