Skip to content

Commit

Permalink
Content: fix missing symbol error when building without ZXING_READERS
Browse files Browse the repository at this point in the history
This fixes the issue targeted with PR zxing-cpp#811 but without changing the API.
  • Loading branch information
axxel committed Jul 22, 2024
1 parent cd11aa5 commit d0c8f22
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/src/Content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "HRI.h"
#include "TextDecoder.h"
#include "Utf.h"
#include "Version.h"
#include "ZXAlgorithms.h"

#include <cctype>
Expand Down Expand Up @@ -98,6 +99,7 @@ std::string Content::render(bool withECI) const
if (empty() || !canProcess())
return {};

#ifdef ZXING_READERS
std::string res;
if (withECI)
res = symbology.toString(true);
Expand Down Expand Up @@ -136,6 +138,10 @@ std::string Content::render(bool withECI) const
});

return res;
#else
//TODO: replace by proper construction from encoded data from within zint
return std::string(bytes.asString());
#endif
}

std::string Content::text(TextMode mode) const
Expand All @@ -145,13 +151,15 @@ std::string Content::text(TextMode mode) const
case TextMode::ECI: return render(true);
case TextMode::HRI:
switch (type()) {
#ifdef ZXING_READERS
case ContentType::GS1: {
auto plain = render(false);
auto hri = HRIFromGS1(plain);
return hri.empty() ? plain : hri;
}
case ContentType::ISO15434: return HRIFromISO15434(render(false));
case ContentType::Text: return render(false);
#endif
default: return text(TextMode::Escaped);
}
case TextMode::Hex: return ToHex(bytes);
Expand Down Expand Up @@ -190,6 +198,7 @@ ByteArray Content::bytesECI() const

CharacterSet Content::guessEncoding() const
{
#ifdef ZXING_READERS
// assemble all blocks with unknown encoding
ByteArray input;
ForEachECIBlock([&](ECI eci, int begin, int end) {
Expand All @@ -201,10 +210,14 @@ CharacterSet Content::guessEncoding() const
return CharacterSet::Unknown;

return TextDecoder::GuessEncoding(input.data(), input.size(), CharacterSet::ISO8859_1);
#else
return CharacterSet::Unknown;
#endif
}

ContentType Content::type() const
{
#ifdef ZXING_READERS
if (empty())
return ContentType::Text;

Expand Down Expand Up @@ -235,6 +248,10 @@ ContentType Content::type() const
return ContentType::Binary;

return ContentType::Mixed;
#else
//TODO: replace by proper construction from encoded data from within zint
return ContentType::Text;
#endif
}

} // namespace ZXing

0 comments on commit d0c8f22

Please sign in to comment.