From d49679d8856cb843bf57dd3332bce9634f10f289 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 7 Jan 2018 15:52:46 -0800 Subject: [PATCH] Fix Range serialization for -1:-1--1:-1 --- src/position.cc | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/position.cc b/src/position.cc index 73a54e17..861bc603 100644 --- a/src/position.cc +++ b/src/position.cc @@ -77,21 +77,18 @@ Range::Range(Position position) : Range(position, position) {} Range::Range(Position start, Position end) : start(start), end(end) {} Range::Range(const char* encoded) { - end = start; + char* p = const_cast(encoded); + start.line = strtol(p, &p, 10); + assert(*p == ':'); + p++; + start.column = strtol(p, &p, 10); + assert(*p == '-'); + p++; - start.line = (int16_t)atoi(encoded); - - encoded = SkipAfter(encoded, ':'); - assert(encoded); - start.column = (int16_t)atoi(encoded); - - encoded = SkipAfter(encoded, '-'); - assert(encoded); - end.line = (int16_t)atoi(encoded); - - encoded = SkipAfter(encoded, ':'); - assert(encoded); - end.column = (int16_t)atoi(encoded); + end.line = strtol(p, &p, 10); + assert(*p == ':'); + p++; + end.column = strtol(p, nullptr, 10); } bool Range::Contains(int line, int column) const {