binary search lut to find node ending (as in range[1] at or before pos. null if none
519087
function findNodeBeforePos(pos) {
    const lut = this.ends;
    assert(is.finitenumber(pos) && pos >= 0);

    let left = 0;
    let right = lut.length - 1;
    while (left < right) {
        const mid = Math.ceil((left + right) / 2);
        assert(mid >= 0 && mid < lut.length);
        if (pos < lut[mid].range[1]) {
            right = mid - 1;
        }
        else {
            left = mid;
        }
    }
    if (left > right) {
        assert(lut[0].range[1] > pos);
        return null;
    }

    const found = left;
    const foundPos = lut[found].range[1];
    if(foundPos > pos) {
        return null;
    }
    if (found <= lut.length - 2) {
        const nextPos = lut[found + 1].range[1];
        assert(nextPos > pos);
    }

    return lut[found];
}
1113434
function finishNodeAt(node, type, pos, loc) {
  node.type = type;
  node.end = pos;
  if (this.options.locations) node.loc.end = loc;
  if (this.options.ranges) node.range[1] = pos;
  return node;
}
1264142
private Tree<Row> findEndIf( Tree<Row> pointer ){
        while( !Type.END_IF.equals( pointer.getContent().getType() ) ){
            pointer = pointer.getNext();
        }
        return pointer;
    }
722854
function findTextNodeRelative(left, startNode) {
            var walker, lastInlineElement, parentBlockContainer;

            startNode = startNode || container;
            parentBlockContainer = dom.getParent(startNode.parentNode, dom.isBlock) || body;

            // Lean left before the BR element if it's the only BR within a block element. Gecko bug: #6680
            // This: <p><br>|</p> becomes <p>|<br></p>
            if (left && startNode.nodeName == 'BR' && isAfterNode && dom.isEmpty(parentBlockContainer)) {
              container = startNode.parentNode;
              offset = dom.nodeIndex(startNode);
              normalized = true;
              return;
            }

            // Walk left until we hit a text node we can move to or a block/br/img
            walker = new TreeWalker(startNode, parentBlockContainer);
            while ((node = walker[left ? 'prev' : 'next']())) {
              // Break if we hit a non content editable node
              if (dom.getContentEditableParent(node) === "false" || isCeFalseCaretContainer(node, dom.getRoot())) {
                return;
              }

              // Found text node that has a length
              if (node.nodeType === 3 && node.nodeValue.length > 0) {
                if (hasParentWithName(node, body, 'A') === false) {
                  container = node;
                  offset = left ? node.nodeValue.length : 0;
                  normalized = true;
                }

                return;
              }

              // Break if we find a block or a BR/IMG/INPUT etc
              if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
                return;
              }

              lastInlineElement = node;
            }

            // Only fetch the last inline element when in caret mode for now
            if (collapsed && lastInlineElement) {
              container = lastInlineElement;
              normalized = true;
              offset = 0;
            }
          }
480029
def find(self, node, interval, start, end):
        """"""
        data = []
        
        if len(interval) != 2:
            raise SyntaxError('Interval malformed %s. Allways specify start and end position for interval.' % str(interval))
        
        left = (start, node[0])
        right = (node[0], end)

        if self.overlap(left, interval):
            data.extend(node[-1])
            if node[1] != -1:
                data.extend(self.find(node[1], interval, left[0], left[1]))

        if self.overlap(right, interval):
            data.extend(node[-1])
            if node[2] != -1:
                data.extend(self.find(node[2], interval, right[0], right[1]))

        return list(set(data))
58091
def find(node, nbk)
      node_type = get_node_type node

      case node_type
      when :blank
        BLANK_NODE
      when :branch
        return node.last if nbk.empty?

        sub_node = decode_to_node node[nbk[0]]
        find sub_node, nbk[1..-1]
      when :leaf
        node_key = NibbleKey.decode(node[0]).terminate(false)
        nbk == node_key ? node[1] : BLANK_NODE
      when :extension
        node_key = NibbleKey.decode(node[0]).terminate(false)
        if node_key.prefix?(nbk)
          sub_node = decode_to_node node[1]
          find sub_node, nbk[node_key.size..-1]
        else
          BLANK_NODE
        end
      else
        raise InvalidNodeType, "node type must be in #{NODE_TYPES}, given: #{node_type}"
      end
    end
