Skip to content

Commit 98583e8

Browse files
committed
DataURI: fix platform specific quirks.
1 parent 511ba82 commit 98583e8

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ add_library(${PROJECT_NAME} OBJECT
6969
src/autobattle.h
7070
src/background.cpp
7171
src/background.h
72-
src/base64.hpp
72+
src/base64.h
7373
src/baseui.cpp
7474
src/baseui.h
7575
src/battle_animation.cpp

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ libeasyrpg_player_a_SOURCES = \
3838
src/autobattle.h \
3939
src/background.cpp \
4040
src/background.h \
41-
src/base64.hpp \
41+
src/base64.h \
4242
src/baseui.cpp \
4343
src/baseui.h \
4444
src/battle_animation.cpp \

src/base64.hpp renamed to src/base64.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <string_view>
1212
#include <type_traits>
1313

14+
#include "output.h"
15+
1416
#if defined(__cpp_lib_bit_cast)
1517
#include <bit> // For std::bit_cast.
1618
#endif
@@ -546,7 +548,7 @@ inline OutputBuffer encode_into(InputIterator begin, InputIterator end) {
546548
break;
547549
}
548550
default: {
549-
throw std::runtime_error{"Invalid base64 encoded data"};
551+
Output::Warning("Invalid base64 encoded data");
550552
}
551553
}
552554

@@ -574,15 +576,13 @@ inline OutputBuffer decode_into(std::string_view base64Text) {
574576
}
575577

576578
if ((base64Text.size() & 3) != 0) {
577-
throw std::runtime_error{
578-
"Invalid base64 encoded data - Size not divisible by 4"};
579+
Output::Warning("Invalid base64 encoded data - Size not divisible by 4");
579580
}
580581

581582
const size_t numPadding =
582583
std::count(base64Text.rbegin(), base64Text.rbegin() + 4, '=');
583584
if (numPadding > 2) {
584-
throw std::runtime_error{
585-
"Invalid base64 encoded data - Found more than 2 padding signs"};
585+
Output::Warning("Invalid base64 encoded data - Found more than 2 padding signs");
586586
}
587587

588588
const size_t decodedsize = (base64Text.size() * 3 >> 2) - numPadding;
@@ -605,8 +605,7 @@ inline OutputBuffer decode_into(std::string_view base64Text) {
605605
const uint32_t temp = d1 | d2 | d3 | d4;
606606

607607
if (temp >= detail::bad_char) {
608-
throw std::runtime_error{
609-
"Invalid base64 encoded data - Invalid character"};
608+
Output::Warning("Invalid base64 encoded data - Invalid character");
610609
}
611610

612611
// Use bit_cast instead of union and type punning to avoid
@@ -636,8 +635,7 @@ inline OutputBuffer decode_into(std::string_view base64Text) {
636635
const uint32_t temp = d1 | d2 | d3;
637636

638637
if (temp >= detail::bad_char) {
639-
throw std::runtime_error{
640-
"Invalid base64 encoded data - Invalid character"};
638+
Output::Warning("Invalid base64 encoded data - Invalid character");
641639
}
642640

643641
// Use bit_cast instead of union and type punning to avoid
@@ -659,8 +657,7 @@ inline OutputBuffer decode_into(std::string_view base64Text) {
659657
const uint32_t temp = d1 | d2;
660658

661659
if (temp >= detail::bad_char) {
662-
throw std::runtime_error{
663-
"Invalid base64 encoded data - Invalid character"};
660+
Output::Warning("Invalid base64 encoded data - Invalid character");
664661
}
665662

666663
const std::array<char, 4> tempBytes =
@@ -669,8 +666,7 @@ inline OutputBuffer decode_into(std::string_view base64Text) {
669666
break;
670667
}
671668
default: {
672-
throw std::runtime_error{
673-
"Invalid base64 encoded data - Invalid padding number"};
669+
Output::Warning("Invalid base64 encoded data - Invalid padding number");
674670
}
675671
}
676672

src/filefinder.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#endif
5555

5656
#include "filesystem_stream.h"
57-
#include "base64.hpp"
57+
#include "base64.h"
5858

5959
namespace { // Anonymous namespace
6060

@@ -82,13 +82,7 @@ namespace { // Anonymous namespace
8282
result.mime_type = header;
8383
}
8484
if (result.is_base64) {
85-
try {
86-
result.data = base64::decode_into<std::vector<unsigned char>>(data_payload.begin(), data_payload.end());
87-
}
88-
catch (const std::exception& e) {
89-
Output::Warning("Base64 decoding failed: {}", e.what());
90-
return std::nullopt;
91-
}
85+
result.data = base64::decode_into<std::vector<unsigned char>>(data_payload.begin(), data_payload.end());
9286
}
9387
else {
9488
result.data.assign(data_payload.begin(), data_payload.end());

0 commit comments

Comments
 (0)