Merge pull request #28782 from RyanStein/regex_sub_test_docs

Add RegEx substitution testcase and fix relevant docs
This commit is contained in:
Rémi Verschelde 2019-05-11 08:49:41 +02:00 committed by GitHub
commit 7b38442173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -33,6 +33,7 @@
//#include "core/math/math_funcs.h" //#include "core/math/math_funcs.h"
#include "core/io/ip_address.h" #include "core/io/ip_address.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "modules/regex/regex.h"
#include <stdio.h> #include <stdio.h>
#include "test_string.h" #include "test_string.h"
@ -429,9 +430,20 @@ bool test_25() {
bool test_26() { bool test_26() {
//TODO: Do replacement RegEx test OS::get_singleton()->print("\n\nTest 26: RegEx substitution\n");
return true;
}; String s = "Double all the vowels.";
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
OS::get_singleton()->print("\tRepeating instances of 'aeiou' once\n");
RegEx re("(?<vowel>[aeiou])");
s = re.sub(s, "$0$vowel", true);
OS::get_singleton()->print("\tResult: %ls\n", s.c_str());
return (s == "Doouublee aall thee vooweels.");
}
struct test_27_data { struct test_27_data {
char const *data; char const *data;

View File

@ -123,7 +123,7 @@
<argument index="4" name="end" type="int" default="-1"> <argument index="4" name="end" type="int" default="-1">
</argument> </argument>
<description> <description>
Searches the text for the compiled pattern and replaces it with the specified string. Escapes and backreferences such as [code]\1[/code] and [code]\g&lt;name&gt;[/code] expanded and resolved. By default only the first instance is replaced but it can be changed for all instances (global replacement). The region to search within can be specified without modifying where the start and end anchor would be. Searches the text for the compiled pattern and replaces it with the specified string. Escapes and backreferences such as [code]$1[/code] and [code]$name[/code] are expanded and resolved. By default only the first instance is replaced but it can be changed for all instances (global replacement). The region to search within can be specified without modifying where the start and end anchor would be.
</description> </description>
</method> </method>
</methods> </methods>