bakaid commented on a change in pull request #596: MINIFICPP-925 - Fix TailFile
hang on long lines
URL: https://github.com/apache/nifi-minifi-cpp/pull/596#discussion_r299897665
##########
File path: libminifi/include/utils/StringUtils.h
##########
@@ -347,6 +227,139 @@ class StringUtils {
return join(std::basic_string<TChar>(separator), container);
};
+ /**
+ * Hexdecodes the hexencoded string in data, ignoring every character that
is not [0-9a-fA-F]
+ * @param data the output buffer where the hexdecoded bytes will be written.
Must be at least length / 2 bytes long.
+ * @param data_length pointer to the length of data the data buffer. It will
be filled with the length of the decoded bytes.
+ * @param hex the hexencoded string
+ * @param hex_length the length of hex
+ * @return true on success
+ */
+ inline static bool from_hex(uint8_t* data, size_t* data_length, const char*
hex, size_t hex_length) {
+ if (*data_length < hex_length / 2) {
+ return false;
+ }
+ uint8_t n1;
+ bool found_first_nibble = false;
+ *data_length = 0;
+ for (size_t i = 0; i < hex_length; i++) {
+ const uint8_t byte = static_cast<uint8_t>(hex[i]);
+ if (byte > 127) {
+ continue;
+ }
+ uint8_t n = hex_lut[byte];
+ if (n != SKIP) {
+ if (found_first_nibble) {
+ data[(*data_length)++] = n1 << 4 | n;
+ found_first_nibble = false;
+ } else {
+ n1 = n;
+ found_first_nibble = true;
+ }
+ }
+ }
+ if (found_first_nibble) {
Review comment:
I think the current version it is more readable than `return
!found_first_nibble;`
This way it checks for an error (there is a nibble at the end without a
pair), and at the end of function returns with true.
The consolidated return statement would be harder to understand at the first
glance.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services