517444
def end_node(self):
        
        return db.cypher_query("MATCH (aNode) "
                               "WHERE id(aNode)={nodeid} "
                               "RETURN aNode".format(nodeid=self._end_node_id),
                               resolve_objects = True)[0][0][0]
751536
private Region find(Region x) {
    Region current = this.root;
    while (current != NULL_NODE) {
      long res = x.orderRelativeTo(current);
      if (res < 0) {
        current = current.left;
      } else if (res > 0) {
        current = current.right;
      } else {
        return current;
      }
    }
    return null;
  }
1052806
@SuppressWarnings("fallthrough")
    private boolean findSection(int offset, Position pos)
    {
        int i = offset, len = rawBytes.length;
        int last = offset;
        int next;
        boolean allBlank = true;

        pos.endOfFirstLine = -1;

        while (i < len) {
            byte b = rawBytes[i];
            switch(b) {
            case '\r':
                if (pos.endOfFirstLine == -1)
                    pos.endOfFirstLine = i-1;
                if ((i < len) &&  (rawBytes[i+1] == '\n'))
                    i++;
                /* fall through */
            case '\n':
                if (pos.endOfFirstLine == -1)
                    pos.endOfFirstLine = i-1;
                if (allBlank || (i == len-1)) {
                    if (i == len-1)
                        pos.endOfSection = i;
                    else
                        pos.endOfSection = last;
                    pos.startOfNext = i+1;
                    return true;
                }
                else {
                    // start of a new line
                    last = i;
                    allBlank = true;
                }
                break;
            default:
                allBlank = false;
                break;
            }
            i++;
        }
        return false;
    }
1109760
private static Object findValue(final OptionElement subroot,
                                  final String[] pathElements, int pos) {
    if (pos >= 0) {
      // Not at root.
      if (!pathElements[pos].equals(subroot.name)) {
        return null;
      }
    }

    if (subroot.isValue) {
      // pos must be last entry
      if ((pos + 1) != pathElements.length) {
        return null;
      }
      return subroot.val;
    }

    pos++;
    if (pos == pathElements.length) {
      return null;
    }

    /* look to children for some value */

    Object singleRes = null;
    ArrayList<Object> multiRes = null;

    for (OptionElement optel: subroot.getChildren()) {
      Object res = findValue(optel, pathElements, pos);
      if (res != null) {
        if (singleRes != null) {
          multiRes = new ArrayList<Object>();
          appendResult(singleRes, multiRes);
          singleRes = null;
          appendResult(res, multiRes);
        } else if (multiRes != null) {
          appendResult(res, multiRes);
        } else {
          singleRes = res;
        }
      }
    }

    if (multiRes != null) {
      return multiRes;
    }

    return singleRes;
  }
9068
def _find_bracket_position(self, text, bracket_left, bracket_right,
                               pos_quote):
        
        pos = {}
        pstack = []

        for idx, character in enumerate(text):
            if character == bracket_left and \
                    not self.is_char_in_pairs(idx, pos_quote):
                pstack.append(idx)
            elif character == bracket_right and \
                    not self.is_char_in_pairs(idx, pos_quote):
                if len(pstack) == 0:
                    raise IndexError(
                        "No matching closing parens at: " + str(idx))
                pos[pstack.pop()] = idx

        if len(pstack) > 0:
            raise IndexError(
                "No matching opening parens at: " + str(pstack.pop()))

        return pos
750410
def end_nodes(self):
        
        for varname, reg in self._nodes_to_regs():
            # If this part goes until the end of the input string.
            if reg[1] == len(self.string):
                value = self._unescape(varname, self.string[reg[0]: reg[1]])
                yield MatchVariable(varname, value, (reg[0], reg[1]))
356241
def _find_read_pos(self) -> Optional[int]:
        
        if self._read_bytes is not None and (
            self._read_buffer_size >= self._read_bytes
            or (self._read_partial and self._read_buffer_size > 0)
        ):
            num_bytes = min(self._read_bytes, self._read_buffer_size)
            return num_bytes
        elif self._read_delimiter is not None:
            # Multi-byte delimiters (e.g. '\r\n') may straddle two
            # chunks in the read buffer, so we can't easily find them
            # without collapsing the buffer.  However, since protocols
            # using delimited reads (as opposed to reads of a known
            # length) tend to be "line" oriented, the delimiter is likely
            # to be in the first few chunks.  Merge the buffer gradually
            # since large merges are relatively expensive and get undone in
            # _consume().
            if self._read_buffer:
                loc = self._read_buffer.find(
                    self._read_delimiter, self._read_buffer_pos
                )
                if loc != -1:
                    loc -= self._read_buffer_pos
                    delimiter_len = len(self._read_delimiter)
                    self._check_max_bytes(self._read_delimiter, loc + delimiter_len)
                    return loc + delimiter_len
                self._check_max_bytes(self._read_delimiter, self._read_buffer_size)
        elif self._read_regex is not None:
            if self._read_buffer:
                m = self._read_regex.search(self._read_buffer, self._read_buffer_pos)
                if m is not None:
                    loc = m.end() - self._read_buffer_pos
                    self._check_max_bytes(self._read_regex, loc)
                    return loc
                self._check_max_bytes(self._read_regex, self._read_buffer_size)
        return None
