Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLPosition.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
10#include <algorithm>
11
12namespace SkSL {
13
14int Position::line(std::string_view source) const {
15 SkASSERT(this->valid());
16 if (fStartOffset == -1) {
17 return -1;
18 }
19 if (!source.data()) {
20 return -1;
21 }
22 // we allow the offset to equal the length, because that's where TK_END_OF_FILE is reported
23 SkASSERT(fStartOffset <= (int)source.length());
24 int offset = std::min(fStartOffset, (int)source.length());
25 int line = 1;
26 for (int i = 0; i < offset; i++) {
27 if (source[i] == '\n') {
28 ++line;
29 }
30 }
31 return line;
32}
33
34} // namespace SkSL
#define SkASSERT(cond)
Definition SkAssert.h:116
int line(std::string_view source) const
bool valid() const
SkBitmap source
Definition examples.cpp:28
Point offset