Fixed double space compression issue by word replacement for a space character
This commit is contained in:
parent
2d392dd676
commit
353d75ac49
16
jsc.cpp
16
jsc.cpp
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
Codeword JSC::codeword(quint32 index, bool separate, quint32 bytesize, quint32 s, quint32 c){
|
Codeword JSC::codeword(quint32 index, bool separate, quint32 bytesize, quint32 s, quint32 c){
|
||||||
QList<Codeword> out;
|
QList<Codeword> out;
|
||||||
@ -52,9 +53,19 @@ QList<CodewordPair> JSC::compress(QString text){
|
|||||||
const quint32 s = 7;
|
const quint32 s = 7;
|
||||||
const quint32 c = pow(2, 4) - s;
|
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 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()){
|
while(!w.isEmpty()){
|
||||||
// this does both prefix and full match lookup
|
// this does both prefix and full match lookup
|
||||||
auto index = lookup(w, &ok);
|
auto index = lookup(w, &ok);
|
||||||
@ -66,7 +77,8 @@ QList<CodewordPair> JSC::compress(QString text){
|
|||||||
w = QString(w.mid(t.size));
|
w = QString(w.mid(t.size));
|
||||||
|
|
||||||
bool isLast = w.isEmpty();
|
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
4
jsc.h
@ -39,8 +39,8 @@ public:
|
|||||||
static const Tuple map[262144];
|
static const Tuple map[262144];
|
||||||
static const Tuple list[262144];
|
static const Tuple list[262144];
|
||||||
|
|
||||||
static const quint32 prefixSize = 68;
|
static const quint32 prefixSize = 69;
|
||||||
static const Tuple prefix[68];
|
static const Tuple prefix[69];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // JSC_H
|
#endif // JSC_H
|
||||||
|
@ -29,7 +29,7 @@ const Tuple JSC::list[262144] = {
|
|||||||
{"_", 1, 48},
|
{"_", 1, 48},
|
||||||
{"^", 1, 64},
|
{"^", 1, 64},
|
||||||
{"]", 1, 59},
|
{"]", 1, 59},
|
||||||
{"\\", 1, 67},
|
{" ", 1, 67},
|
||||||
{"[", 1, 58},
|
{"[", 1, 58},
|
||||||
{"ZZZZ", 4, 91474},
|
{"ZZZZ", 4, 91474},
|
||||||
{"ZZZ", 3, 70901},
|
{"ZZZ", 3, 70901},
|
||||||
@ -180080,7 +180080,7 @@ const Tuple JSC::list[262144] = {
|
|||||||
{"FTAD", 4, 112460},
|
{"FTAD", 4, 112460},
|
||||||
{"FTAC", 4, 68872},
|
{"FTAC", 4, 68872},
|
||||||
{"FTAB", 4, 72752},
|
{"FTAB", 4, 72752},
|
||||||
{"FT8CALL", 7, 69},
|
{"\\", 1, 69},
|
||||||
{"FT8", 3, 68},
|
{"FT8", 3, 68},
|
||||||
{"FSYW", 4, 155790},
|
{"FSYW", 4, 155790},
|
||||||
{"FSYT", 4, 186523},
|
{"FSYT", 4, 186523},
|
||||||
@ -262167,7 +262167,7 @@ const Tuple JSC::list[262144] = {
|
|||||||
{"!", 1, 28},
|
{"!", 1, 28},
|
||||||
};
|
};
|
||||||
|
|
||||||
const Tuple JSC::prefix[68] = {
|
const Tuple JSC::prefix[69] = {
|
||||||
{"!", 1, 262143},
|
{"!", 1, 262143},
|
||||||
{"\"", 1, 262142},
|
{"\"", 1, 262142},
|
||||||
{"#", 1, 262141},
|
{"#", 1, 262141},
|
||||||
@ -262205,6 +262205,7 @@ const Tuple JSC::prefix[68] = {
|
|||||||
{"C", 17608, 216261},
|
{"C", 17608, 216261},
|
||||||
{"D", 13749, 202512},
|
{"D", 13749, 202512},
|
||||||
{"E", 12403, 190109},
|
{"E", 12403, 190109},
|
||||||
|
{"\\", 1, 180059},
|
||||||
{"F", 11252, 178857},
|
{"F", 11252, 178857},
|
||||||
{"G", 10672, 168185},
|
{"G", 10672, 168185},
|
||||||
{"H", 9060, 159125},
|
{"H", 9060, 159125},
|
||||||
@ -262227,7 +262228,7 @@ const Tuple JSC::prefix[68] = {
|
|||||||
{"Y", 4348, 2264},
|
{"Y", 4348, 2264},
|
||||||
{"Z", 2254, 10},
|
{"Z", 2254, 10},
|
||||||
{"[", 1, 9},
|
{"[", 1, 9},
|
||||||
{"\\", 1, 8},
|
{" ", 1, 8},
|
||||||
{"]", 1, 7},
|
{"]", 1, 7},
|
||||||
{"^", 1, 6},
|
{"^", 1, 6},
|
||||||
{"_", 1, 5},
|
{"_", 1, 5},
|
||||||
|
@ -88,9 +88,9 @@ const Tuple JSC::map[262144] = {
|
|||||||
{"^", 1, 64},
|
{"^", 1, 64},
|
||||||
{"`", 1, 65},
|
{"`", 1, 65},
|
||||||
{"~", 1, 66},
|
{"~", 1, 66},
|
||||||
{"\\", 1, 67},
|
{" ", 1, 67},
|
||||||
{"FT8", 3, 68},
|
{"FT8", 3, 68},
|
||||||
{"FT8CALL", 7, 69},
|
{"\\", 1, 69},
|
||||||
{"JS8", 3, 70},
|
{"JS8", 3, 70},
|
||||||
{"JS8CALL", 7, 71},
|
{"JS8CALL", 7, 71},
|
||||||
{"JSQSO", 5, 72},
|
{"JSQSO", 5, 72},
|
||||||
|
Loading…
Reference in New Issue
Block a user