~ubuntu-branches/ubuntu/maverick/codelite/maverick

« back to all changes in this revision

Viewing changes to CodeLite/comment_parser.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-07-29 19:42:47 UTC
  • mfrom: (1.1.9 upstream) (18.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100729194247-cuibfk03wog33nxq
Tags: 2.6.0.4189~dfsg-1
* New upstream release.
* Bump Standards.
* Refresh patches.
* Add license information about files under ./Debugger/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef INCLUDE_FINDER_H
 
2
#define INCLUDE_FINDER_H
 
3
 
 
4
#include <map>
 
5
#include <string>
 
6
 
 
7
class CommentParseResult {
 
8
private:
 
9
        std::map<size_t, std::string> m_comments;
 
10
        std::string                   m_filename;
 
11
        
 
12
public:
 
13
        void addComment(const std::string& comment, size_t line, bool cppComment)
 
14
        {
 
15
                // try to group this comment with the one above it
 
16
                std::string cmt = comment;
 
17
                if(cppComment && line) {
 
18
                        size_t prevLine = line - 1;
 
19
                        std::map<size_t, std::string>::iterator iter = m_comments.find(prevLine);
 
20
                        if(iter != m_comments.end()) {
 
21
                                cmt =  iter->second;
 
22
                                cmt += "\n";
 
23
                                cmt += comment;
 
24
                                
 
25
                                // remove the previous comment from the map
 
26
                                m_comments.erase(iter);
 
27
                        }
 
28
                }
 
29
                m_comments[line] = cmt;
 
30
        }
 
31
        
 
32
        std::string getCommentForLine(size_t line) const
 
33
        {
 
34
                std::map<size_t, std::string>::const_iterator iter = m_comments.find(line);
 
35
                if(iter == m_comments.end())
 
36
                        return "";
 
37
                return iter->second;
 
38
        }
 
39
        
 
40
        void print()
 
41
        {
 
42
                std::map<size_t, std::string>::const_iterator iter = m_comments.begin();
 
43
                for(; iter != m_comments.end(); iter++) {
 
44
                        printf("Line   : %d\n", iter->first);
 
45
                        printf("Comment:\n%s\n", iter->second.c_str());
 
46
                }
 
47
        }
 
48
        
 
49
        void setFilename(const std::string& filename)
 
50
        {
 
51
                m_filename = filename;
 
52
        }
 
53
        
 
54
        const std::string& getFilename() const
 
55
        {
 
56
                return m_filename;
 
57
        }
 
58
        
 
59
        void clear()
 
60
        {
 
61
                m_comments.clear();
 
62
                m_filename.clear();
 
63
        }
 
64
};
 
65
 
 
66
extern int ParseComments(const char* filePath, CommentParseResult &comments);
 
67
 
 
68
#endif