| 769 | } |
| 770 | |
| 771 | Status ValidateCppIdent(absl::string_view ident, absl::string_view msg) { |
| 772 | if (ident.empty()) { |
| 773 | return errors::InvalidArgument("empty identifier: ", msg); |
| 774 | } |
| 775 | // Require that the identifier starts with a nondigit, and is composed of |
| 776 | // nondigits and digits, as specified in section [2.11 Identifiers] of the |
| 777 | // C++11 Standard. Note that nondigit is defined as [_a-zA-Z] and digit is |
| 778 | // defined as [0-9]. |
| 779 | // |
| 780 | // Technically the standard also allows for `universal-character-name`, with a |
| 781 | // table of allowed unicode ranges, as well as `other implementation-defined |
| 782 | // characters`. We disallow those here to give better error messages, at the |
| 783 | // expensive of being more restrictive than the standard. |
| 784 | if (ident[0] != '_' && !IsAlpha(ident[0])) { |
| 785 | return errors::InvalidArgument("illegal leading char: ", msg); |
| 786 | } |
| 787 | for (size_t pos = 1; pos < ident.size(); ++pos) { |
| 788 | if (ident[pos] != '_' && !IsAlphaNum(ident[pos])) { |
| 789 | return errors::InvalidArgument("illegal char: ", msg); |
| 790 | } |
| 791 | } |
| 792 | return Status::OK(); |
| 793 | } |
| 794 | |
| 795 | } // namespace tfcompile |
| 796 | } // namespace tensorflow |