From 42d6205e8cb7775a901e280a9984c7c5b7da172a Mon Sep 17 00:00:00 2001 From: Ryan Stein Date: Thu, 9 May 2019 11:11:53 -0400 Subject: Add RegEx substitution testcase and fix relevant docs (cherry picked from commit a31bbb4bd920e28cbb2c737a785e91da5e7a599f) --- main/tests/test_string.cpp | 18 +++++++++++++++--- modules/regex/doc_classes/RegEx.xml | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp index dcbb930d1b..531887a452 100644 --- a/main/tests/test_string.cpp +++ b/main/tests/test_string.cpp @@ -33,6 +33,7 @@ //#include "core/math/math_funcs.h" #include "core/io/ip_address.h" #include "core/os/os.h" +#include "modules/regex/regex.h" #include #include "test_string.h" @@ -429,9 +430,20 @@ bool test_25() { bool test_26() { - //TODO: Do replacement RegEx test - return true; -}; + OS::get_singleton()->print("\n\nTest 26: RegEx substitution\n"); + + 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("(?[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 { char const *data; diff --git a/modules/regex/doc_classes/RegEx.xml b/modules/regex/doc_classes/RegEx.xml index 0538753a47..cc8205e400 100644 --- a/modules/regex/doc_classes/RegEx.xml +++ b/modules/regex/doc_classes/RegEx.xml @@ -123,7 +123,7 @@ - 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<name>[/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. -- cgit v1.2.3