Resolve the line num of a message in a file
327046
function _resolveLineColNumInFile(file, message, options={}){
    if (!message){
        return {line: 0, col: 0}
    }

    let fileContent = fs.readFileSync(file, 'utf8')

    let beyondPos = 0

    switch (typeof options.after){
        case 'string':
            beyondPos = fileContent.indexOf(options.after)
            break
        case 'number':
            beyondPos = options.after
            break
        default:
            break
    }

    let pos = fileContent.indexOf(message, beyondPos >= 0 ? beyondPos : 0)
    if (pos <= 0){
        return {line: 0, col: 0}
    }

    let lineNum = 1
    let linePos = 0
    for (let i = 0; i < pos; i++){
        if (fileContent.charCodeAt(i) === 10){ // 10: "\n"
            lineNum++
            linePos = i
        }
    }
    
    return {line: lineNum, col: pos - linePos, endCol: pos - linePos + message.length}
}
744619
def get_text_line(self, line_nb):
        """"""
        # Taking into account the case when a file ends in an empty line,
        # since splitlines doesn't return that line as the last element
        # TODO: Make this function more efficient
        try:
            return to_text_string(self.toPlainText()).splitlines()[line_nb]
        except IndexError:
            return self.get_line_separator()
250984
public static void dumpNumberToFile(final Path filePath, final long num) throws IOException {
    try (final BufferedWriter writer = Files
        .newBufferedWriter(filePath, StandardCharsets.UTF_8)) {
      writer.write(String.valueOf(num));
    } catch (final IOException e) {
      log.error("Failed to write the number {} to the file {}", num, filePath, e);
      throw e;
    }
  }
542950
def add_line_numbers(src)
            if src =~ /\A.*, line (\d+)/
                first = $1.to_i - 1
                last  = first + src.count("\n")
                size = last.to_s.length
                real_fmt = "%#{size}d: "
                fmt = " " * (size+2)
                src.gsub!(/^/) do
                    res = sprintf(fmt, first) 
                    first += 1
                    fmt = real_fmt
                    res
                end
            end
        end
1229249
function getInputLine(n) {
    if (n===undefined) n=0;
    var startLine = termText.length-1;
    while (startLine>=0 && !(n==0 && termText[startLine].substr(0,1)==">")) {
      if (termText[startLine].substr(0,1)==">") n--;
      startLine--;
    }
    if (startLine<0) return undefined;
    var line = startLine;
    var text = termText[line++].substr(1);
    while (line < termText.length && termText[line].substr(0,1)==":")
      text += "\n"+termText[line++].substr(1);
    return { line : startLine, text : text };
  }
1139
def count_lines_in(filename):
    ""
    f = open(filename)                  
    lines = 0
    buf_size = 1024 * 1024
    read_f = f.read # loop optimization
    
    buf = read_f(buf_size)
    while buf:
        lines += buf.count('\n')
        buf = read_f(buf_size)
    
    return lines
153249
def p_preprocessor_line_line_file(p):
    
    p.lexer.lineno = int(p[2]) + p.lexer.lineno - p.lineno(3) - 1
    gl.FILENAME = p[3]
989125
def numberify_file(self, filename):
        '''
        '''
        try:
            fd = open(filename, 'r+')
            lines = fd.readlines()
            for i in range(len(lines)):
                if lines[i][0:len(str(i+1))] != str(i+1):
                    lines[i] = str(i+1) + ' ' + lines[i]
                else:
                    print "File already numbered"
                    return False
            fd.seek(0)
            fd.writelines(lines)
            fd.close()
            return True
        except IOError as e:
            print 'I/O error({0}): {1}'.format(e.errno, e.strerror)
        except:
            print 'Unexpected error:', exc_info()[0]
            raise
236789
def nom(txt, off, cset, trim=True):
    '''
    

    '''
    if trim:
        while len(txt) > off and txt[off] in whites:
            off += 1

    r = ''
    while len(txt) > off and txt[off] in cset:
        r += txt[off]
        off += 1

    if trim:
        while len(txt) > off and txt[off] in whites:
            off += 1

    return r, off
699996
def read_end_of_message(self):
        """"""
        read = self._file.read
        last = read(1)
        current = read(1)
        while last != b'' and current != b'' and not \
                (last == b'\r' and current == b'\n'):
            last = current
            current = read(1)
530459
def current_line_num(self):
        '''
        '''
        if self.is_optimized_out():
            return None
        f_trace = self.field('f_trace')
        if long(f_trace) != 0:
            # we have a non-NULL f_trace:
            return self.f_lineno
        else:
            #try:
            return self.co.addr2line(self.f_lasti)
398956
def infer_delimiter(filename, comment_char="#", n_lines=3):
    
    lines = []
    with open(filename, "r") as f:
        for line in f:
            if line.startswith(comment_char):
                continue
            if len(lines) < n_lines:
                lines.append(line)
            else:
                break
    if len(lines) < n_lines:
        raise ValueError(
            "Not enough lines in %s to infer delimiter" % filename)
    candidate_delimiters = ["\t", ",", "\s+"]
    for candidate_delimiter in candidate_delimiters:
        counts = [len(re.split(candidate_delimiter, line)) for line in lines]
        first_line_count = counts[0]
        if all(c == first_line_count for c in counts) and first_line_count > 1:
            return candidate_delimiter
    raise ValueError("Could not determine delimiter for %s" % filename)
784594
def message(self, message, source, point, ln):
        """"""
        if message is None:
            message = "parsing failed"
        if ln is not None:
            message += " (line " + str(ln) + ")"
        if source:
            if point is None:
                message += "\n" + " " * taberrfmt + clean(source)
            else:
                part = clean(source.splitlines()[lineno(point, source) - 1], False).lstrip()
                point -= len(source) - len(part)  # adjust all points based on lstrip
                part = part.rstrip()  # adjust only points that are too large based on rstrip
                message += "\n" + " " * taberrfmt + part
                if point > 0:
                    if point >= len(part):
                        point = len(part) - 1
                    message += "\n" + " " * (taberrfmt + point) + "^"
        return message
1074831
def convert_line(line_num)
      return '' unless @callouts.key? line_num

      @callouts[line_num]
        .map { |num| convert_callout(num) }
        .join(' ')
    end
844281
def count_lines(fname, mode='rU'):
    '''
    '''

    with open(fname, mode) as f:
        for i, l in enumerate(f):
            pass
    return i + 1
628629
def _process_info_message(self, message):
        """"""
        # Extract the output resolution from the appropriate message, if
        # it's present.
        if message['messageCode'] == 'JOB_RUNNING_RESOLUTION':
            self._resolution = message['contents']['resolutionMs']
        elif message['messageCode'] == 'FETCH_NUM_TIMESERIES':
            self._num_input_timeseries += int(message['numInputTimeSeries'])
155788
@Override
	public String getMessage() {
		String ret = super.getMessage();
		if (fileName != null) {
			ret += (" in " + fileName);
			if (lineNumber != -1) {
				ret += " at line number " + lineNumber;
			}

			if (columnNumber != -1) {
				ret += " at column number " + columnNumber;
			}
		}

		return ret;
	}