-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to latest commit, change warning into error, add Digital Asset…
…s Link info
- Loading branch information
1 parent
5790a36
commit 997a6e0
Showing
6 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "coloredstring.h" | ||
|
||
QMap<QString, QString> ColoredString::map = QMap<QString, QString>({ | ||
{"green", "32"} | ||
}); | ||
|
||
ColoredString::ColoredString(const QString text) | ||
{ | ||
m_text = text; | ||
} | ||
|
||
QString ColoredString::toString() const | ||
{ | ||
enum Mode { // todo come up with better names | ||
String, | ||
Tag, | ||
TagString, | ||
TagTag | ||
}; | ||
QString out; | ||
|
||
auto mode = Mode::String; | ||
QString currentTag; | ||
|
||
for (int i = 0; i < m_text.length(); ++i) { | ||
auto letter = m_text.at(i); | ||
switch (mode) { | ||
case String: | ||
if (letter == "<") { | ||
mode = Tag; | ||
continue; | ||
} | ||
out += letter; | ||
break; | ||
case Tag: | ||
if (letter == ">") { | ||
if (!map.contains(currentTag)) { | ||
mode = String; | ||
continue; | ||
} | ||
out += "\033[0;" + map.value(currentTag) + "m"; | ||
mode = TagString; | ||
} else { | ||
currentTag += letter; | ||
} | ||
break; | ||
case TagString: | ||
if (letter == "<") { | ||
mode = TagTag; | ||
continue; | ||
} | ||
out += letter; | ||
break; | ||
case TagTag: | ||
if (letter != ">") { | ||
continue; | ||
} | ||
out += "\033[0m"; | ||
currentTag = ""; | ||
mode = String; | ||
break; | ||
} | ||
} | ||
|
||
return out; | ||
} | ||
|
||
ColoredString::operator QString() const | ||
{ | ||
return toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef COLOREDSTRING_H | ||
#define COLOREDSTRING_H | ||
|
||
#include <QString> | ||
#include <QMap> | ||
|
||
class ColoredString | ||
{ | ||
public: | ||
explicit ColoredString(const QString text); | ||
QString toString() const; | ||
|
||
operator QString() const; | ||
|
||
private: | ||
QString m_text; | ||
static QMap<QString, QString> map; | ||
}; | ||
|
||
#endif // COLOREDSTRING_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters