From 353d75ac491166daa9f4e40fc688eb620aa0759b Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Mon, 8 Oct 2018 15:36:09 -0400 Subject: [PATCH] Fixed double space compression issue by word replacement for a space character --- jsc.cpp | 16 ++++++++++++++-- jsc.h | 4 ++-- jsc_list.cpp | 15 ++++++++------- jsc_map.cpp | 6 +++--- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/jsc.cpp b/jsc.cpp index 46692cd..eb5c376 100644 --- a/jsc.cpp +++ b/jsc.cpp @@ -23,6 +23,7 @@ #include +#include Codeword JSC::codeword(quint32 index, bool separate, quint32 bytesize, quint32 s, quint32 c){ QList out; @@ -52,9 +53,19 @@ QList 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 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 */}); } } diff --git a/jsc.h b/jsc.h index 0a56e35..9929e10 100644 --- a/jsc.h +++ b/jsc.h @@ -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 diff --git a/jsc_list.cpp b/jsc_list.cpp index 99dacff..d44cdd2 100644 --- a/jsc_list.cpp +++ b/jsc_list.cpp @@ -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}, diff --git a/jsc_map.cpp b/jsc_map.cpp index af153da..83a1cb8 100644 --- a/jsc_map.cpp +++ b/jsc_map.cpp @@ -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},