Skip to content

Commit

Permalink
implement bytearray isdigit()
Browse files Browse the repository at this point in the history
  • Loading branch information
sziraqui committed Mar 6, 2018
1 parent 80c55c8 commit 6ca14b8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions python/common/org/python/types/ByteArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,16 @@ public org.python.Object isalpha() {
@org.python.Method(
__doc__ = "B.isdigit() -> bool\n\nReturn True if all characters in B are digits\nand there is at least one character in B, False otherwise."
)
public org.python.Object isdigit(java.util.List<org.python.Object> args, java.util.Map<java.lang.String, org.python.Object> kwargs, java.util.List<org.python.Object> default_args, java.util.Map<java.lang.String, org.python.Object> default_kwargs) {
throw new org.python.exceptions.NotImplementedError("bytearray.isdigit has not been implemented.");
public org.python.Object isdigit() {
if (this.value.length == 0) {
return new org.python.types.Bool(false);
}
for (byte ch: this.value) {
if (!Bytes._isnum(ch)) {
return new org.python.types.Bool(false);
}
}
return new org.python.types.Bool(true);
}

@org.python.Method(
Expand Down

0 comments on commit 6ca14b8

Please sign in to comment.