| 743 | } |
| 744 | |
| 745 | Status ParseCppClass(const string& cpp_class, string* class_name, |
| 746 | std::vector<string>* namespaces) { |
| 747 | class_name->clear(); |
| 748 | namespaces->clear(); |
| 749 | if (cpp_class.empty()) { |
| 750 | return errors::InvalidArgument("empty cpp_class: " + cpp_class); |
| 751 | } |
| 752 | std::vector<string> parts = absl::StrSplit(cpp_class, "::"); |
| 753 | if (parts.front().empty()) { |
| 754 | // Allow a fully qualified name that starts with "::". |
| 755 | parts.erase(parts.begin()); |
| 756 | } |
| 757 | for (int i = 0; i < parts.size(); ++i) { |
| 758 | if (i < parts.size() - 1) { |
| 759 | TF_RETURN_IF_ERROR(ValidateCppIdent( |
| 760 | parts[i], "in namespace component of cpp_class: " + cpp_class)); |
| 761 | namespaces->push_back(parts[i]); |
| 762 | } else { |
| 763 | TF_RETURN_IF_ERROR(ValidateCppIdent( |
| 764 | parts[i], "in class name of cpp_class: " + cpp_class)); |
| 765 | *class_name = parts[i]; |
| 766 | } |
| 767 | } |
| 768 | return Status::OK(); |
| 769 | } |
| 770 | |
| 771 | Status ValidateCppIdent(absl::string_view ident, absl::string_view msg) { |
| 772 | if (ident.empty()) { |