| 60 | }; |
| 61 | |
| 62 | bool SplitStructuredLine(absl::string_view line, char delimiter, |
| 63 | const char* symbol_pairs, |
| 64 | std::vector<absl::string_view>* cols) { |
| 65 | ClosingSymbolLookup lookup(symbol_pairs); |
| 66 | |
| 67 | // Stack of symbols expected to close the current opened expressions. |
| 68 | std::vector<char> expected_to_close; |
| 69 | |
| 70 | ABSL_RAW_CHECK(cols != nullptr, ""); |
| 71 | cols->push_back(line); |
| 72 | for (size_t i = 0; i < line.size(); ++i) { |
| 73 | char c = line[i]; |
| 74 | if (expected_to_close.empty() && c == delimiter) { |
| 75 | // We don't have any open expression, this is a valid separator. |
| 76 | cols->back().remove_suffix(line.size() - i); |
| 77 | cols->push_back(line.substr(i + 1)); |
| 78 | } else if (!expected_to_close.empty() && c == expected_to_close.back()) { |
| 79 | // Can we close the currently open expression? |
| 80 | expected_to_close.pop_back(); |
| 81 | } else if (lookup.GetClosingChar(c)) { |
| 82 | // If this is an opening symbol, we open a new expression and push |
| 83 | // the expected closing symbol on the stack. |
| 84 | expected_to_close.push_back(lookup.GetClosingChar(c)); |
| 85 | } else if (lookup.IsClosing(c)) { |
| 86 | // Error: mismatched closing symbol. |
| 87 | return false; |
| 88 | } |
| 89 | } |
| 90 | if (!expected_to_close.empty()) { |
| 91 | return false; // Missing closing symbol(s) |
| 92 | } |
| 93 | return true; // Success |
| 94 | } |
| 95 | |
| 96 | inline bool TryStripPrefixString(absl::string_view str, |
| 97 | absl::string_view prefix, string* result) { |