The string representation of the values received in EqFailure() are already escaped. Split them on escaped '\n' boundaries. Leave all other escaped characters the same.
| 2742 | // escaped. Split them on escaped '\n' boundaries. Leave all other escaped |
| 2743 | // characters the same. |
| 2744 | std::vector<std::string> SplitEscapedString(const std::string& str) { |
| 2745 | std::vector<std::string> lines; |
| 2746 | size_t start = 0, end = str.size(); |
| 2747 | if (end > 2 && str[0] == '"' && str[end - 1] == '"') { |
| 2748 | ++start; |
| 2749 | --end; |
| 2750 | } |
| 2751 | bool escaped = false; |
| 2752 | for (size_t i = start; i + 1 < end; ++i) { |
| 2753 | if (escaped) { |
| 2754 | escaped = false; |
| 2755 | if (str[i] == 'n') { |
| 2756 | lines.push_back(str.substr(start, i - start - 1)); |
| 2757 | start = i + 1; |
| 2758 | } |
| 2759 | } else { |
| 2760 | escaped = str[i] == '\\'; |
| 2761 | } |
| 2762 | } |
| 2763 | lines.push_back(str.substr(start, end - start)); |
| 2764 | return lines; |
| 2765 | } |
| 2766 | |
| 2767 | } // namespace |
| 2768 |