Interns strings to eliminate duplicates and to refer to them as numbers. Args: a_string: the string to be interned Returns: The string id, a negative number -1 to -MAXINT.
(self, a_string)
| 130 | self.string_id_by_interned_string_ = {} |
| 131 | |
| 132 | def InternString(self, a_string): |
| 133 | """Interns strings to eliminate duplicates and to refer to them as numbers. |
| 134 | |
| 135 | Args: |
| 136 | a_string: the string to be interned |
| 137 | Returns: |
| 138 | The string id, a negative number -1 to -MAXINT. |
| 139 | """ |
| 140 | string_id = self.string_id_by_interned_string_.get(a_string, 0) |
| 141 | if string_id != 0: |
| 142 | return string_id |
| 143 | self.interned_strings_.append(a_string) |
| 144 | string_id = -len(self.interned_strings_) |
| 145 | self.string_id_by_interned_string_[a_string] = string_id |
| 146 | return string_id |
| 147 | |
| 148 | def InternedStrings(self): |
| 149 | """The interned strings which will be emitted into validator-generated.js. |
no test coverage detected