Fixed typeahead issues with trailing spaces
This commit is contained in:
parent
6ddbd47f81
commit
b7718ca528
17
jsc.cpp
17
jsc.cpp
@ -58,13 +58,17 @@ QList<CodewordPair> 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<CodewordPair> 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);
|
||||
|
@ -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);
|
||||
|
@ -1862,7 +1862,9 @@ QList<QPair<QString, int>> 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()){
|
||||
|
Loading…
Reference in New Issue
Block a user