summaryrefslogtreecommitdiffstats
path: root/tools/gn/c_include_iterator.h
blob: 2a25ef6f95fa9e13bda9a3df0a8bf13257ff2c37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef TOOLS_GN_C_INCLUDE_ITERATOR_H_
#define TOOLS_GN_C_INCLUDE_ITERATOR_H_

#include "base/basictypes.h"
#include "base/strings/string_piece.h"

// Iterates through #includes in C source and header files.
//
// This only returns includes we want to check, which is user includes with
// double-quotes: #include "..."
class CIncludeIterator {
 public:
  // The buffer pointed to must outlive this class.
  CIncludeIterator(const base::StringPiece& file);
  ~CIncludeIterator();

  // Fills in the string with the contents of the next include and returns
  // true, or returns false if there are no more includes.
  bool GetNextIncludeString(base::StringPiece* out);

  // Maximum numbef of non-includes we'll tolerate before giving up. This does
  // not count comments or preprocessor.
  static const int kMaxNonIncludeLines;

 private:
  // Returns false on EOF, otherwise fills in the given line.
  bool GetNextLine(base::StringPiece* line);

  base::StringPiece file_;

  size_t offset_;

  // Number of lines we've processed since seeing the last include (or the
  // beginning of the file) with some exceptions.
  int lines_since_last_include_;

  DISALLOW_COPY_AND_ASSIGN(CIncludeIterator);
};

#endif  // TOOLS_GN_INCLUDE_ITERATOR_H_