diff options
author | Rickard Green <[email protected]> | 2019-06-18 22:31:20 +0200 |
---|---|---|
committer | Rickard Green <[email protected]> | 2019-06-18 22:31:20 +0200 |
commit | 413d6d694eaf7530fd10bdc4dcafa4c7efa24e3e (patch) | |
tree | cf981e5507f36e31ad5cea0f32a9782b52615f0c /erts/emulator/pcre/pcre_valid_utf8.c | |
parent | 272ee2d47e7c648a1c5987429053d7a3ee208716 (diff) | |
parent | 6cae8e7a45970ceb7fb1dd5bf974bf9ebe26144f (diff) | |
download | otp-413d6d694eaf7530fd10bdc4dcafa4c7efa24e3e.tar.gz otp-413d6d694eaf7530fd10bdc4dcafa4c7efa24e3e.tar.bz2 otp-413d6d694eaf7530fd10bdc4dcafa4c7efa24e3e.zip |
Merge branch 'rickard/re-yield-unicode-validation/OTP-15836/ERL-876' into rickard/re-unicode-validation/OTP-15831/OTP-15836/ERL-876
* rickard/re-yield-unicode-validation/OTP-15836/ERL-876:
Update runtime dependency from stdlib to erts
Yield when validating UTF8 for long subject in re:run()
Add yield_on_subject_validation() test
Diffstat (limited to 'erts/emulator/pcre/pcre_valid_utf8.c')
-rw-r--r-- | erts/emulator/pcre/pcre_valid_utf8.c | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/erts/emulator/pcre/pcre_valid_utf8.c b/erts/emulator/pcre/pcre_valid_utf8.c index 516d8f4725..1dc1f9ba0c 100644 --- a/erts/emulator/pcre/pcre_valid_utf8.c +++ b/erts/emulator/pcre/pcre_valid_utf8.c @@ -107,19 +107,80 @@ Returns: = 0 if the string is a valid UTF-8 string int PRIV(valid_utf)(PCRE_PUCHAR string, int length, int *erroroffset) { + +#if defined(ERLANG_INTEGRATION) + return PRIV(yielding_valid_utf)(string, length, erroroffset, NULL); +} + +int +PRIV(yielding_valid_utf)(PCRE_PUCHAR string, int length, int *erroroffset, struct PRIV(valid_utf_ystate) *ystate) +{ +#endif + #ifdef SUPPORT_UTF register PCRE_PUCHAR p; +#if defined(ERLANG_INTEGRATION) +register long cnt; + +if (!ystate) { + cnt = -1; +} +else { + cnt = ystate->cnt; + if (ystate->yielded) { + p = ystate->p; + length = ystate->length; + if (length < 0) + goto restart_length; + else + goto restart_validate; + } +} +#endif + if (length < 0) { - for (p = string; *p != 0; p++); - length = (int)(p - string); + for (p = string; *p != 0; p++) { +#if defined(ERLANG_INTEGRATION) + if (cnt > 0 && --cnt == 0) { + /* + * Return with cnt set to amount consumed; + * i.e. same amount as at start... + */ + ystate->yielded = !0; + ystate->length = length; + ystate->p = p; + return PCRE_UTF8_YIELD; + } + restart_length: + (void) !0; +#endif + } + length = (int)(p - string); } for (p = string; length-- > 0; p++) { register pcre_uchar ab, c, d; +#if defined(ERLANG_INTEGRATION) + + if (cnt > 0 && --cnt == 0) { + /* + * Return with cnt set to amount consumed; + * i.e. same amount as at start... + */ + ystate->yielded = !0; + ystate->length = length; + ystate->p = p; + return PCRE_UTF8_YIELD; + } + + restart_validate: + +#endif + c = *p; if (c < 128) continue; /* ASCII character */ @@ -290,6 +351,14 @@ for (p = string; length-- > 0; p++) } } +#if defined(ERLANG_INTEGRATION) +if (ystate) { + /* Return with cnt set to amount consumed... */ + ystate->cnt -= cnt; + ystate->yielded = 0; +} +#endif + #else /* Not SUPPORT_UTF */ (void)(string); /* Keep picky compilers happy */ (void)(length); |