diff --git a/jsc.cpp b/jsc.cpp index df7f8d3..fe86a12 100644 --- a/jsc.cpp +++ b/jsc.cpp @@ -58,13 +58,17 @@ QList JSC::compress(QString text){ QString space(" "); - foreach(QString w, text.split(" ", QString::KeepEmptyParts)){ - bool ok = false; + QStringList words = text.split(" ", QString::KeepEmptyParts); + for(int i = 0, len = words.length(); i < len; i++){ + QString w = words[i]; + + bool isLastWord = (i == len - 1); + bool ok = false; bool isSpaceCharacter = false; - // if this is an empty part, it should be a space. - if(w.isEmpty()){ + // if this is an empty part, it should be a space, unless its the last word. + if(w.isEmpty() && !isLastWord){ w = space; isSpaceCharacter = true; } @@ -77,10 +81,12 @@ QList JSC::compress(QString text){ } auto t = JSC::map[index]; + w = QString(w).mid(t.size); bool isLast = w.isEmpty(); - bool shouldAppendSpace = isLast && !isSpaceCharacter; + bool shouldAppendSpace = isLast && !isSpaceCharacter && !isLastWord; + out.append({ codeword(index, shouldAppendSpace, b, s, c), (quint32)t.size + (shouldAppendSpace ? 1 : 0) /* for the space that follows */}); } } @@ -145,6 +151,7 @@ QString JSC::decompress(Codeword const& bitvec){ if(j >= (int)JSC::size){ break; } + auto word = QString(JSC::map[j].str); out.append(word); diff --git a/mainwindow.cpp b/mainwindow.cpp index 0749dee..5f59cec 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1719,6 +1719,16 @@ void MainWindow::initializeDummyData(){ return; } +#if 0 + Codeword all; + foreach(CodewordPair p, JSC::compress("")){ + all.append(p.first); + } + qDebug() << all; + qDebug() << JSC::decompress(all) << (JSC::decompress(all) == "HELLO WORLD "); + exit(-1); +#endif + #if 0 auto t = new QTimer(this); t->setInterval(150); diff --git a/varicode.cpp b/varicode.cpp index bdf8884..cd2c2a5 100644 --- a/varicode.cpp +++ b/varicode.cpp @@ -1862,7 +1862,9 @@ QList> Varicode::buildMessageFrames(QString const& mycall, if(line.startsWith(mycall + ":") || line.startsWith(mycall + " ")){ line = lstrip(line.mid(mycall.length() + 1)); } +#endif +#if AUTO_RSTRIP_WHITESPACE // remove trailing whitespace as long as there are characters left afterwards auto rline = rstrip(line); if(!rline.isEmpty()){