-
Notifications
You must be signed in to change notification settings - Fork 112
[k2] fix preg_replace function #1464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f6a626d
split tests
Shamzik c7c6dac
fix preg_replace function
Shamzik bf2a142
inline value_or_else
Shamzik e7f2019
unescaper -> decoder, escaper -> encoder
Shamzik 82b645f
unescaper -> decoder, escaper -> encoder
Shamzik 9352ec8
decode -> parse, encode -> format
Shamzik 0cb923b
inline pcre2_replacement_formatter
Shamzik 4b43180
explicit noexcept preg_replacement_parser constructor
Shamzik f925e7e
remove std::move
Shamzik 7543b22
rewrite preg_replacement_parser as range
Shamzik fed3f76
use std::isdigit
Shamzik ba98c71
add assertion
Shamzik e3309d6
using backref = std::string_view;
Shamzik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| @ok callback benchmark k2_skip | ||
| <?php | ||
|
|
||
| define('RE_URL_PATTERN', '(?<![A-Za-z\$0-9À-ßà-ÿ¸¨\-\_])(https?:\/\/)?((?:[A-Za-z\$0-9À-ßà-ÿ¸¨](?:[A-Za-z\$0-9\-\_À-ßà-ÿ¸¨]*[A-Za-z\$0-9À-ßà-ÿ¸¨])?\.){1,5}[A-Za-z\$ðôóêÐÔÓÊ\-\d]{2,22}(?::\d{2,5})?)((?:\/(?:(?:\&|\!|,[_%]|[A-Za-z0-9\xa8\xb8\xc0-\xffºª¥´¯¿²³\-\_#%?+\/\$.~=;:]+|\[[A-Za-z0-9\xa8\xb8\xc0-\xffºª¥´¯¿²³\-\_#%?+\/\$.,~=;:]*\]|\([A-Za-z0-9\xa8\xb8\xc0-\xffºª¥´¯¿²³\-\_#%?+\/\$.,~=;:]*\))*(?:,[_%]|[A-Za-z0-9\xa8\xb8\xc0-\xffºª¥´¯¿\-\_#%?+\/\$.~=;:]*[A-Za-z0-9\xa8\xb8\xc0-\xffºª¥´¯¿²³\_#%?+\/\$~=]|\[[A-Za-z0-9\xa8\xb8\xc0-\xffºª¥´¯¿²³\-\_#%?+\/\$.,~=;:]*\]|\([A-Za-z0-9\xa8\xb8\xc0-\xffºª¥´¯¿²³\-\_#%?+\/\$.,~=;:]*\)))?)?)'); | ||
|
|
||
| $text = 'ß ñëûøàë, ÷òî â iOS 7 ïîÿâèëèñü ëîêàëüíûå ïóø-óâåäîìëåíèÿ. Íî òóò http://blog.derand.net/2010/08/local-notifications-ios-40.html óòâåðæäàåòñÿ, ÷òî åùå â ÷åòâåðòîé.'; | ||
| $text = preg_replace_callback('/'.RE_URL_PATTERN.'/', 'prcConvertHyperref', $text); | ||
|
|
||
| /** | ||
| * @kphp-required | ||
| * @param string[] $matches | ||
| * @return string | ||
| */ | ||
| function prcConvertHyperref($matches) { | ||
| return (string)preg_match('/\.([a-zA-ZðôóêÐÔÓÊ\-0-9]+)$/', $matches[2], $match); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @kphp-required | ||
| * @param string[] $param | ||
| * @return string | ||
| */ | ||
| function cb($param) { | ||
| var_dump($param); | ||
| return "yes!"; | ||
| } | ||
|
|
||
|
|
||
| $input = "plain [indent] deep [indent] [abcd]deeper[/abcd] [/indent] deep [/indent] plain"; | ||
|
|
||
| /** | ||
| * @param mixed $input | ||
| * @return string | ||
| */ | ||
| function parseTagsRecursive($input) | ||
| { | ||
| global $count; | ||
| $regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#'; | ||
| var_dump ($input); | ||
|
|
||
| if (is_array($input)) { | ||
| $input = '<div style="margin-left: 10px">'.$input[1].'</div>'; | ||
| } | ||
|
|
||
|
|
||
| $res = preg_replace_callback($regex, 'parseTagsRecursive', $input, -1, $count); | ||
| var_dump ($count); | ||
| return (string)$res; | ||
|
|
||
| } | ||
|
|
||
| $output = parseTagsRecursive($input); | ||
|
|
||
| echo $output, "\n"; | ||
|
|
||
|
|
||
| /** | ||
| * @kphp-required | ||
| * @param string[] $x | ||
| * @return string | ||
| */ | ||
| function g($x) { | ||
| return "'{$x[0]}'"; | ||
| } | ||
|
|
||
| var_dump(preg_replace_callback('@\b\w{1,2}\b@', 'g', array('a b3 bcd', 'v' => 'aksfjk', 12 => 'aa bb'))); | ||
|
|
||
| @var_dump(preg_replace_callback('~\A.~', 'g', array(array('xyz')))); | ||
|
|
||
| /** | ||
| * @kphp-required | ||
| * @param string[] $m | ||
| * @return string | ||
| */ | ||
| function tmp($m) { | ||
| return strtolower($m[0]); | ||
| } | ||
|
|
||
| var_dump(preg_replace_callback('~\A.~', 'tmp', 'ABC')); | ||
|
|
||
| var_dump(preg_replace_callback("/(ab)(cd)(e)/", "cb", 'abcde')); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.