Line data Source code
1 : // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 : // for details. All rights reserved. Use of this source code is governed by a
3 : // BSD-style license that can be found in the LICENSE file.
4 :
5 : /// Returns the minimum of [obj1] and [obj2] according to
6 : /// [Comparable.compareTo].
7 : Comparable min(Comparable obj1, Comparable obj2) =>
8 0 : obj1.compareTo(obj2) > 0 ? obj2 : obj1;
9 :
10 : /// Returns the maximum of [obj1] and [obj2] according to
11 : /// [Comparable.compareTo].
12 : Comparable max(Comparable obj1, Comparable obj2) =>
13 0 : obj1.compareTo(obj2) > 0 ? obj1 : obj2;
14 :
15 : /// Finds a line in [context] containing [text] at the specified [column].
16 : ///
17 : /// Returns the index in [context] where that line begins, or null if none
18 : /// exists.
19 : int findLineStart(String context, String text, int column) {
20 0 : var isEmpty = text == '';
21 0 : var index = context.indexOf(text);
22 0 : while (index != -1) {
23 0 : var lineStart = context.lastIndexOf('\n', index) + 1;
24 0 : var textColumn = index - lineStart;
25 0 : if (column == textColumn || (isEmpty && column == textColumn + 1)) {
26 : return lineStart;
27 : }
28 0 : index = context.indexOf(text, index + 1);
29 : }
30 : return null;
31 : }
|