NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
|
This class represents a text file in memory (e.g. a code file). This class will try to lex the loaded file and detect simple comment blocks. It defaults to NumeRe code files, however the comment character sequences can be adapted using the reStyle() method. More...
#include <styledtextfile.hpp>
Public Types | |
enum | Style { STYLE_ERROR = -1 , DEFAULT = 0 , COMMENT_LINE , COMMENT_DOC_LINE , BLOCK_START , STRING , COMMENT_BLOCK , COMMENT_DOC_BLOCK } |
Public Member Functions | |
StyledTextFile (const std::string &fileName) | |
StyledTextFile constructor. Will load and lex the specified file using NumeRe code. More... | |
std::string | getFileName () const |
Returns the filename of the respresented file in memory. More... | |
std::string | getTextRange (int pos1, int pos2) const |
This method returns the text between the passed two positions (including possible line termination characters). More... | |
std::string | getLine (size_t line) const |
Returns the selected line (without the line termination characters). More... | |
std::string | getStrippedLine (size_t line) const |
Returns the selected line (without the line termination characters and without any comments). More... | |
int | getLastPosition () const |
Returns the last printable character position in the currently loaded file. More... | |
int | getLinesCount () const |
Returns the number of lines in the current loaded file. More... | |
int | PositionFromLine (size_t line) const |
Returns the position of the first character in the selected line. More... | |
int | LineFromPosition (size_t pos) const |
Returns the line number containing the selected character position. More... | |
int | getLineEndPosition (size_t line) const |
Returns the position of the last printable character in the selected line (before any line termination characters). More... | |
int | getLineStartPosition (size_t line) const |
Returns the position of the first character in the selected line. More... | |
int | findDocStartLine (size_t line) const |
Finds the first line of the current documentation comment or -1, if the current line does not contain any documentation comment. More... | |
Style | getStyleAt (size_t pos) const |
Returns the style at the current selected character position. More... | |
char | getCharAt (size_t pos) const |
Returns the character located at the position pos. More... | |
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 loaded file. More... | |
Private Member Functions | |
void | load () |
This method loads the specified file to memory, while keeping the character positions. More... | |
void | lex () |
This method runs a lexer over the loaded document to obtain styling information. More... | |
Private Attributes | |
std::vector< std::pair< size_t, std::string > > | vFileContents |
std::vector< std::vector< Style > > | vStyles |
std::string | sFileName |
std::string | sCommentLine |
std::string | sDocCommentLine |
std::string | sCommentBlockStart |
std::string | sDocCommentBlockStart |
std::string | sBlockEnd |
std::string | sStringMarks |
bool | useStrings |
This class represents a text file in memory (e.g. a code file). This class will try to lex the loaded file and detect simple comment blocks. It defaults to NumeRe code files, however the comment character sequences can be adapted using the reStyle() method.
The interface resembles the wxStyledTextCtrl interface for simplified portability.
Definition at line 40 of file styledtextfile.hpp.
Enumerator | |
---|---|
STYLE_ERROR | |
DEFAULT | |
COMMENT_LINE | |
COMMENT_DOC_LINE | |
BLOCK_START | |
STRING | |
COMMENT_BLOCK | |
COMMENT_DOC_BLOCK |
Definition at line 43 of file styledtextfile.hpp.
StyledTextFile::StyledTextFile | ( | const std::string & | fileName | ) |
StyledTextFile constructor. Will load and lex the specified file using NumeRe code.
fileName | const std::string& |
Definition at line 174 of file styledtextfile.cpp.
References lex(), load(), sBlockEnd, sCommentBlockStart, sCommentLine, sDocCommentBlockStart, sDocCommentLine, sStringMarks, and useStrings.
int StyledTextFile::findDocStartLine | ( | size_t | line | ) | const |
Finds the first line of the current documentation comment or -1, if the current line does not contain any documentation comment.
line | size_t |
Definition at line 394 of file styledtextfile.cpp.
References COMMENT_DOC_BLOCK, COMMENT_DOC_LINE, getCharAt(), getStyleAt(), LineFromPosition(), and vFileContents.
char StyledTextFile::getCharAt | ( | size_t | pos | ) | const |
Returns the character located at the position pos.
pos | size_t |
Definition at line 447 of file styledtextfile.cpp.
References LineFromPosition(), and vFileContents.
Referenced by findDocStartLine().
std::string StyledTextFile::getFileName | ( | ) | const |
Returns the filename of the respresented file in memory.
Definition at line 196 of file styledtextfile.cpp.
References sFileName.
Referenced by Includer::getIncludedFileName(), DocumentationGenerator::parseDocumentation(), and resolveIncludes().
int StyledTextFile::getLastPosition | ( | ) | const |
Returns the last printable character position in the currently loaded file.
Definition at line 296 of file styledtextfile.cpp.
References getLinesCount(), and vFileContents.
Referenced by DocumentationGenerator::convertToLaTeX(), and Includer::openIncludedFile().
std::string StyledTextFile::getLine | ( | size_t | line | ) | const |
Returns the selected line (without the line termination characters).
line | size_t |
Definition at line 252 of file styledtextfile.cpp.
References vFileContents.
Referenced by readFromFile().
int StyledTextFile::getLineEndPosition | ( | size_t | line | ) | const |
Returns the position of the last printable character in the selected line (before any line termination characters).
line | size_t |
Definition at line 358 of file styledtextfile.cpp.
References vFileContents.
Referenced by DocumentationGenerator::convertToLaTeX().
int StyledTextFile::getLinesCount | ( | ) | const |
Returns the number of lines in the current loaded file.
Definition at line 309 of file styledtextfile.cpp.
References vFileContents.
Referenced by getEventProcedures(), ProcedureLibrary::getFileContents(), getLastPosition(), Includer::getNextLine(), parseLayoutScript(), ProcedureElement::ProcedureElement(), readFromFile(), and resolveIncludes().
int StyledTextFile::getLineStartPosition | ( | size_t | line | ) | const |
Returns the position of the first character in the selected line.
line | size_t |
Definition at line 375 of file styledtextfile.cpp.
References vFileContents.
Referenced by getStyleAt(), and PositionFromLine().
std::string StyledTextFile::getStrippedLine | ( | size_t | line | ) | const |
Returns the selected line (without the line termination characters and without any comments).
line | size_t |
Definition at line 270 of file styledtextfile.cpp.
References DEFAULT, STRING, vFileContents, and vStyles.
Referenced by getEventProcedures(), Includer::getNextLine(), parseLayoutScript(), ProcedureElement::ProcedureElement(), readFromFile(), and resolveIncludes().
StyledTextFile::Style StyledTextFile::getStyleAt | ( | size_t | pos | ) | const |
Returns the style at the current selected character position.
pos | size_t |
Definition at line 428 of file styledtextfile.cpp.
References getLineStartPosition(), LineFromPosition(), STYLE_ERROR, and vStyles.
Referenced by DocumentationGenerator::convertToLaTeX(), and findDocStartLine().
std::string StyledTextFile::getTextRange | ( | int | pos1, |
int | pos2 | ||
) | const |
This method returns the text between the passed two positions (including possible line termination characters).
pos1 | int |
pos2 | int |
Definition at line 212 of file styledtextfile.cpp.
References LineFromPosition(), and vFileContents.
Referenced by DocumentationGenerator::convertToLaTeX(), and DocumentationGenerator::getStrippedRange().
|
private |
This method runs a lexer over the loaded document to obtain styling information.
Definition at line 64 of file styledtextfile.cpp.
References BLOCK_START, COMMENT_BLOCK, COMMENT_DOC_BLOCK, COMMENT_DOC_LINE, COMMENT_LINE, DEFAULT, sBlockEnd, sCommentBlockStart, sCommentLine, sDocCommentBlockStart, sDocCommentLine, sStringMarks, STRING, useStrings, vFileContents, and vStyles.
Referenced by reStyle(), and StyledTextFile().
int StyledTextFile::LineFromPosition | ( | size_t | pos | ) | const |
Returns the line number containing the selected character position.
pos | size_t |
Definition at line 337 of file styledtextfile.cpp.
References vFileContents.
Referenced by DocumentationGenerator::convertToLaTeX(), findDocStartLine(), getCharAt(), getStyleAt(), and getTextRange().
|
private |
This method loads the specified file to memory, while keeping the character positions.
Definition at line 32 of file styledtextfile.cpp.
References sFileName, and vFileContents.
Referenced by StyledTextFile().
int StyledTextFile::PositionFromLine | ( | size_t | line | ) | const |
Returns the position of the first character in the selected line.
line | size_t |
Definition at line 323 of file styledtextfile.cpp.
References getLineStartPosition().
Referenced by DocumentationGenerator::convertToLaTeX().
void StyledTextFile::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 loaded file.
sComLine | const std::string& |
sDocComLine | const std::string& |
sComBlockStart | const std::string& |
sDocComBlockStart | const std::string& |
sComBlockEnd | const std::string& |
sStrMarks | const std::string& |
strings | bool |
Definition at line 473 of file styledtextfile.cpp.
References lex(), sBlockEnd, sCommentBlockStart, sCommentLine, sDocCommentBlockStart, sDocCommentLine, sStringMarks, and useStrings.
Referenced by readFromFile().
|
private |
Definition at line 65 of file styledtextfile.hpp.
Referenced by lex(), reStyle(), and StyledTextFile().
|
private |
Definition at line 63 of file styledtextfile.hpp.
Referenced by lex(), reStyle(), and StyledTextFile().
|
private |
Definition at line 61 of file styledtextfile.hpp.
Referenced by lex(), reStyle(), and StyledTextFile().
|
private |
Definition at line 64 of file styledtextfile.hpp.
Referenced by lex(), reStyle(), and StyledTextFile().
|
private |
Definition at line 62 of file styledtextfile.hpp.
Referenced by lex(), reStyle(), and StyledTextFile().
|
private |
Definition at line 59 of file styledtextfile.hpp.
Referenced by getFileName(), and load().
|
private |
Definition at line 66 of file styledtextfile.hpp.
Referenced by lex(), reStyle(), and StyledTextFile().
|
private |
Definition at line 68 of file styledtextfile.hpp.
Referenced by lex(), reStyle(), and StyledTextFile().
|
private |
Definition at line 56 of file styledtextfile.hpp.
Referenced by findDocStartLine(), getCharAt(), getLastPosition(), getLine(), getLineEndPosition(), getLinesCount(), getLineStartPosition(), getStrippedLine(), getTextRange(), lex(), LineFromPosition(), and load().
|
private |
Definition at line 57 of file styledtextfile.hpp.
Referenced by getStrippedLine(), getStyleAt(), and lex().