Exemple #1
0
size_t IconvWrapper::Convert(const char* source, size_t sourceSize, char *dest, size_t destSize) {
	if (sourceSize == (size_t)-1)
		sourceSize = SrcStrLen(source);

	size_t res = conv->Convert(&source, &sourceSize, &dest, &destSize);
	if (res == 0) res = conv->Convert(nullptr, nullptr, &dest, &destSize);

	if (res == iconv_failed) {
		switch (errno) {
			case E2BIG:
				throw BufferTooSmall(
					"Destination buffer was not large enough to fit converted "
					"string.");
			case EINVAL:
				throw BadInput(
					"One or more characters in the input string were not valid "
					"characters in the given input encoding");
			case EILSEQ:
				throw BadOutput(
					"One or more characters could not be converted to the "
					"selected target encoding and the version of iconv "
					"Aegisub was built with does not have useful fallbacks. "
					"For best results, please build Aegisub using a recent "
					"version of GNU iconv.");
			default:
				throw ConversionFailure("An unknown conversion failure occurred");
		}
	}
	return res;
}
Exemple #2
0
size_t IconvWrapper::Convert(const char* source, size_t sourceSize, char *dest, size_t destSize) {
	if (sourceSize == (size_t)-1)
		sourceSize = SrcStrLen(source);

	size_t res = conv->Convert(&source, &sourceSize, &dest, &destSize);
	if (res == 0) res = conv->Convert(nullptr, nullptr, &dest, &destSize);

	if (res == iconv_failed) {
		switch (errno) {
			case E2BIG:
				throw BufferTooSmall(
					"Destination buffer was not large enough to fit converted "
					"string.");
			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 res;
}