30 |
// Author: Sanjay Ghemawat |
// Author: Sanjay Ghemawat |
31 |
|
|
32 |
#include <vector> |
#include <vector> |
|
#include <algorithm> // for count() |
|
33 |
#include <assert.h> |
#include <assert.h> |
34 |
#include "config.h" |
#include "config.h" |
35 |
#include "pcre_scanner.h" |
#include "pcre_scanner.h" |
89 |
int Scanner::LineNumber() const { |
int Scanner::LineNumber() const { |
90 |
// TODO: Make it more efficient by keeping track of the last point |
// TODO: Make it more efficient by keeping track of the last point |
91 |
// where we computed line numbers and counting newlines since then. |
// where we computed line numbers and counting newlines since then. |
92 |
return 1 + std::count(data_.data(), input_.data(), '\n'); |
// We could use std:count, but not all systems have it. :-( |
93 |
|
int count = 1; |
94 |
|
for (const char* p = data_.data(); p < input_.data(); ++p) |
95 |
|
if (*p == '\n') |
96 |
|
++count; |
97 |
|
return count; |
98 |
} |
} |
99 |
|
|
100 |
int Scanner::Offset() const { |
int Scanner::Offset() const { |