Updated QrCode.encodeSegments() to throw DataTooLongException - in Java, C++, Python, Rust code. Rust code also changes return types from Option to Result. Updated Java and Rust documentation.

This commit is contained in:
Project Nayuki
2018-10-26 02:42:04 +00:00
parent 4635e8a8a8
commit 8da8107cc2
4 changed files with 43 additions and 21 deletions
+10 -2
View File
@@ -74,8 +74,16 @@ QrCode QrCode::encodeSegments(const vector<QrSegment> &segs, Ecc ecl,
dataUsedBits = QrSegment::getTotalBits(segs, version);
if (dataUsedBits != -1 && dataUsedBits <= dataCapacityBits)
break; // This version number is found to be suitable
if (version >= maxVersion) // All versions in the range could not fit the given data
throw std::length_error("Data too long");
if (version >= maxVersion) { // All versions in the range could not fit the given data
std::ostringstream sb;
if (dataUsedBits == -1)
sb << "Segment too long";
else {
sb << "Data length = " << dataUsedBits << " bits, ";
sb << "Max capacity = " << dataCapacityBits << " bits";
}
throw data_too_long(sb.str());
}
}
if (dataUsedBits == -1)
throw std::logic_error("Assertion error");