Skip to content
Snippets Groups Projects
Commit 6c03c4c3 authored by Franck Dary's avatar Franck Dary
Browse files

Added some gettters

parent 5b2017a1
Branches
No related tags found
No related merge requests found
...@@ -42,6 +42,10 @@ std::string int2HumanStr(int number); ...@@ -42,6 +42,10 @@ std::string int2HumanStr(int number);
int printedLength(std::string_view s); int printedLength(std::string_view s);
bool isSeparator(utf8char c);
bool isIllegal(utf8char c);
template <typename T> template <typename T>
bool isEmpty(const std::vector<T> & s) bool isEmpty(const std::vector<T> & s)
{ {
......
...@@ -25,6 +25,16 @@ std::string_view getFilenameFromPath(std::string_view s) ...@@ -25,6 +25,16 @@ std::string_view getFilenameFromPath(std::string_view s)
return {s.data()+indexOfSlash+1, s.size()-1-indexOfSlash}; return {s.data()+indexOfSlash+1, s.size()-1-indexOfSlash};
} }
bool isSeparator(utf8char c)
{
return c == ' ' || isIllegal(c);
}
bool isIllegal(utf8char c)
{
return c == '\n' || c == '\t';
}
std::vector<std::string_view> split(std::string_view remaining, char delimiter) std::vector<std::string_view> split(std::string_view remaining, char delimiter)
{ {
std::vector<std::string_view> result; std::vector<std::string_view> result;
......
...@@ -12,6 +12,7 @@ int main(int argc, char * argv[]) ...@@ -12,6 +12,7 @@ int main(int argc, char * argv[])
BaseConfig goldConfig(argv[3], argv[1], argv[2]); BaseConfig goldConfig(argv[3], argv[1], argv[2]);
SubConfig config(goldConfig); SubConfig config(goldConfig);
auto other = config;
while (config.moveWordIndex(1)) while (config.moveWordIndex(1))
{ {
......
...@@ -20,7 +20,7 @@ class Config ...@@ -20,7 +20,7 @@ class Config
public : public :
using String = boost::flyweight<std::string>; using String = boost::flyweight<std::string>;
using Utf8String = boost::flyweight<util::utf8string>; using Utf8String = util::utf8string;
using ValueIterator = std::vector<String>::iterator; using ValueIterator = std::vector<String>::iterator;
using ConstValueIterator = std::vector<String>::const_iterator; using ConstValueIterator = std::vector<String>::const_iterator;
...@@ -72,7 +72,7 @@ class Config ...@@ -72,7 +72,7 @@ class Config
const String & getConst(const std::string & colName, int lineIndex, int hypothesisIndex) const; const String & getConst(const std::string & colName, int lineIndex, int hypothesisIndex) const;
String & getLastNotEmpty(const std::string & colName, int lineIndex); String & getLastNotEmpty(const std::string & colName, int lineIndex);
const String & getLastNotEmptyConst(const std::string & colName, int lineIndex) const; const String & getLastNotEmptyConst(const std::string & colName, int lineIndex) const;
bool hasLetter(int letterIndex) const; bool hasCharacter(int letterIndex) const;
util::utf8char getLetter(int letterIndex) const; util::utf8char getLetter(int letterIndex) const;
void addToHistory(const std::string & transition); void addToHistory(const std::string & transition);
void addToStack(std::size_t index); void addToStack(std::size_t index);
...@@ -81,6 +81,13 @@ class Config ...@@ -81,6 +81,13 @@ class Config
bool isEmptyNode(std::size_t lineIndex) const; bool isEmptyNode(std::size_t lineIndex) const;
bool isToken(std::size_t lineIndex) const; bool isToken(std::size_t lineIndex) const;
bool moveWordIndex(int relativeMovement); bool moveWordIndex(int relativeMovement);
bool moveCharacterIndex(int relativeMovement);
bool rawInputOnlySeparatorsLeft() const;
std::size_t getWordIndex() const;
std::size_t getCharacterIndex() const;
const String & getHistory(int relativeIndex) const;
bool hasHistory(int relativeIndex) const;
}; };
#endif #endif
...@@ -207,14 +207,14 @@ void Config::addToStack(std::size_t index) ...@@ -207,14 +207,14 @@ void Config::addToStack(std::size_t index)
stack.push_back(index); stack.push_back(index);
} }
bool Config::hasLetter(int letterIndex) const bool Config::hasCharacter(int letterIndex) const
{ {
return letterIndex >= 0 and letterIndex < (int)util::getSize(rawInput); return letterIndex >= 0 and letterIndex < (int)util::getSize(rawInput);
} }
util::utf8char Config::getLetter(int letterIndex) const util::utf8char Config::getLetter(int letterIndex) const
{ {
return rawInput.get()[letterIndex]; return rawInput[letterIndex];
} }
bool Config::isComment(std::size_t lineIndex) const bool Config::isComment(std::size_t lineIndex) const
...@@ -260,3 +260,48 @@ bool Config::moveWordIndex(int relativeMovement) ...@@ -260,3 +260,48 @@ bool Config::moveWordIndex(int relativeMovement)
return true; return true;
} }
bool Config::moveCharacterIndex(int relativeMovement)
{
for (int i = 0; i < relativeMovement; i++)
{
int oldVal = characterIndex;
relativeMovement > 0 ? characterIndex++ : characterIndex--;
if (!hasCharacter(characterIndex))
{
characterIndex = oldVal;
return false;
}
}
return true;
}
bool Config::rawInputOnlySeparatorsLeft() const
{
for (unsigned int i = characterIndex; i < rawInput.size(); i++)
if (!util::isSeparator(rawInput[i]))
return false;
return true;
}
std::size_t Config::getWordIndex() const
{
return wordIndex;
}
std::size_t Config::getCharacterIndex() const
{
return characterIndex;
}
const Config::String & Config::getHistory(int relativeIndex) const
{
return history[history.size()-1-relativeIndex];
}
bool Config::hasHistory(int relativeIndex) const
{
return relativeIndex > 0 && relativeIndex < (int)history.size();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment