Skip to content

vakarelov/qt-lzstring

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qt-lzstring

Qt implementation of LZ-String with a platform-agnostic core and a simple CLI.

Refactor highlights

  • LZ core extracted to src/LZCore.{h,cpp}. It contains the compression/decompression logic and depends only on an abstract platform interface.
  • New platform interface src/ILZPlatform.h encapsulates string/character operations the core needs.
  • Two platform implementations:
    • src/QtLZPlatform.{h,cpp} for Qt builds (uses QString/QChar/QHash).
    • src/StdLZPlatform.{h,cpp} for non-Qt builds (uses std::string and simple containers).
  • src/lzstring.cpp is a thin facade that selects the platform at compile time and delegates to LZCore.
  • Build files (CMake and qmake .pri) updated to include the new sources.

Public API

  • LZString public static methods are unchanged: compress, compressToUTF16, compressToBase64, and corresponding decompress* variants.

Notes

  • The core does not depend on Qt; only the platform layer bridges to Qt or std. This improves separation of concerns and makes the LZ implementation reusable.
  • Non-Qt mode (CMake default) is intended for simple CLI usage. For full Unicode fidelity and UTF‑16/Base64 behavior identical to the original Qt implementation, build/run the Qt test target which uses QString code units.

Installation (Linux)

  • Prerequisites: a C++ compiler and either Qt (for the full-featured test suite) or just CMake (for the minimal non‑Qt CLI + std round‑trip tests).

Debian/Ubuntu

sudo apt-get update
sudo apt-get install -y build-essential cmake
# For Qt tests (optional)
sudo apt-get install -y qtbase5-dev qtbase5-dev-tools

Fedora

sudo dnf install -y cmake make gcc-c++
# For Qt tests (optional)
sudo dnf install -y qt5-qtbase-devel

Build (CMake)

  • Default (non-Qt CLI only):

    • Windows (cmd.exe):
      cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_QT_TESTS=OFF
      cmake --build build --config Release
    • Linux/macOS:
      cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_QT_TESTS=OFF
      cmake --build build --config Release
    • Binary: lzstring / lzstring.exe in the build tree.
  • With Qt tests (auto-detect Qt5/Qt6):

    cmake -S . -B build -DBUILD_QT_TESTS=ON
    cmake --build build --target lzstring_test
    ctest --test-dir build -V -R lzstring_test

    If Qt isn't found, a status message is printed and the normal CLI plus non-Qt tests still build.

Tests (CMake)

  • Always built: lzstring_std_test (non-Qt, exercises StdLZPlatform).
    cmake -S . -B build -DBUILD_QT_TESTS=OFF
    cmake --build build --target lzstring_std_test
    ctest --test-dir build -V -R lzstring_std_test
  • Optionally (with Qt): lzstring_test (original Qt/QString test + benchmarks). Data file data.json is auto-copied beside the test binary and the working directory set via CTest so relative open succeeds.

Build (qmake, legacy / optional)

  • The .pri pulls in all sources; tests are under tests/.
  • Linux/macOS:
    qmake
    make -j
  • Windows (from a Qt command prompt):
    qmake
    nmake

Getting the sources

git clone <REPO_URL>
cd qt-lzstring

Usage (CLI)

  • The CLI reads from a file or stdin (-) and writes to a file or stdout (-).
  • Binary name: lzstring (.exe on Windows)
  • Operations:
    • --compress
    • --compressToUTF16
    • --compressToBase64
    • --decompress
    • --decompressFromUTF16
    • --decompressFromBase64
    • --test (round‑trip checks for all codecs on the provided input; prints boolean results and exits)

Examples (Linux/macOS)

./lzstring --compress input.txt output.lz
./lzstring --compressToUTF16 input.txt output.lz16
./lzstring --compressToBase64 input.txt output.lz64
./lzstring --decompress input.lz output.txt
./lzstring --decompressFromUTF16 input.lz16 output.txt
./lzstring --decompressFromBase64 input.lz64 output.txt
./lzstring --test input.txt
cat input.txt | ./lzstring --compress - -
cat input.lz  | ./lzstring --decompress - -

Examples (Windows cmd.exe)

lzstring.exe --compress input.txt output.lz
lzstring.exe --decompress input.lz output.txt
lzstring.exe --test input.txt
:: Pipes
type input.txt | lzstring.exe --compress - -
type input.lz  | lzstring.exe --decompress - -

Extending tests

  • Add more corpus cases: modify tests/std_roundtrip_test.cpp or the Qt test's test_data() method.
  • For performance comparisons, run the Qt benchmarks (they use QBENCHMARK).
  • To disable the std test (e.g., in a packaging build), you can wrap its target creation in an option similar to BUILD_QT_TESTS.

License

About

Qt implementation of LZ-String javascript library for creating an executable

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 88.0%
  • CMake 7.1%
  • QMake 4.9%