NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
styledtextfile.hpp
Go to the documentation of this file.
1
2/*****************************************************************************
3 NumeRe: Framework fuer Numerische Rechnungen
4 Copyright (C) 2020 Erik Haenel et al.
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18******************************************************************************/
19
20
21#ifndef STYLEDTEXTFILE_HPP
22#define STYLEDTEXTFILE_HPP
23
24#include <string>
25#include <vector>
26#include <utility>
27
41{
42 public:
43 enum Style
44 {
53 };
54
55 private:
56 std::vector<std::pair<size_t, std::string>> vFileContents;
57 std::vector<std::vector<Style>> vStyles;
58
59 std::string sFileName;
60
61 std::string sCommentLine;
62 std::string sDocCommentLine;
63 std::string sCommentBlockStart;
65 std::string sBlockEnd;
66 std::string sStringMarks;
67
69
70 void load();
71 void lex();
72
73 public:
74 StyledTextFile(const std::string& fileName);
75
76 std::string getFileName() const;
77
78 std::string getTextRange(int pos1, int pos2) const;
79 std::string getLine(size_t line) const;
80 std::string getStrippedLine(size_t line) const;
81 int getLastPosition() const;
82 int getLinesCount() const;
83 int PositionFromLine(size_t line) const;
84 int LineFromPosition(size_t pos) const;
85 int getLineEndPosition(size_t line) const;
86 int getLineStartPosition(size_t line) const;
87 int findDocStartLine(size_t line) const;
88
89 Style getStyleAt(size_t pos) const;
90 char getCharAt(size_t pos) const;
91
92 void reStyle(const std::string& sComLine,
93 const std::string& sDocComLine,
94 const std::string& sComBlockStart,
95 const std::string& sDocComBlockStart,
96 const std::string& sComBlockEnd,
97 const std::string& sStrMarks = "",
98 bool strings = true);
99};
100
101#endif // STYLEDTEXTFILE_HPP
102
103
This class represents a text file in memory (e.g. a code file). This class will try to lex the loaded...
int getLastPosition() const
Returns the last printable character position in the currently loaded file.
std::string sCommentLine
std::vector< std::pair< size_t, std::string > > vFileContents
std::string getStrippedLine(size_t line) const
Returns the selected line (without the line termination characters and without any comments).
int getLineStartPosition(size_t line) const
Returns the position of the first character in the selected line.
void lex()
This method runs a lexer over the loaded document to obtain styling information.
StyledTextFile(const std::string &fileName)
StyledTextFile constructor. Will load and lex the specified file using NumeRe code.
int LineFromPosition(size_t pos) const
Returns the line number containing the selected character position.
std::string getTextRange(int pos1, int pos2) const
This method returns the text between the passed two positions (including possible line termination ch...
std::string sBlockEnd
std::string sFileName
std::string sCommentBlockStart
std::string sDocCommentLine
int getLineEndPosition(size_t line) const
Returns the position of the last printable character in the selected line (before any line terminatio...
int PositionFromLine(size_t line) const
Returns the position of the first character in the selected line.
Style getStyleAt(size_t pos) const
Returns the style at the current selected character position.
std::string sDocCommentBlockStart
int findDocStartLine(size_t line) const
Finds the first line of the current documentation comment or -1, if the current line does not contain...
void reStyle(const std::string &sComLine, const std::string &sDocComLine, const std::string &sComBlockStart, const std::string &sDocComBlockStart, const std::string &sComBlockEnd, const std::string &sStrMarks="", bool strings=true)
Can be used to change the code style detection sequences and to re-apply the lexer to the currently l...
void load()
This method loads the specified file to memory, while keeping the character positions.
int getLinesCount() const
Returns the number of lines in the current loaded file.
std::vector< std::vector< Style > > vStyles
std::string sStringMarks
std::string getLine(size_t line) const
Returns the selected line (without the line termination characters).
std::string getFileName() const
Returns the filename of the respresented file in memory.
char getCharAt(size_t pos) const
Returns the character located at the position pos.