diff --git a/README.md b/README.md index 546e7f4..7e9edb9 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,9 @@ Available through the following package managers: ### Flatpak - Official Seer versions from Flathub (coming soon!) +Official Seer versions from Flathub (coming soon!) - Alpha Seer versions. [Seer's release page](https://github.com/epasveer/seer/releases/tag/flatpak-latest) on github. +Alpha Seer versions. [Seer's release page](https://github.com/epasveer/seer/releases/tag/flatpak-latest) on github. Install from source diff --git a/tests/hellorecursive/Makefile b/tests/hellorecursive/Makefile new file mode 100644 index 0000000..e140cc8 --- /dev/null +++ b/tests/hellorecursive/Makefile @@ -0,0 +1,10 @@ +.PHONY: all +all: hellorecursive + +hellorecursive: hellorecursive.cpp + g++ -std=c++17 -g -I/usr/include/qt6 -o hellorecursive hellorecursive.cpp -L/usr/lib64 -lQt6Widgets -lQt6Core + +.PHONY: clean +clean: + rm -f hellorecursive hellorecursive.o + diff --git a/tests/hellorecursive/hellorecursive b/tests/hellorecursive/hellorecursive new file mode 100755 index 0000000..fccc7fd Binary files /dev/null and b/tests/hellorecursive/hellorecursive differ diff --git a/tests/hellorecursive/hellorecursive.cpp b/tests/hellorecursive/hellorecursive.cpp new file mode 100644 index 0000000..0f45ca9 --- /dev/null +++ b/tests/hellorecursive/hellorecursive.cpp @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include +#include +#include + +QStringList parseCommaList (const QString& str, QChar startBracket, QChar endBracket) { + + // name = "Pasveer, Ernie", age = 60, salary = 0.25, location = {city = "Houston", state = "Texas", zip = 77063} + // + // name = "Pasveer, Ernie" + // age = 60 + // salary = 0.25 + // location = {city = "Houston", state = "Texas", zip = 77063} + // + // special case: garbage value: + // {id = 2, b = \"000hildTest 2000377177000000260324377377377177\", '000' , \"hildTest 2000-", '0' , "1", '0' , "330324377377377177000000004", '0' , "test\", '000' , \"325377377\", child = {childId = -9864, childString = \"\"}} + + enum STATE{ + START = 0, + SCANNING = 1, + FOUND = 2, + IGNORE = 3, + }; + + QStringList list; + int index = 0; + int start = 0; + int end = 0; + int previousComma= 0; + STATE state = START; + + while (index < str.length()) { + + // Handle "=" + if (str[index] == '=') { + if (state == SCANNING) // looking for 2nd '=' + { + // state = FOUND; + end = previousComma; + QString field = str.mid(start, end-start); + list.append(field.trimmed()); + start = previousComma + 1; + } + if (state == START) // looking for 2nd '=' + { + state = SCANNING; + + } + } + + if (str[index] == startBracket) + { + state = IGNORE; + } + + if (str[index] == endBracket) + { + state = SCANNING; + } + + if (str[index] == ',' && state != IGNORE) { + previousComma = index; + } + + // The last + if (index == str.length() - 1) + { + QString field = str.mid(start, index); + list.append(field.trimmed()); + } + index++; + } + return list; +} + +void readLinesFromFile(const QString &filePath) { + + QFile file(filePath); + + // Open file in read-only mode + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug() << "Cannot open file:" << file.errorString(); + return; + } + + QTextStream in(&file); + + // Read line by line + while (!in.atEnd()) { + qDebug() << "========================================================================================================\n"; + + QStringList list; + QString line = in.readLine(); + qDebug() << "New string: " << line << "\n"; + list = parseCommaList(line, '{', '}'); + qDebug() << "Output: " << list; + } + + file.close(); +} + +int main(int argc, char *argv[]) { + + QApplication app(argc, argv); + + // "/home/quangnm/Desktop/testcase.txt" + // "C:/path/to/file.txt" + + readLinesFromFile(argv[1]); + + return app.exec(); +} + diff --git a/tests/hellorecursive/testcase.txt b/tests/hellorecursive/testcase.txt new file mode 100644 index 0000000..24a55ad --- /dev/null +++ b/tests/hellorecursive/testcase.txt @@ -0,0 +1,12 @@ +id = 2, b = \\\"\\\\000hildTest 2\\\\000\\\\377\\\\177\\\\000\\\\000P\\\\327\\\\377\\\\377\\\\377\\\\177\\\", '\\\\000' , \\\"hildTest 2\\\\000\\\\377\\\\177\\\\000\\\\000\\\\001\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000x\\\\327\\\\377\\\\377\\\\377\\\\177\\\\000\\\\000\\\\004\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000test\\\", '\\\\000' , \\\"\\\\240\\\\327\\\\377\\\\377\\\", child = {childId = -9864, childString = \\\"\\\"} +id = 2, b = \"000hildTest 2000377177000000P327377377377177\", '000' , \"hildTest 2000377177000000001", '0' , "x327377377377177000000004", '0' , "test\", '000' , \"240327377377\", child = {childId = -9864, childString = \"\"} +id = -2, b = \"test\", child = {childId = -1, childString = \"childTest\"} +id = 2, b = \"000hildTest 2000377177000000P327377377377177\", '000' , \"hildTest 2000377177000000001", '0' , "x327377377377177000000004", '0' , "test\", '000' , \"240327377377\", child = {childId = -9864, childString = \"\"} +child = {childId = -9864, childString = \"\"}, child = {childId = -9864, childString = \"\"} +id = 1431674881, b = \"\", child = {childId = 1431667073, childString = \"\"} +id = -2, b = \\\"test\\\", child = {childId = -1, childString = \\\"childTest\\\"} +id = -2, b = \"test\", child = {childId = -1, childString = \"childTest\"} +id = 1431674881, b = \"\", child = {childId = 1431667073, childString = \"\"} +childId = -1, childString = \"childTest\" +childId = 1431667073, childString = \"\", childId = 1431667073, childString = \"\" +childId = -9864, childString = \\\"\\\" \ No newline at end of file