コード例 #1
0
ファイル: charset_conv.cpp プロジェクト: seawaveT/Aegisub
size_t IconvWrapper::RequiredBufferSize(const char* src, size_t srcLen) {
	char buff[512];
	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:
				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 occured");
		}
	}
	return charsWritten;
}
コード例 #2
0
ファイル: charset_conv.cpp プロジェクト: seawaveT/Aegisub
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;
}
コード例 #3
0
ファイル: charset_conv.cpp プロジェクト: seawaveT/Aegisub
void IconvWrapper::Convert(std::string const& source, std::string &dest) {
	char buff[512];

	const char *src = source.data();
	size_t srcLen = source.size();
	size_t res;
	do {
		char *dst = buff;
		size_t dstLen = sizeof(buff);
		res = conv->Convert(&src, &srcLen, &dst, &dstLen);
		if (res == 0) conv->Convert(nullptr, nullptr, &dst, &dstLen);

		dest.append(buff, sizeof(buff) - dstLen);
	} while (res == iconv_failed && errno == E2BIG);
	
	if (res == iconv_failed) {
		switch (errno) {
			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");
		}
	}
}
コード例 #4
0
ファイル: charset_conv.cpp プロジェクト: Aegisub/Aegisub
size_t IconvWrapper::RequiredBufferSize(const char* src, size_t srcLen) {
	char buff[512];
	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;
}
コード例 #5
0
ファイル: charset_conv.cpp プロジェクト: Aegisub/Aegisub
void IconvWrapper::Convert(const char *src, size_t srcLen, std::string &dest) {
	char buff[512];

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

		dest.append(buff, sizeof(buff) - dstLen);
	} while (res == iconv_failed && errno == E2BIG);

	if (res == iconv_failed) {
		switch (errno) {
			case EILSEQ:
			case EINVAL:
				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");
		}
	}
}
コード例 #6
0
ファイル: charset_conv.cpp プロジェクト: Aegisub/Aegisub
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;
}