Skip to content

Commit

Permalink
Revert "Bring back IconvWrapper::RequiredBufferSize"
Browse files Browse the repository at this point in the history
This reverts commit 04f4b26.
  • Loading branch information
arch1t3cht committed Nov 29, 2023
1 parent 812351f commit b0eda84
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 42 deletions.
32 changes: 0 additions & 32 deletions libaegisub/common/charset_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,38 +358,6 @@ size_t IconvWrapper::Convert(std::string_view source, std::span<char> dest) {
return dest.size() - dstLen;
}

size_t IconvWrapper::RequiredBufferSize(std::string_view str) {
return RequiredBufferSize(str.data(), str.size());
}

size_t IconvWrapper::RequiredBufferSize(const char* src, size_t srcLen) {
char buff[4096];
size_t charsWritten = 0;
size_t res;

do {
char* dst = buff;
size_t dstSize = sizeof(buff);
res = conv->Convert(&src, &srcLen, &dst, &dstSize);
conv->Convert(nullptr, nullptr, &dst, &dstSize);

charsWritten += dst - buff;
} while (res == iconv_failed && errno == E2BIG);

if (res == iconv_failed) {
switch (errno) {
case EINVAL:
case EILSEQ:
throw BadInput(
"One or more characters in the input string were not valid "
"characters in the given input encoding");
default:
throw ConversionFailure("An unknown conversion failure occurred");
}
}
return charsWritten;
}

bool IsConversionSupported(const char *src, const char *dst) {
iconv_t cd = iconv_open(dst, src);
bool supported = cd != iconv_invalid;
Expand Down
10 changes: 0 additions & 10 deletions libaegisub/include/libaegisub/charset_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ class IconvWrapper {
/// @param[out] dest Buffer to place the result in
/// @return Number of bytes written to dest
size_t Convert(std::string_view source, std::span<char> dest);

/// @brief Get the required buffer size required to fit the source string in the target charset
/// @param source A string in the source charset
/// @param sourceSize Length of the source in bytes
/// @return Bytes required, including NUL terminator if applicable
size_t RequiredBufferSize(const char* source, size_t sourceSize);
/// @brief Get the required buffer size required to fit the source string in the target charset
/// @param str A string in the source charset
/// @return Bytes required, not including space needed for NUL terminator
size_t RequiredBufferSize(std::string_view str);
};

/// Is the conversion from src to dst supported by the linked iconv library?
Expand Down

0 comments on commit b0eda84

Please sign in to comment.