Skip to content

Commit be810e6

Browse files
committed
add str.isascii
1 parent 0eb1bdb commit be810e6

File tree

1 file changed

+14
-0
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str

1 file changed

+14
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.nio.CharBuffer;
5555
import java.nio.charset.CharacterCodingException;
5656
import java.nio.charset.Charset;
57+
import java.nio.charset.CharsetEncoder;
5758
import java.nio.charset.CodingErrorAction;
5859
import java.nio.charset.IllegalCharsetNameException;
5960
import java.nio.charset.UnsupportedCharsetException;
@@ -1606,6 +1607,19 @@ Object doGeneric(VirtualFrame frame, String left, Object right,
16061607
}
16071608
}
16081609

1610+
@Builtin(name = "isascii", minNumOfPositionalArgs = 1)
1611+
@GenerateNodeFactory
1612+
@TypeSystemReference(PythonArithmeticTypes.class)
1613+
abstract static class IsAsciiNode extends PythonUnaryBuiltinNode {
1614+
private static final CharsetEncoder asciiEncoder = Charset.forName("US-ASCII").newEncoder();
1615+
1616+
@Specialization
1617+
@TruffleBoundary
1618+
boolean doString(String self) {
1619+
return asciiEncoder.canEncode(self);
1620+
}
1621+
}
1622+
16091623
@Builtin(name = "isalnum", minNumOfPositionalArgs = 1)
16101624
@GenerateNodeFactory
16111625
@TypeSystemReference(PythonArithmeticTypes.class)

0 commit comments

Comments
 (0)