| 95 | */ |
| 96 | |
| 97 | void qpdf_stream_decoder::handleObject(QPDFObjectHandle obj, size_t offset, size_t len) |
| 98 | { |
| 99 | //LOG_S(INFO) << __FUNCTION__ << "\t offset: " << offset << ", len: " << len; |
| 100 | |
| 101 | qpdf_stream_instruction row; |
| 102 | { |
| 103 | row.key = obj.getTypeName(); |
| 104 | row.val = obj.unparse(); |
| 105 | row.obj = obj; |
| 106 | |
| 107 | // LOG_S(INFO) << std::setw(12) << row.key << " | " << row.val; |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | if(row.is_null() or row.is_array() or row.is_dict()) |
| 112 | { |
| 113 | LOG_S(WARNING) << "null: " << row.is_null() << ", array: " << row.is_array() << ", dict: " << row.is_dict(); |
| 114 | } |
| 115 | */ |
| 116 | |
| 117 | // if the row is null, reinterprete it as an empty array. We encountered |
| 118 | // this usecase for a parameter of the d operator (see Table 56) that is |
| 119 | // null but in reality should be an empty array. |
| 120 | if(row.is_null()) |
| 121 | { |
| 122 | row.key = "parameter"; |
| 123 | row.val = "[]"; |
| 124 | } |
| 125 | // All three regex patterns match malformed numbers containing '-' at |
| 126 | // position > 0 (e.g. "1.23-45", "--123.4"). Skip the expensive regex |
| 127 | // calls for the vast majority of tokens that don't have this. |
| 128 | else if (row.val.find('-', 1) != std::string::npos) |
| 129 | { |
| 130 | std::smatch match; |
| 131 | |
| 132 | if (std::regex_match(row.val, match, value_pattern_0)) |
| 133 | { |
| 134 | std::string mvalue = match[1].str(); |
| 135 | LOG_S(WARNING) << "match-1: " << std::setw(12) << row.key << " | " << row.val << " => new matched value: " << mvalue; |
| 136 | |
| 137 | double value = utils::numeric::locale_safe_stod(mvalue); |
| 138 | |
| 139 | // Creating a real (floating-point) QPDFObjectHandle |
| 140 | QPDFObjectHandle new_obj = QPDFObjectHandle::newReal(value); |
| 141 | |
| 142 | row.key = new_obj.getTypeName(); |
| 143 | row.val = new_obj.unparse(); |
| 144 | row.obj = new_obj; |
| 145 | } |
| 146 | else if (std::regex_match(row.val, match, value_pattern_1)) |
| 147 | { |
| 148 | std::string mvalue = match[1].str() + match[4].str(); |
| 149 | LOG_S(WARNING) << "match-2: " << std::setw(12) << row.key << " | " << row.val << " => new matched value: " << mvalue; |
| 150 | |
| 151 | double value = utils::numeric::locale_safe_stod(mvalue); |
| 152 | |
| 153 | // Creating a real (floating-point) QPDFObjectHandle |
| 154 | QPDFObjectHandle new_obj = QPDFObjectHandle::newReal(value); |
nothing calls this directly
no test coverage detected