Returns the trailing position number (or zero if no number is present) if NodeName(input_name) is equal to node_name. Returns -1 for control inputs. Returns -2 if input_name is empty or NodeName(input_name) is not equal to node_name.
| 125 | // Returns -2 if input_name is empty or NodeName(input_name) is not equal to |
| 126 | // node_name. |
| 127 | inline int NodePositionIfSameNode(absl::string_view input_name, |
| 128 | absl::string_view node_name) { |
| 129 | bool is_control = absl::StartsWith(input_name, "^"); |
| 130 | if (is_control) input_name.remove_prefix(1); |
| 131 | if (input_name.empty() || node_name.empty() || |
| 132 | input_name.size() < node_name.size()) { |
| 133 | return -2; |
| 134 | } |
| 135 | TensorId id = ParseTensorName(input_name); |
| 136 | if (id.first != node_name) return -2; |
| 137 | if (is_control) return -1; |
| 138 | return id.second; |
| 139 | } |
| 140 | |
| 141 | // Returns the node name and position in a single call. |
| 142 | inline StringPiece ParseNodeNameAsStringPiece(absl::string_view name, |