513733
function check(node) {
    var initial = start(node).offset
    var final = end(node).offset

    if (generated(node)) {
      return null
    }

    return node.lang || /^\s*([~`])\1{2,}/.test(contents.slice(initial, final))
      ? 'fenced'
      : 'indented'
  }
901679
function(content, pos, isBackward) {
			var bounds = this.extractTag(content, pos, isBackward);
			if (!bounds || !bounds.inside(pos))
				// no matching HTML tag or caret outside tag bounds
				return null;
			
			return this.parse(bounds.substring(content), {
				offset: bounds.start
			});
		}
881994
function findBeginningAndEnd(cm, symb, inclusive) {
    var cur = cm.getCursor();
    var line = cm.getLine(cur.line);
    var chars = line.split('');
    var start = undefined;
    var end = undefined;
    var firstIndex = chars.indexOf(symb);

    // the decision tree is to always look backwards for the beginning first,
    // but if the cursor is in front of the first instance of the symb,
    // then move the cursor forward
    if (cur.ch < firstIndex) {
      cur.ch = firstIndex;
      cm.setCursor(cur.line, firstIndex+1);
    }
    // otherwise if the cursor is currently on the closing symbol
    else if (firstIndex < cur.ch && chars[cur.ch] == symb) {
      end = cur.ch; // assign end to the current cursor
      --cur.ch; // make sure to look backwards
    }

    // if we're currently on the symbol, we've got a start
    if (chars[cur.ch] == symb && end == null)
      start = cur.ch + 1; // assign start to ahead of the cursor
    else {
      // go backwards to find the start
      for (var i = cur.ch; i > -1 && start == null; i--)
        if (chars[i] == symb) start = i + 1;
    }

    // look forwards for the end symbol
    if (start != null && end == null) {
      for (var i = start, len = chars.length; i < len && end == null; i++) {
        if (chars[i] == symb) end = i;
      }
    }

    // nothing found
    // FIXME still enters insert mode
    if (start == null || end == null) return {
      start: cur, end: cur  
    };

    // include the symbols
    if (inclusive) {
      --start; ++end;
    }

    return {
      start: {line: cur.line, ch: start},
      end: {line: cur.line, ch: end}
    };
  }
520139
def find_cell_end(self, lines):
        """"""
        if self.metadata is None and lines[0].startswith("#'"):
            self.cell_type = 'markdown'
            for i, line in enumerate(lines):
                if not line.startswith("#'"):
                    if _BLANK_LINE.match(line):
                        return i, i + 1, False
                    return i, i, False

            return len(lines), len(lines), False

        if self.metadata and 'cell_type' in self.metadata:
            self.cell_type = self.metadata.pop('cell_type')
        else:
            self.cell_type = 'code'

        parser = StringParser(self.language or self.default_language)
        for i, line in enumerate(lines):
            # skip cell header
            if self.metadata is not None and i == 0:
                continue

            if parser.is_quoted():
                parser.read_line(line)
                continue

            parser.read_line(line)

            if self.start_code_re.match(line) or (self.markdown_prefix and line.startswith(self.markdown_prefix)):
                if i > 0 and _BLANK_LINE.match(lines[i - 1]):
                    if i > 1 and _BLANK_LINE.match(lines[i - 2]):
                        return i - 2, i, False
                    return i - 1, i, False
                return i, i, False

            if _BLANK_LINE.match(line):
                if not next_code_is_indented(lines[i:]):
                    if i > 0:
                        return i, i + 1, False
                    if len(lines) > 1 and not _BLANK_LINE.match(lines[1]):
                        return 1, 1, False
                    return 1, 2, False

        return len(lines), len(lines), False