Fixed double space compression issue by word replacement for a space character

This commit is contained in:
Jordan Sherer 2018-10-08 15:36:09 -04:00
parent 2d392dd676
commit 353d75ac49
4 changed files with 27 additions and 14 deletions

16
jsc.cpp
View File

@ -23,6 +23,7 @@
#include <cmath>
#include <QDebug>
Codeword JSC::codeword(quint32 index, bool separate, quint32 bytesize, quint32 s, quint32 c){
QList<Codeword> out;
@ -52,9 +53,19 @@ QList<CodewordPair> JSC::compress(QString text){
const quint32 s = 7;
const quint32 c = pow(2, 4) - s;
foreach(QString w, text.split(" ", QString::SkipEmptyParts)){
QString space(" ");
foreach(QString w, text.split(" ", QString::KeepEmptyParts)){
bool ok = false;
bool isSpaceCharacter = false;
// if this is an empty part, it should be a space.
if(w.isEmpty()){
w = space;
isSpaceCharacter = true;
}
while(!w.isEmpty()){
// this does both prefix and full match lookup
auto index = lookup(w, &ok);
@ -66,7 +77,8 @@ QList<CodewordPair> JSC::compress(QString text){
w = QString(w.mid(t.size));
bool isLast = w.isEmpty();
out.append({ codeword(index, isLast, b, s, c), (quint32)t.size + (isLast ? 1 : 0) /* for the space that follows */});
bool shouldAppendSpace = isLast && !isSpaceCharacter;
out.append({ codeword(index, shouldAppendSpace, b, s, c), (quint32)t.size + (shouldAppendSpace ? 1 : 0) /* for the space that follows */});
}
}

4
jsc.h
View File

@ -39,8 +39,8 @@ public:
static const Tuple map[262144];
static const Tuple list[262144];
static const quint32 prefixSize = 68;
static const Tuple prefix[68];
static const quint32 prefixSize = 69;
static const Tuple prefix[69];
};
#endif // JSC_H

View File

@ -29,7 +29,7 @@ const Tuple JSC::list[262144] = {
{"_", 1, 48},
{"^", 1, 64},
{"]", 1, 59},
{"\\", 1, 67},
{" ", 1, 67},
{"[", 1, 58},
{"ZZZZ", 4, 91474},
{"ZZZ", 3, 70901},
@ -180080,8 +180080,8 @@ const Tuple JSC::list[262144] = {
{"FTAD", 4, 112460},
{"FTAC", 4, 68872},
{"FTAB", 4, 72752},
{"FT8CALL", 7, 69},
{"FT8", 3, 68},
{"\\", 1, 69},
{"FT8", 3, 68},
{"FSYW", 4, 155790},
{"FSYT", 4, 186523},
{"FSYS", 4, 69541},
@ -262164,10 +262164,10 @@ const Tuple JSC::list[262144] = {
{"$", 1, 51},
{"#", 1, 53},
{"\"", 1, 26},
{"!", 1, 28},
{"!", 1, 28},
};
const Tuple JSC::prefix[68] = {
const Tuple JSC::prefix[69] = {
{"!", 1, 262143},
{"\"", 1, 262142},
{"#", 1, 262141},
@ -262204,7 +262204,8 @@ const Tuple JSC::prefix[68] = {
{"B", 13306, 233869},
{"C", 17608, 216261},
{"D", 13749, 202512},
{"E", 12403, 190109},
{"E", 12403, 190109},
{"\\", 1, 180059},
{"F", 11252, 178857},
{"G", 10672, 168185},
{"H", 9060, 159125},
@ -262227,7 +262228,7 @@ const Tuple JSC::prefix[68] = {
{"Y", 4348, 2264},
{"Z", 2254, 10},
{"[", 1, 9},
{"\\", 1, 8},
{" ", 1, 8},
{"]", 1, 7},
{"^", 1, 6},
{"_", 1, 5},

View File

@ -88,9 +88,9 @@ const Tuple JSC::map[262144] = {
{"^", 1, 64},
{"`", 1, 65},
{"~", 1, 66},
{"\\", 1, 67},
{"FT8", 3, 68},
{"FT8CALL", 7, 69},
{" ", 1, 67},
{"FT8", 3, 68},
{"\\", 1, 69},
{"JS8", 3, 70},
{"JS8CALL", 7, 71},
{"JSQSO", 5, 72},