adamdebreceni commented on a change in pull request #923:
URL: https://github.com/apache/nifi-minifi-cpp/pull/923#discussion_r503342925
##########
File path: libminifi/src/utils/Id.cpp
##########
@@ -115,18 +116,36 @@ std::string Identifier::to_string() const {
utils::optional<Identifier> Identifier::parse(const std::string &str) {
Identifier id;
- int assigned = sscanf(str.c_str(), UUID_FORMAT_STRING,
- &id.data_[0], &id.data_[1], &id.data_[2], &id.data_[3],
- &id.data_[4], &id.data_[5],
- &id.data_[6], &id.data_[7],
- &id.data_[8], &id.data_[9],
- &id.data_[10], &id.data_[11], &id.data_[12], &id.data_[13],
&id.data_[14], &id.data_[15]);
- if (assigned != 16) {
- return utils::nullopt;
+ if (str.length() != 36) return {};
+ int charIdx = 0;
+ int byteIdx = 0;
+ auto input = reinterpret_cast<const uint8_t*>(str.c_str());
+ while(byteIdx < 4) {
+ if (!parseByte(id.data_, input, charIdx, byteIdx)) return {};
+ }
+ if (input[charIdx++] != '-') return {};
+
+ for (size_t idx = 0; idx < 3; ++idx) {
+ if (!parseByte(id.data_, input, charIdx, byteIdx)) return {};
+ if (!parseByte(id.data_, input, charIdx, byteIdx)) return {};
+ if (input[charIdx++] != '-') return {};
+ }
+ while(byteIdx < 16) {
+ if(!parseByte(id.data_, input, charIdx, byteIdx)) return {};
Review comment:
done
----------------------------------------------------------------
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]