Skip to content

Commit 1216a2a

Browse files
committed
import is_uprop parrot op from rakudo ng
1 parent 14a9298 commit 1216a2a

File tree

1 file changed

+89
-1
lines changed

1 file changed

+89
-1
lines changed

src/ops/nqp.ops

100644100755
Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,4 +1792,92 @@ inline op nqp_radix(out PMC, in INT, in STR, in INT, in INT) :base_core {
17921792
$1 = out;
17931793
}
17941794

1795-
1795+
/*
1796+
1797+
=item inline op is_uprop(out INT, in STR, in STR, in INT)
1798+
1799+
Sets a true value in $1 if character $4 in string $3 has the unicode property
1800+
named $2.
1801+
1802+
=cut
1803+
1804+
*/
1805+
inline op is_uprop(out INT, in STR, in STR, in INT) :base_core {
1806+
#if PARROT_HAS_ICU
1807+
char *cstr;
1808+
INTVAL ord;
1809+
int32_t strwhich, ordwhich;
1810+
UProperty strprop;
1811+
opcode_t *handler;
1812+
1813+
if ($4 > 0 && (UINTVAL)$4 == ($3->strlen)) {
1814+
$1 = 0;
1815+
goto NEXT();
1816+
}
1817+
1818+
ord = Parrot_str_indexed(interp, $3, $4);
1819+
cstr = Parrot_str_to_cstring(interp, $2);
1820+
1821+
/* try block tests */
1822+
if (strncmp(cstr, "In", 2) == 0) {
1823+
strwhich = u_getPropertyValueEnum(UCHAR_BLOCK, cstr+2);
1824+
ordwhich = u_getIntPropertyValue(ord, UCHAR_BLOCK);
1825+
if (strwhich != UCHAR_INVALID_CODE) {
1826+
$1 = (strwhich == ordwhich);
1827+
Parrot_str_free_cstring(cstr);
1828+
goto NEXT();
1829+
}
1830+
}
1831+
1832+
/* try bidi tests */
1833+
if (strncmp(cstr, "Bidi", 4) == 0) {
1834+
strwhich = u_getPropertyValueEnum(UCHAR_BIDI_CLASS, cstr+4);
1835+
ordwhich = u_getIntPropertyValue(ord, UCHAR_BIDI_CLASS);
1836+
if (strwhich != UCHAR_INVALID_CODE) {
1837+
$1 = (strwhich == ordwhich);
1838+
Parrot_str_free_cstring(cstr);
1839+
goto NEXT();
1840+
}
1841+
}
1842+
1843+
/* try property value aliases */
1844+
strwhich = u_getPropertyValueEnum(UCHAR_GENERAL_CATEGORY_MASK, cstr);
1845+
if (strwhich != UCHAR_INVALID_CODE) {
1846+
ordwhich = u_getIntPropertyValue(ord, UCHAR_GENERAL_CATEGORY_MASK);
1847+
$1 = ((strwhich & ordwhich) != 0);
1848+
Parrot_str_free_cstring(cstr);
1849+
goto NEXT();
1850+
}
1851+
1852+
/* try property */
1853+
strprop = u_getPropertyEnum(cstr);
1854+
if (strprop != UCHAR_INVALID_CODE) {
1855+
$1 = (u_hasBinaryProperty(ord, strprop) != 0);
1856+
Parrot_str_free_cstring(cstr);
1857+
goto NEXT();
1858+
}
1859+
1860+
/* try script aliases */
1861+
strwhich = u_getPropertyValueEnum(UCHAR_SCRIPT, cstr);
1862+
if (strwhich != UCHAR_INVALID_CODE) {
1863+
ordwhich = u_getIntPropertyValue(ord, UCHAR_SCRIPT);
1864+
$1 = (strwhich == ordwhich);
1865+
Parrot_str_free_cstring(cstr);
1866+
goto NEXT();
1867+
}
1868+
1869+
/* unrecognized property name */
1870+
Parrot_str_free_cstring(cstr);
1871+
handler = Parrot_ex_throw_from_op_args(interp, NULL,
1872+
EXCEPTION_ICU_ERROR,
1873+
"Unicode property '%Ss' not found", $2);
1874+
goto ADDRESS(handler);
1875+
#else
1876+
opcode_t * const handler = Parrot_ex_throw_from_op_args(interp, NULL,
1877+
EXCEPTION_ICU_ERROR,
1878+
"ICU not loaded", $2);
1879+
goto ADDRESS(handler);
1880+
#endif
1881+
}
1882+
1883+

0 commit comments

Comments
 (0)