|
52 | 52 |
|
53 | 53 | import com.oracle.graal.python.builtins.objects.module.PythonModule;
|
54 | 54 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
| 55 | +import com.oracle.graal.python.nodes.util.CannotCastException; |
55 | 56 | import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
|
56 | 57 | import com.oracle.truffle.api.strings.TruffleString.CodePointAtByteIndexNode;
|
57 | 58 | import com.oracle.truffle.api.strings.TruffleString.CodePointLengthNode;
|
@@ -333,6 +334,32 @@ protected ArgumentClinicProvider getArgumentClinic() {
|
333 | 334 | }
|
334 | 335 | }
|
335 | 336 |
|
| 337 | + // unicodedata.combining(chr) |
| 338 | + @Builtin(name = "combining", minNumOfPositionalArgs = 1, numOfPositionalOnlyArgs = 1, parameterNames = {"chr"}) |
| 339 | + @GenerateNodeFactory |
| 340 | + public abstract static class CombiningNode extends PythonUnaryBuiltinNode { |
| 341 | + |
| 342 | + @Specialization |
| 343 | + @TruffleBoundary |
| 344 | + static Object combining(Object object, |
| 345 | + @Bind Node inliningTarget) { |
| 346 | + final TruffleString chr; |
| 347 | + |
| 348 | + try { |
| 349 | + chr = CastToTruffleStringNode.getUncached().execute(inliningTarget, object); |
| 350 | + } catch (CannotCastException e) { |
| 351 | + throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.S_ARG_MUST_BE_S_NOT_P, "combining()", "a unicode character", object); |
| 352 | + } |
| 353 | + |
| 354 | + if (CodePointLengthNode.getUncached().execute(chr, TS_ENCODING) != 1) { |
| 355 | + throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.S_ARG_MUST_BE_S_NOT_P, "combining()", "a unicode character", object); |
| 356 | + } |
| 357 | + |
| 358 | + int codepoint = CodePointAtByteIndexNode.getUncached().execute(chr, 0, TS_ENCODING); |
| 359 | + return UCharacter.getCombiningClass(codepoint); |
| 360 | + } |
| 361 | + } |
| 362 | + |
336 | 363 | // unicode.east_asia_width(chr)
|
337 | 364 | @Builtin(name = "east_asian_width", minNumOfPositionalArgs = 1, numOfPositionalOnlyArgs = 1, parameterNames = {"chr"})
|
338 | 365 | @GenerateNodeFactory
|
|
0 commit comments