部分函数重构
This commit is contained in:
parent
60073251ab
commit
32e5ea34ed
|
@ -41,37 +41,67 @@ EndProject
|
|||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1EF577E8-D92D-4926-9207-1567137BB672}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{1EF577E8-D92D-4926-9207-1567137BB672}.Debug|x64.Build.0 = Debug|x64
|
||||
{1EF577E8-D92D-4926-9207-1567137BB672}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{1EF577E8-D92D-4926-9207-1567137BB672}.Debug|x86.Build.0 = Debug|x64
|
||||
{1EF577E8-D92D-4926-9207-1567137BB672}.Release|x64.ActiveCfg = Release|x64
|
||||
{1EF577E8-D92D-4926-9207-1567137BB672}.Release|x64.Build.0 = Release|x64
|
||||
{1EF577E8-D92D-4926-9207-1567137BB672}.Release|x86.ActiveCfg = Release|x64
|
||||
{1EF577E8-D92D-4926-9207-1567137BB672}.Release|x86.Build.0 = Release|x64
|
||||
{DAB406C7-174A-47C3-893C-343079396350}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{DAB406C7-174A-47C3-893C-343079396350}.Debug|x64.Build.0 = Debug|x64
|
||||
{DAB406C7-174A-47C3-893C-343079396350}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{DAB406C7-174A-47C3-893C-343079396350}.Debug|x86.Build.0 = Debug|x64
|
||||
{DAB406C7-174A-47C3-893C-343079396350}.Release|x64.ActiveCfg = Release|x64
|
||||
{DAB406C7-174A-47C3-893C-343079396350}.Release|x64.Build.0 = Release|x64
|
||||
{DAB406C7-174A-47C3-893C-343079396350}.Release|x86.ActiveCfg = Release|x64
|
||||
{DAB406C7-174A-47C3-893C-343079396350}.Release|x86.Build.0 = Release|x64
|
||||
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19}.Debug|x64.Build.0 = Debug|x64
|
||||
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19}.Debug|x86.Build.0 = Debug|x64
|
||||
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19}.Release|x64.ActiveCfg = Release|x64
|
||||
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19}.Release|x64.Build.0 = Release|x64
|
||||
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19}.Release|x86.ActiveCfg = Release|x64
|
||||
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19}.Release|x86.Build.0 = Release|x64
|
||||
{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}.Debug|x64.Build.0 = Debug|x64
|
||||
{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}.Debug|x86.Build.0 = Debug|x64
|
||||
{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}.Release|x64.ActiveCfg = Release|x64
|
||||
{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}.Release|x64.Build.0 = Release|x64
|
||||
{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}.Release|x86.ActiveCfg = Release|x64
|
||||
{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}.Release|x86.Build.0 = Release|x64
|
||||
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Debug|x64.Build.0 = Debug|x64
|
||||
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Debug|x86.Build.0 = Debug|x64
|
||||
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Release|x64.ActiveCfg = Release|x64
|
||||
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Release|x64.Build.0 = Release|x64
|
||||
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Release|x86.ActiveCfg = Release|x64
|
||||
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Release|x86.Build.0 = Release|x64
|
||||
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Debug|x64.Build.0 = Debug|x64
|
||||
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Debug|x86.Build.0 = Debug|x64
|
||||
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x64.ActiveCfg = Release|x64
|
||||
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x64.Build.0 = Release|x64
|
||||
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x86.ActiveCfg = Release|x64
|
||||
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x86.Build.0 = Release|x64
|
||||
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x64.Build.0 = Debug|x64
|
||||
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x86.Build.0 = Debug|x64
|
||||
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x64.ActiveCfg = Release|x64
|
||||
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x64.Build.0 = Release|x64
|
||||
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x86.ActiveCfg = Release|x64
|
||||
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x86.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -6,24 +6,25 @@
|
|||
using namespace lib_token;
|
||||
|
||||
std::shared_ptr<const IWordBase> WordReader::wordsFrom(const QString& path) const {
|
||||
auto content_list = extract_from(path);
|
||||
if (!content_list.size())
|
||||
auto primary_words = extract_primary(path);
|
||||
if (!primary_words.size())
|
||||
return nullptr;
|
||||
|
||||
std::shared_ptr<const IWordBase> prev_ptr = std::make_shared<const WordImpl>(content_list.last(), nullptr);
|
||||
for (auto idx = content_list.size() - 2; idx >=0; --idx) {
|
||||
auto content_ptr = content_list[idx];
|
||||
std::shared_ptr<const IWordBase> prev_ptr = std::make_shared<const WordImpl>(primary_words.last(), nullptr);
|
||||
for (auto idx = primary_words.size() - 2; idx >= 0; --idx) {
|
||||
auto content_ptr = primary_words[idx];
|
||||
prev_ptr = std::make_shared<const WordImpl>(content_ptr, prev_ptr);
|
||||
}
|
||||
|
||||
return prev_ptr;
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<const IWordBase>> WordReader::extract_from(const QString& path) const {
|
||||
QList<std::shared_ptr<const IWordBase>> WordReader::extract_primary(const QString& path) const {
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
throw new TokenException(u8"Lex[0x0000]Ö¸¶¨ÎļþÎÞ·¨´ò¿ª£º" + path);
|
||||
}
|
||||
|
||||
QTextStream tin(&file);
|
||||
tin.setCodec("UTF-8");
|
||||
|
||||
|
@ -59,22 +60,32 @@ QList<std::shared_ptr<const IWordBase>> WordReader::parse_line(uint64_t start_po
|
|||
|
||||
TokenException::TokenException(const QString& message) : msg_store(message) { }
|
||||
|
||||
QString TokenException::message() const { return msg_store; }
|
||||
QString TokenException::message() const {
|
||||
return msg_store;
|
||||
}
|
||||
|
||||
WordContent::WordContent(int r, int c, uint64_t pos, const QString& t, const QString& p)
|
||||
: row_n(r), col_n(c), doc_offset(pos), text_n(t), path_p(p) { }
|
||||
|
||||
QString WordContent::file() const { return path_p; }
|
||||
QString WordContent::file() const {
|
||||
return path_p;
|
||||
}
|
||||
|
||||
uint64_t lib_token::WordContent::position() const {
|
||||
return doc_offset;
|
||||
}
|
||||
|
||||
QString WordContent::content() const { return text_n; }
|
||||
QString WordContent::content() const {
|
||||
return text_n;
|
||||
}
|
||||
|
||||
int WordContent::row() const { return row_n; }
|
||||
int WordContent::row() const {
|
||||
return row_n;
|
||||
}
|
||||
|
||||
int WordContent::column() const { return col_n; }
|
||||
int WordContent::column() const {
|
||||
return col_n;
|
||||
}
|
||||
|
||||
std::shared_ptr<const IWordBase> WordContent::nextWord() const {
|
||||
return nullptr;
|
||||
|
@ -83,8 +94,7 @@ std::shared_ptr<const IWordBase> WordContent::nextWord() const {
|
|||
WordImpl::WordImpl(std::shared_ptr<const IWordBase> content, std::shared_ptr<const IWordBase> next)
|
||||
: content_ptr(content), next_ptr(next) { }
|
||||
|
||||
QString WordImpl::file() const
|
||||
{
|
||||
QString WordImpl::file() const {
|
||||
return content_ptr->file();
|
||||
}
|
||||
|
||||
|
@ -92,22 +102,18 @@ uint64_t lib_token::WordImpl::position() const {
|
|||
return content_ptr->position();
|
||||
}
|
||||
|
||||
QString WordImpl::content() const
|
||||
{
|
||||
QString WordImpl::content() const {
|
||||
return content_ptr->content();
|
||||
}
|
||||
|
||||
int WordImpl::row() const
|
||||
{
|
||||
int WordImpl::row() const {
|
||||
return content_ptr->row();
|
||||
}
|
||||
|
||||
int WordImpl::column() const
|
||||
{
|
||||
int WordImpl::column() const {
|
||||
return content_ptr->column();
|
||||
}
|
||||
|
||||
std::shared_ptr<const IWordBase> WordImpl::nextWord() const
|
||||
{
|
||||
std::shared_ptr<const IWordBase> WordImpl::nextWord() const {
|
||||
return next_ptr;
|
||||
}
|
||||
|
|
|
@ -140,14 +140,17 @@ namespace lib_token {
|
|||
|
||||
|
||||
/**
|
||||
* @brief 词法获取器
|
||||
* @brief 源码词语获取器
|
||||
*/
|
||||
class LIBTOKEN_EXPORT WordReader {
|
||||
private:
|
||||
QList<std::shared_ptr<const IWordBase>> parse_line(uint64_t start_pos, int row, const QString& line_text, const QString& path) const;
|
||||
QList<std::shared_ptr<const IWordBase>> extract_from(const QString& path) const;
|
||||
QList<std::shared_ptr<const IWordBase>> extract_primary(const QString& path) const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief 提取源码中所有的词语
|
||||
*/
|
||||
std::shared_ptr<const IWordBase> wordsFrom(const QString &path) const;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue