Mercurial > dedupe
diff BitDecoder.cpp @ 45:41cc0d8ac77f
Decode directly from bitString.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 10 Sep 2012 21:29:43 +0200 |
| parents | 95a10553ff90 |
| children | f8d0ea827db3 |
line wrap: on
line diff
--- a/BitDecoder.cpp Mon Sep 10 19:18:30 2012 +0200 +++ b/BitDecoder.cpp Mon Sep 10 21:29:43 2012 +0200 @@ -1,5 +1,7 @@ #include "BitDecoder.hpp" +#include "Exception/InvalidDataException.hpp" + BitDecoder::BitDecoder(BitDecoder* low_in, BitDecoder* high_in) : low(low_in), high(high_in) { } @@ -61,3 +63,22 @@ } return retVal; } + +QBitArray BitDecoder::bitsFromString(const QString& str) +{ + QBitArray bits(str.size()); + for (int i = 0; i < str.size(); ++i) { + if (str[i] == '1') + bits[i] = true; + else if (str[i] == '0') + bits[i] = false; + else + throw InvalidDataException(); + } + return bits; +} + +QString BitDecoder::decode(const QString& bits) const +{ + return decode(bitsFromString(bits)); +}
