mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-11-17 07:48:27 +01:00
Little refactoring
This commit is contained in:
parent
3a82ab75fd
commit
fc04b0604b
3 changed files with 31 additions and 18 deletions
|
@ -83,19 +83,6 @@ struct params_7plus1_t
|
||||||
char search_letters[63];
|
char search_letters[63];
|
||||||
};
|
};
|
||||||
|
|
||||||
wdstring convertToDisplay(const Header &iHeader, const wstring &iWord)
|
|
||||||
{
|
|
||||||
wdstring dispStr;
|
|
||||||
dispStr.reserve(iWord.size());
|
|
||||||
for (unsigned int i = 0; i < iWord.size(); ++i)
|
|
||||||
{
|
|
||||||
const wdstring &chr =
|
|
||||||
iHeader.getDisplayStr(iHeader.getCodeFromChar(iWord[i]));
|
|
||||||
dispStr += chr;
|
|
||||||
}
|
|
||||||
return dispStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dictionary::searchWordByLen(struct params_7plus1_t ¶ms,
|
void Dictionary::searchWordByLen(struct params_7plus1_t ¶ms,
|
||||||
int i, const DicEdge *edgeptr) const
|
int i, const DicEdge *edgeptr) const
|
||||||
{
|
{
|
||||||
|
@ -117,7 +104,7 @@ void Dictionary::searchWordByLen(struct params_7plus1_t ¶ms,
|
||||||
// Add the solution
|
// Add the solution
|
||||||
vector<wdstring> &sols = (*params.results)[params.added_display];
|
vector<wdstring> &sols = (*params.results)[params.added_display];
|
||||||
if (sols.empty() || sols.back() != params.search_wordtst)
|
if (sols.empty() || sols.back() != params.search_wordtst)
|
||||||
sols.push_back(convertToDisplay(getHeader(), params.search_wordtst));
|
sols.push_back(getHeader().convertToDisplay(params.search_wordtst));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -140,7 +127,7 @@ void Dictionary::searchWordByLen(struct params_7plus1_t ¶ms,
|
||||||
// Add the solution
|
// Add the solution
|
||||||
vector<wdstring> &sols = (*params.results)[params.added_display];
|
vector<wdstring> &sols = (*params.results)[params.added_display];
|
||||||
if (sols.empty() || sols.back() != params.search_wordtst)
|
if (sols.empty() || sols.back() != params.search_wordtst)
|
||||||
sols.push_back(convertToDisplay(getHeader(), params.search_wordtst));
|
sols.push_back(getHeader().convertToDisplay(params.search_wordtst));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -243,7 +230,7 @@ void Dictionary::searchRacc(const wstring &iWord,
|
||||||
oWordList.reserve(DEFAULT_VECT_ALLOC);
|
oWordList.reserve(DEFAULT_VECT_ALLOC);
|
||||||
|
|
||||||
// Transform the given word to make it suitable for display
|
// Transform the given word to make it suitable for display
|
||||||
const wdstring &displayWord = convertToDisplay(getHeader(), iWord);
|
const wdstring &displayWord = getHeader().convertToDisplay(iWord);
|
||||||
|
|
||||||
// Try to add a letter at the front
|
// Try to add a letter at the front
|
||||||
const wstring &letters = getHeader().getLetters();
|
const wstring &letters = getHeader().getLetters();
|
||||||
|
@ -296,7 +283,7 @@ void Dictionary::searchBenj(const wstring &iWord, vector<wdstring> &oWordList,
|
||||||
oWordList.reserve(DEFAULT_VECT_ALLOC);
|
oWordList.reserve(DEFAULT_VECT_ALLOC);
|
||||||
|
|
||||||
// Transform the given word to make it suitable for display
|
// Transform the given word to make it suitable for display
|
||||||
const wdstring &displayWord = convertToDisplay(getHeader(), iWord);
|
const wdstring &displayWord = getHeader().convertToDisplay(iWord);
|
||||||
|
|
||||||
const DicEdge *edge0, *edge1, *edge2, *edgetst;
|
const DicEdge *edge0, *edge1, *edge2, *edgetst;
|
||||||
edge0 = getEdgeAt(getRoot());
|
edge0 = getEdgeAt(getRoot());
|
||||||
|
|
|
@ -273,6 +273,23 @@ wstring Header::getDisplayStr(unsigned int iCode) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wdstring Header::convertToDisplay(const wstring &iWord) const
|
||||||
|
{
|
||||||
|
// TODO: if we had a flag saying that the current dictionary is
|
||||||
|
// such that all the display strings are equal to the internal
|
||||||
|
// characters themselves (which would be the case for most languages),
|
||||||
|
// we could simply return the given string without further processing.
|
||||||
|
wdstring dispStr;
|
||||||
|
dispStr.reserve(iWord.size());
|
||||||
|
for (unsigned int i = 0; i < iWord.size(); ++i)
|
||||||
|
{
|
||||||
|
const wdstring &chr = getDisplayStr(getCodeFromChar(iWord[i]));
|
||||||
|
dispStr += chr;
|
||||||
|
}
|
||||||
|
return dispStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Header::read(istream &iStream)
|
void Header::read(istream &iStream)
|
||||||
{
|
{
|
||||||
Dict_header_old aHeader;
|
Dict_header_old aHeader;
|
||||||
|
|
11
dic/header.h
11
dic/header.h
|
@ -28,6 +28,9 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// XXX: duplicated typedef (also present in dic.h)
|
||||||
|
typedef wstring wdstring;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structure used to create a Header object.
|
* Structure used to create a Header object.
|
||||||
|
@ -122,10 +125,16 @@ public:
|
||||||
unsigned int getCodeFromChar(wchar_t iChar) const;
|
unsigned int getCodeFromChar(wchar_t iChar) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the display stirng corresponding to the given code
|
* Return the display string corresponding to the given code
|
||||||
*/
|
*/
|
||||||
wstring getDisplayStr(unsigned int iCode) const;
|
wstring getDisplayStr(unsigned int iCode) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the given string (made of internal characters)
|
||||||
|
* into a string suitable for display
|
||||||
|
*/
|
||||||
|
wdstring convertToDisplay(const wstring &iWord) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print a readable summary of the header on standard output
|
* Print a readable summary of the header on standard output
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue