diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2022-10-28 13:38:46 -0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2022-11-06 17:22:00 +0200 |
commit | a6db624aada29e0e11e7e0297d6310413dd1f8f9 (patch) | |
tree | c7f6d67a5160ff89b9c5a4ee07c818900104a102 /mesonbuild | |
parent | 8abbcf78870c350cd9ff43f65d89e7e998d50448 (diff) | |
download | meson-a6db624aada29e0e11e7e0297d6310413dd1f8f9.zip meson-a6db624aada29e0e11e7e0297d6310413dd1f8f9.tar.gz meson-a6db624aada29e0e11e7e0297d6310413dd1f8f9.tar.bz2 |
Implement `in` operator on string
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/interpreter/primitives/string.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/mesonbuild/interpreter/primitives/string.py b/mesonbuild/interpreter/primitives/string.py index 0c635a2..d8133c1 100644 --- a/mesonbuild/interpreter/primitives/string.py +++ b/mesonbuild/interpreter/primitives/string.py @@ -64,6 +64,8 @@ class StringHolder(ObjectHolder[str]): self.operators.update({ MesonOperator.DIV: self.op_div, MesonOperator.INDEX: self.op_index, + MesonOperator.IN: self.op_in, + MesonOperator.NOT_IN: self.op_notin, }) def display_name(self) -> str: @@ -173,6 +175,16 @@ class StringHolder(ObjectHolder[str]): except IndexError: raise InvalidArguments(f'Index {other} out of bounds of string of size {len(self.held_object)}.') + @FeatureNew('"in" string operator', '0.64.0') + @typed_operator(MesonOperator.IN, str) + def op_in(self, other: str) -> bool: + return other in self.held_object + + @FeatureNew('"not in" string operator', '0.64.0') + @typed_operator(MesonOperator.NOT_IN, str) + def op_notin(self, other: str) -> bool: + return other not in self.held_object + class MesonVersionString(str): pass |