|
16 | 16 |
|
17 | 17 | package com.github.simy4.coregex.core; |
18 | 18 |
|
| 19 | +import java.lang.invoke.MethodHandle; |
| 20 | +import java.lang.invoke.MethodHandles; |
| 21 | +import java.lang.invoke.MethodType; |
19 | 22 | import java.util.ArrayList; |
20 | 23 | import java.util.Arrays; |
21 | 24 | import java.util.List; |
@@ -600,6 +603,17 @@ private static final class Context { |
600 | 603 | private static final char SKIP = '\u0000'; |
601 | 604 | private static final char EOF = '\uFFFF'; |
602 | 605 |
|
| 606 | + private static final MethodHandle CHARACTER_CODE_POINT_OF; |
| 607 | + static { |
| 608 | + MethodHandle codePointOf = null; |
| 609 | + try { |
| 610 | + codePointOf = MethodHandles.lookup().findStatic(Character.class, "codePointOf", MethodType.methodType(int.class, String.class)); |
| 611 | + } catch (Exception ignored) { |
| 612 | + } finally { |
| 613 | + CHARACTER_CODE_POINT_OF = codePointOf; |
| 614 | + } |
| 615 | + } |
| 616 | + |
603 | 617 | private final String regex; |
604 | 618 | private final char[] tokens = {SKIP, SKIP, SKIP, SKIP}; |
605 | 619 | private int flags, groupIndex, cursor, tokensCursor; |
@@ -698,13 +712,21 @@ private char token() { |
698 | 712 | ch = chars[0]; |
699 | 713 | break loop; |
700 | 714 | case 'N': |
| 715 | + if (null == CHARACTER_CODE_POINT_OF) { |
| 716 | + break; |
| 717 | + } |
701 | 718 | start = cursor += 3; |
702 | 719 | while ('}' != regex.charAt(cursor)) { |
703 | 720 | cursor++; |
704 | 721 | } |
705 | | - chars = Character.toChars(Character.codePointOf(regex.substring(start, cursor))); |
706 | | - System.arraycopy(chars, 0, tokens, tokensCursor, chars.length); |
707 | | - ch = chars[0]; |
| 722 | + try { |
| 723 | + chars = Character.toChars((int) CHARACTER_CODE_POINT_OF.invoke(regex.substring(start, cursor))); |
| 724 | + System.arraycopy(chars, 0, tokens, tokensCursor, chars.length); |
| 725 | + ch = chars[0]; |
| 726 | + } catch (Throwable t) { |
| 727 | + //noinspection DataFlowIssue |
| 728 | + throw (RuntimeException) t; |
| 729 | + } |
708 | 730 | break; |
709 | 731 | case 'u': |
710 | 732 | String u = regex.substring(cursor + 2, cursor + 6); |
|
0 commit comments