22#include "../version.h"
23#include "../utils/tools.hpp"
24#include "../../kernel.hpp"
41 while (sLine.find(
"<!--") != std::string::npos)
43 if (sLine.find(
"-->", sLine.find(
"<!--")+4) != std::string::npos)
44 sLine.erase(sLine.find(
"<!--"), sLine.find(
"-->", sLine.find(
"<!--")+4)+3 - sLine.find(
"<!--"));
47 sLine.erase(sLine.find(
"<!--"));
48 std::string sLineTemp =
"";
50 while (!fDocument.eof())
52 std::getline(fDocument, sLineTemp);
55 if (!sLineTemp.length())
58 if (sLineTemp.find(
"-->") != std::string::npos)
60 sLine += sLineTemp.substr(sLineTemp.find(
"-->")+3);
79static void findArticleById(std::string& sLine,
const std::string& sArticleID, std::ifstream& fDocument)
81 while (sLine.find(
"<article ") != std::string::npos && !fDocument.eof())
86 while (!fDocument.eof())
88 std::getline(fDocument, sLine);
92 if (sLine.find(
"<!--") != std::string::npos)
99 if (sLine.find(
"<article") != std::string::npos)
105 sLine.erase(0, sLine.find(
'>', sLine.find(
"<article "))+1);
124 std::ifstream fDocument;
125 fDocument.open(sFileName.c_str(), std::ios_base::in);
127 if (fDocument.fail())
134 std::vector<std::string> vReturn;
136 while (!fDocument.eof())
138 std::getline(fDocument, sLine);
142 if (sLine.find(
"<!--") != std::string::npos)
149 if (sLine.find(
"<article ") != std::string::npos)
155 vReturn.push_back(
"NO_ENTRY_FOUND");
164 if (sLine.find(
"<title ") != std::string::npos)
166 vReturn.push_back(
getArgAtPos(sLine, sLine.find(
"string=", sLine.find(
"<title "))+7));
167 sLine.erase(0, sLine.find(
"/>", sLine.find(
"<title "))+2);
175 if (sLine.find(
"<contents>") != std::string::npos)
177 sLine.erase(0, sLine.find(
"<contents>")+10);
180 vReturn.push_back(sLine);
182 while (!fDocument.eof())
184 std::getline(fDocument, sLine);
190 if (sLine.find(
"<!--") != std::string::npos)
193 if (sLine.find(
"</contents>") != std::string::npos)
195 sLine.erase(sLine.find(
"</contents>"));
198 vReturn.push_back(sLine);
203 vReturn.push_back(sLine);
211 vReturn.push_back(
"NO_ENTRY_FOUND");
263 for (
const std::string& key : keys)
271 for (
const std::string& key : keys)
277 for (
const std::string& kw : keyWords)
298 for (
int i = sTopic.length(); i > 0; i--)
305 for (; iter != secondIndex; ++iter)
307 if (iter->first[0] < sTopic[0])
313 if (iter->first[0] > sTopic[0])
319 if (iter->first == sTopic.substr(0,i))
321 nIndex = iter->second;
352 std::map<int,size_t> keyCount;
353 for (
const std::string& key : keys)
364 auto el = std::max_element(keyCount.begin(), keyCount.end(),
365 [](
const pair<int,size_t>& p1,
const pair<int,size_t>& p2) { return p1.second < p2.second; });
384 std::string sArgument =
"";
388 if (nPos >= sCmd.length())
392 while (nPos < sCmd.length() && sCmd[nPos] ==
' ')
396 if (nPos >= sCmd.length())
401 if (sCmd[nPos] ==
'"')
406 for (
unsigned int i = nPos + 1; i < sCmd.length(); i++)
408 if (sCmd[i] ==
'"' && sCmd[i - 1] !=
'\\')
410 sArgument = sCmd.substr(nPos+1, i - nPos - 1);
419 for (
unsigned int i = nPos; i < sCmd.length(); i++)
422 if (sCmd[i] ==
'(' || sCmd[i] ==
'[' || sCmd[i] ==
'{')
428 sArgument = sCmd.substr(nPos, i - nPos);
436 if (!sArgument.length())
438 sArgument = sCmd.substr(nPos);
463 for (
const std::string& file : vFiles)
471 for (
const std::string& file : vFiles)
476 if (!bLoadUserLangFiles)
482 for (
const std::string& file : vFiles)
500 if (!sFileName.length())
511 if (article.m_keywords.size())
512 addEntry(article.m_docEntry, article.m_keywords);
536 if (_sID ==
"<<NO_HLP_ENTRY>>")
549 if (iter->second == (
int)i)
555 else if (iter->second > (
int)i)
583 std::vector<std::string> vReturn;
590 if (sTopic !=
"idx" && sTopic !=
"index")
597 if (
vDocIndexTable[nIndex].sDocFilePath.find(
"<>") != std::string::npos)
603 vReturn.push_back(
"NO_ENTRY_FOUND");
608 vReturn.push_back(
"Index");
609 std::map<std::string,std::string> mIdx;
615 for (
const std::string& key : keylist)
621 vReturn.push_back(
_lang.
get(
"DOCHELPER_KEYWORDS_AND_ARTICLES")+
":");
622 vReturn.push_back(
"<list>");
624 for (
auto iter = mIdx.begin(); iter != mIdx.end(); ++iter)
626 vReturn.push_back(
"<item node=\"" + iter->first +
"\">" + iter->second +
"</item>");
629 vReturn.push_back(
"</list>");
648 std::vector<std::string> vReturn;
654 std::string sKeyWords;
659 if (iter.second == (
int)i)
660 sKeyWords +=
" " + iter.first;
665 for (
const std::string& key : keylist)
668 if (std::find(vReturn.begin(), vReturn.end(), key+sKeyWords) == vReturn.end())
669 vReturn.push_back(key+sKeyWords);
673 std::sort(vReturn.begin(), vReturn.end());
690 std::string sReturn =
"";
697 if (sReturn.find(
',') != std::string::npos)
698 sReturn.erase(sReturn.find(
','));
719 return "NO_ENTRY_FOUND";
This class represents a whole documentation file with its contained documentation articles.
std::vector< DocumentationArticle > & getArticles()
Get all articles present in the current documentation file.
~Documentation()
The destructor closes the internal file stream, if it is still open.
void addFileToDocumentationIndex(const std::string &sFileName)
This member function is used to add documentation index entries to the index during a plugin or packa...
std::string getHelpArticleID(const std::string &sTopic)
This member function returns the article ID corresponding to the queried topic.
std::vector< DocumentationEntry > vDocIndexTable
std::string getHelpIdxKey(const std::string &sTopic)
This member function returns an index key, which corresponds to the queried topic.
void removeFromDocIndex(const std::string &_sID)
This member function removes the index entry passed to the function from the documentation index.
std::vector< std::string > getHelpArticle(const std::string &sTopic)
This member function returns the documentation article, which corresponds to the passed documentation...
void createDocumentationIndex(bool bLoadUserLangFiles=true)
This member function loads the index files to memory.
void addEntry(const DocumentationEntry &entry, const std::vector< std::string > &keyWords)
Add a new entry to the documentation index respecting already existing versions of the new entry....
std::vector< std::string > getDocIndex() const
This member function returns the key list for the documentation index prepared for the corresponding ...
int findPositionUsingIdxKeys(const std::string &sIdxKeys) const
Finds the best match of a documentation entry using a list of index keys. If multiple matches have be...
std::string getHelpArticleTitle(const std::string &_sIdxKey)
This member function returns the documentation article title corresponding to the queried index key.
Documentation()
The default constructor.
static std::string getArgAtPos(const std::string &sCmd, unsigned int pos)
This static member is a fallback for the XML-parsing logic-stuff.
std::map< std::string, int > mDocumentationIndex
int findPositionInDocumentationIndex(const std::string &sTopic) const
This private member function returns the position of the queried topic in the documentation index tab...
This class extends the std::vector for endlessness.
This class implements the basic input/ output file system and provides functionalities to work with f...
std::string ValidFolderName(std::string _sFileName, bool doCleanPath=true, bool appendTrailingSeparator=true) const
This member function evaluates, whether the passed foldername is a valid foldername.
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
This class manages the setting values of the internal (kernel) settings of this application.
Common exception class for all exceptions thrown in NumeRe.
static size_t invalid_position
static void stripComments(std::string &sLine, std::ifstream &fDocument)
Strips comments from the documentation article file.
static std::vector< std::string > loadDocumentationArticle(const std::string &sFileName, const std::string &sArticleID)
This static function loads and prepares the selected documentation article.
static void findArticleById(std::string &sLine, const std::string &sArticleID, std::ifstream &fDocument)
Searches an article in a file by the selected ID.
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
This structure defines a single article in a documentation file.
This structure defines a single entry in the documentation index.
std::string toString(int)
Converts an integer to a string without the Settings bloat.