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(" ");
|
QString space(" ");
|
||||||
|
|
||||||
foreach(QString w, text.split(" ", QString::KeepEmptyParts)){
|
QStringList words = text.split(" ", QString::KeepEmptyParts);
|
||||||
bool ok = false;
|
|
||||||
|
|
||||||
|
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;
|
bool isSpaceCharacter = false;
|
||||||
|
|
||||||
// if this is an empty part, it should be a space.
|
// if this is an empty part, it should be a space, unless its the last word.
|
||||||
if(w.isEmpty()){
|
if(w.isEmpty() && !isLastWord){
|
||||||
w = space;
|
w = space;
|
||||||
isSpaceCharacter = true;
|
isSpaceCharacter = true;
|
||||||
}
|
}
|
||||||
@ -77,10 +81,12 @@ QList<CodewordPair> JSC::compress(QString text){
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto t = JSC::map[index];
|
auto t = JSC::map[index];
|
||||||
|
|
||||||
w = QString(w).mid(t.size);
|
w = QString(w).mid(t.size);
|
||||||
|
|
||||||
bool isLast = w.isEmpty();
|
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 */});
|
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){
|
if(j >= (int)JSC::size){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto word = QString(JSC::map[j].str);
|
auto word = QString(JSC::map[j].str);
|
||||||
|
|
||||||
out.append(word);
|
out.append(word);
|
||||||
|
@ -1719,6 +1719,16 @@ void MainWindow::initializeDummyData(){
|
|||||||
return;
|
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
|
#if 0
|
||||||
auto t = new QTimer(this);
|
auto t = new QTimer(this);
|
||||||
t->setInterval(150);
|
t->setInterval(150);
|
||||||
|
@ -1862,7 +1862,9 @@ QList<QPair<QString, int>> Varicode::buildMessageFrames(QString const& mycall,
|
|||||||
if(line.startsWith(mycall + ":") || line.startsWith(mycall + " ")){
|
if(line.startsWith(mycall + ":") || line.startsWith(mycall + " ")){
|
||||||
line = lstrip(line.mid(mycall.length() + 1));
|
line = lstrip(line.mid(mycall.length() + 1));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if AUTO_RSTRIP_WHITESPACE
|
||||||
// remove trailing whitespace as long as there are characters left afterwards
|
// remove trailing whitespace as long as there are characters left afterwards
|
||||||
auto rline = rstrip(line);
|
auto rline = rstrip(line);
|
||||||
if(!rline.isEmpty()){
|
if(!rline.isEmpty()){
|
||||||
|
Loading…
Reference in New Issue
Block a user