:CreateTestArray function for making array of random strings with lots of options

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
shodan
Posts: 89
Joined: 01 May 2023 01:49

:CreateTestArray function for making array of random strings with lots of options

#1 Post by shodan » 09 Jun 2024 23:06

Here is a visual demo of running this function

https://youtu.be/bs8lVi1q9-0

Here is the full test file
GetSubstringIndex-DEMO.zip
(11.34 KiB) Downloaded 4572 times
Here is the code to make these test arrays

Code: Select all

call :CreateTestArray OutputArray 100 "All F base array, all G delimiter"                                                                                               "OVERRIDE 70" 100                           Delimiter "OVERRIDE 71" 10
call :CreateTestArray OutputArray 100 "All F base array, alphanumeric delimiter"                                                                                        "OVERRIDE 70" 100                           Delimiter "" 10
call :CreateTestArray OutputArray 100 "All F base array, with punctuation and space"                                                                                    "OVERRIDE 70" 100                           Delimiter "PUNCTUATION NOPOISON SPACE" 10
call :CreateTestArray OutputArray 100 "All F base array, with punctuation and space and extended"                                                                       "OVERRIDE 70" 100                           Delimiter "PUNCTUATION NOPOISON SPACE EXTENDED" 10
call :CreateTestArray OutputArray 100 "All F base array, with punctuation and space and extended and poison"                                                            "OVERRIDE 70" 100                           Delimiter "PUNCTUATION SPACE EXTENDED" 10

call :CreateTestArray OutputArray 100 "Alphanumeric base array, all G delimiter"                                                                                        "" 100                                      Delimiter "OVERRIDE 71" 10
call :CreateTestArray OutputArray 100 "Alphanumeric base array, alphanumeric delimiter"                                                                                 "" 100                                      Delimiter "" 10
call :CreateTestArray OutputArray 100 "Alphanumeric base array, with punctuation and space"                                                                             "" 100                                      Delimiter "PUNCTUATION NOPOISON SPACE" 10
call :CreateTestArray OutputArray 100 "Alphanumeric base array, with punctuation and space and extended"                                                                "" 100                                      Delimiter "PUNCTUATION NOPOISON SPACE EXTENDED" 10
call :CreateTestArray OutputArray 100 "Alphanumeric base array, with punctuation and space and extended and poison"                                                     "" 100                                      Delimiter "PUNCTUATION SPACE EXTENDED" 10

call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space base array, all G delimiter"                                                             "PUNCTUATION NOPOISON SPACE" 100            Delimiter "OVERRIDE 71" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space base array, alphanumeric delimiter"                                                      "PUNCTUATION NOPOISON SPACE" 100            Delimiter "" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space base array, with punctuation and space"                                                  "PUNCTUATION NOPOISON SPACE" 100            Delimiter "PUNCTUATION NOPOISON SPACE" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space base array, with punctuation and space and extended"                                     "PUNCTUATION NOPOISON SPACE" 100            Delimiter "PUNCTUATION NOPOISON SPACE EXTENDED" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space base array, with punctuation and space and extended and poison"                          "PUNCTUATION NOPOISON SPACE" 100            Delimiter "PUNCTUATION SPACE EXTENDED" 10
:GetSubstringIndex-demo-skip
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space and extended base array, all G delimiter"                                                "PUNCTUATION NOPOISON SPACE EXTENDED" 100   Delimiter "OVERRIDE 71" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space and extended base array, alphanumeric delimiter"                                         "PUNCTUATION NOPOISON SPACE EXTENDED" 100   Delimiter "" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space and extended base array, with punctuation and space"                                     "PUNCTUATION NOPOISON SPACE EXTENDED" 100   Delimiter "PUNCTUATION NOPOISON SPACE" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space and extended base array, with punctuation and space and extended"                        "PUNCTUATION NOPOISON SPACE EXTENDED" 100   Delimiter "PUNCTUATION NOPOISON SPACE EXTENDED" 10

call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space and extended and poison base array, all G delimiter"                                     "PUNCTUATION SPACE EXTENDED" 100            Delimiter "OVERRIDE 71" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space and extended and poison base array, alphanumeric delimiter"                              "PUNCTUATION SPACE EXTENDED" 100            Delimiter "" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space and extended and poison base array, with punctuation and space"                          "PUNCTUATION SPACE EXTENDED" 100            Delimiter "PUNCTUATION NOPOISON SPACE" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space and extended and poison base array, with punctuation and space and extended"             "PUNCTUATION SPACE EXTENDED" 100            Delimiter "PUNCTUATION NOPOISON SPACE EXTENDED" 10

call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space and extended base array, with punctuation and space and extended and poison"             "PUNCTUATION NOPOISON SPACE EXTENDED" 100   Delimiter "PUNCTUATION SPACE EXTENDED" 10
call :CreateTestArray OutputArray 100 "Alphanumeric with punctuation and space and extended and poison base array, with punctuation and space and extended and poison"  "PUNCTUATION SPACE EXTENDED" 100            Delimiter "PUNCTUATION SPACE EXTENDED" 10

:GetSubstringIndex-1-skip
REM GoTo :GetSubstringIndex-2-skip

call :CreateTestArray OutputArray 100 "1 All F base array, all G delimiter"                                                                                               "OVERRIDE 70" 100                            Delimiter "OVERRIDE 71" 10                               Delimiter INVERTPOSITION "OVERRIDE 80" 10
call :CreateTestArray OutputArray 100 "2 All F base array, alphanumeric delimiter"                                                                                        "OVERRIDE 70" 100                            Delimiter "" 10                                          Delimiter INVERTPOSITION "OVERRIDE 80" 10
call :CreateTestArray OutputArray 100 "3 All F base array, with punctuation and space"                                                                                    "OVERRIDE 70" 100                            Delimiter "PUNCTUATION NOPOISON SPACE" 10                Delimiter INVERTPOSITION "OVERRIDE 80" 10  
call :CreateTestArray OutputArray 100 "4 All F base array, with punctuation and space and extended"                                                                       "OVERRIDE 70" 100                            Delimiter "PUNCTUATION NOPOISON SPACE EXTENDED" 10       Delimiter INVERTPOSITION "OVERRIDE 80" 10  
call :CreateTestArray OutputArray 100 "5 All F base array, with punctuation and space and extended and poison"                                                            "OVERRIDE 70" 100                            Delimiter "PUNCTUATION SPACE EXTENDED" 10                Delimiter INVERTPOSITION "OVERRIDE 80" 10 

call :CreateTestArray OutputArray 100 "6 Alphanumeric  base array, all G delimiter"                                                                                       "" 100                                       Delimiter "OVERRIDE 71" 10                               Delimiter INVERTPOSITION "OVERRIDE 80" 10  
call :CreateTestArray OutputArray 100 "7 Alphanumeric  base array, alphanumeric delimiter"                                                                                "" 100                                       Delimiter "" 10                                          Delimiter INVERTPOSITION "OVERRIDE 80" 10  
call :CreateTestArray OutputArray 100 "8 Alphanumeric  base array, with punctuation and space"                                                                            "" 100                                       Delimiter "PUNCTUATION NOPOISON SPACE" 10                Delimiter INVERTPOSITION "OVERRIDE 80" 10  
call :CreateTestArray OutputArray 100 "9 Alphanumeric  base array, with punctuation and space and extended"                                                               "" 100                                       Delimiter "PUNCTUATION NOPOISON SPACE EXTENDED" 10       Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "10 Alphanumeric  base array, with punctuation and space and extended and poison"                                                    "" 100                                       Delimiter "PUNCTUATION SPACE EXTENDED" 10                Delimiter INVERTPOSITION "OVERRIDE 80" 10 

call :CreateTestArray OutputArray 100 "11 Alphanumeric with punctuation and space base array, all G delimiter"                                                             "PUNCTUATION NOPOISON SPACE" 100             Delimiter "OVERRIDE 71" 10                               Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "12 Alphanumeric with punctuation and space base array, alphanumeric delimiter"                                                      "PUNCTUATION NOPOISON SPACE" 100             Delimiter "" 10                                          Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "13 Alphanumeric with punctuation and space base array, with punctuation and space"                                                  "PUNCTUATION NOPOISON SPACE" 100             Delimiter "PUNCTUATION NOPOISON SPACE" 10                Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "14 Alphanumeric with punctuation and space base array, with punctuation and space and extended"                                     "PUNCTUATION NOPOISON SPACE" 100             Delimiter "PUNCTUATION NOPOISON SPACE EXTENDED" 10       Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "15 Alphanumeric with punctuation and space base array, with punctuation and space and extended and poison"                          "PUNCTUATION NOPOISON SPACE" 100             Delimiter "PUNCTUATION SPACE EXTENDED" 10                Delimiter INVERTPOSITION "OVERRIDE 80" 10  

call :CreateTestArray OutputArray 100 "16 Alphanumeric with punctuation and space and extended base array, all G delimiter"                                                "PUNCTUATION NOPOISON SPACE EXTENDED" 100    Delimiter "OVERRIDE 71" 10                               Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "17 Alphanumeric with punctuation and space and extended base array, alphanumeric delimiter"                                         "PUNCTUATION NOPOISON SPACE EXTENDED" 100    Delimiter "" 10                                          Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "18 Alphanumeric with punctuation and space and extended base array, with punctuation and space"                                     "PUNCTUATION NOPOISON SPACE EXTENDED" 100    Delimiter "PUNCTUATION NOPOISON SPACE" 10                Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "19 Alphanumeric with punctuation and space and extended base array, with punctuation and space and extended"                        "PUNCTUATION NOPOISON SPACE EXTENDED" 100    Delimiter "PUNCTUATION NOPOISON SPACE EXTENDED" 10       Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "20 Alphanumeric with punctuation and space and extended base array, with punctuation and space and extended and poison"             "PUNCTUATION NOPOISON SPACE EXTENDED" 100    Delimiter "PUNCTUATION SPACE EXTENDED" 10                Delimiter INVERTPOSITION "OVERRIDE 80" 10 

REM PROBLEM BELOW
call :CreateTestArray OutputArray 100 "21 Alphanumeric with punctuation and space and extended and poison base array, all G delimiter"                                     "PUNCTUATION SPACE EXTENDED" 100             Delimiter "OVERRIDE 71" 10                               Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "22 Alphanumeric with punctuation and space and extended and poison base array, alphanumeric delimiter"                              "PUNCTUATION SPACE EXTENDED" 100             Delimiter "" 10                                          Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "23 Alphanumeric with punctuation and space and extended and poison base array, with punctuation and space"                          "PUNCTUATION SPACE EXTENDED" 100             Delimiter "PUNCTUATION NOPOISON SPACE" 10                Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "24 Alphanumeric with punctuation and space and extended and poison base array, with punctuation and space and extended"             "PUNCTUATION SPACE EXTENDED" 100             Delimiter "PUNCTUATION NOPOISON SPACE EXTENDED" 10       Delimiter INVERTPOSITION "OVERRIDE 80" 10 
call :CreateTestArray OutputArray 100 "25 Alphanumeric with punctuation and space and extended and poison base array, with punctuation and space and extended and poison"  "PUNCTUATION SPACE EXTENDED" 100             Delimiter "PUNCTUATION SPACE EXTENDED" 10                Delimiter INVERTPOSITION "OVERRIDE 80" 10 
REM PROBLEM BELOW

:GetSubstringIndex-2-skip
REM GoTo :GetSubstringIndex-3-skip
call :CreateTestArray OutputArray 100 "26 All F base array, multiple delimiters with invertposition and negative indexoffset"                                              "OVERRIDE 70" 100                            Delimiter "OVERRIDE 71" 10                               Delimiter INVERTPOSITION "OVERRIDE 80" 10    Delimiter INVERTPOSITION INDEXOFFSET -15 "OVERRIDE 81" 10        Delimiter INVERTPOSITION INDEXOFFSET -30 "OVERRIDE 82" 10
call :CreateTestArray OutputArray 100 "27 All F base array, all G delimiter repeat 3 times"                                                                                "OVERRIDE 70" 100                            Delimiter REPEAT 3 "OVERRIDE 71" 10
call :CreateTestArray OutputArray 100 "28 All F base array, all G delimiter repeat 5 times"                                                                                "OVERRIDE 70" 100                            Delimiter REPEAT 5 "OVERRIDE 71" 3                       Delimiter INVERTPOSITION "OVERRIDE 80" 3
call :CreateTestArray OutputArray 100 "29 All F base array, all G delimiter, repeat 3 times element offset is 3"                                                           "OVERRIDE 70" 100                            Delimiter REPEAT "3,3" "OVERRIDE 71" 4
call :CreateTestArray OutputArray 100 "30 All F base array, all G delimiter repeated 5 times then all P delimiter, inverted"                                               "OVERRIDE 70" 100                            Delimiter REPEAT "5,3" "OVERRIDE 71" 4                   Delimiter INVERTPOSITION "OVERRIDE 80" 3

Here is the function itself

Code: Select all

::Usage Call :CreateTestArray 
:CreateTestArray
set "_CreateTestArray_prefix=_CTA"
setlocal enabledelayedexpansion
set "_CTA_OutputArray=%~1" & shift
for /f "tokens=1,2 delims=-" %%a in ("%~1") do ( set /a _CTA_Min=%%a & set /a _CTA_Max=%%b 2>nul ) & shift
if not defined _CTA_Max ( set /a _CTA_ActualCount=%_CTA_Min% ) else ( call :rnd _CTA_ActualCount %_CTA_Min% %_CTA_Max% )
set "%_CTA_OutputArray%.comment=%~1" & shift
set /a _CTA_Base.ubound=0 & set /a _CTA_Delimiters.ubound=-1
GoTo :CreateTestArray-base-args
:CreateTestArray-args
if /i "[%~1]" EQU "[BASE]" ( set /a _CTA_Base.ubound+=1 & shift & GoTo :CreateTestArray-base-args )
if /i "[%~1]" EQU "[DELIMITER]" ( set /a _CTA_Delimiters.ubound+=1 & set /a _CTA_Delimiters[!_CTA_Delimiters.ubound!].IndexOffset=0 & set /a _CTA_Delimiters[!_CTA_Delimiters.ubound!].Repeat=0 & shift & GoTo :CreateTestArray-delimiter-args )
GoTo :CreateTestArray-args-skip
:CreateTestArray-base-args
if defined %~1 ( set "_CTA_Base[%_CTA_Base.ubound%]=%~1" & Call :len _CTA_Base[%_CTA_Base%] _CTA_Base[%_CTA_Base%].len & shift & GoTo :CreateTestArray-args )
if /i "[%~1]" EQU "[LITERAL]" ( set "_CTA_Base[%_CTA_Base.ubound%]=%~2" & shift & shift & GoTo :CreateTestArray-args )
for /f "tokens=1,2 delims=-" %%a in ("%~2") do ( set /a _CTA_Min=%%a & set /a _CTA_Max=%%b 2>nul )
if not defined _CTA_Max ( set /a _CTA_Base[%_CTA_Base.ubound%].len=%_CTA_Min% ) else ( call :rnd _CTA_Base[%_CTA_Base.ubound%].len %_CTA_Min% %_CTA_Max% )
Call :CreateRandomStringPS %~1 !_CTA_Base[%_CTA_Base.ubound%].len! _CTA_Base[%_CTA_Base.ubound%] & shift & shift 
if "[%~1]" NEQ "[]" ( GoTo :CreateTestArray-args ) else ( GoTo :CreateTestArray-args-skip )
:CreateTestArray-delimiter-args
if /i "[%~1]" EQU "[INVERTPOSITION]" ( set "_CTA_Delimiters[%_CTA_Delimiters.ubound%].InvertPosition=true" & shift & GoTo :CreateTestArray-delimiter-args )
if /i "[%~1]" EQU "[INDEXOFFSET]" ( set /a "_CTA_Delimiters[%_CTA_Delimiters.ubound%].IndexOffset=%~2" & shift & shift & GoTo :CreateTestArray-delimiter-args )
if /i "[%~1]" EQU "[REPEAT]" ( set "_CTA_Delimiters[%_CTA_Delimiters.ubound%].Repeat=%~2" & shift & shift & GoTo :CreateTestArray-delimiter-args )
if /i "[%~1]" EQU "[LITERAL]" ( set "_CTA_Delimiters[%_CTA_Delimiters.ubound%]=%~2" & shift & shift & GoTo :CreateTestArray-args )
if defined %~1 ( set "_CTA_Delimiters[%_CTA_Delimiters.ubound%]=!%~1!" & Call :len _CTA_Delimiters[%_CTA_Delimiters_ubound%] _CTA_Delimiters[%_CTA_Delimiters.ubound%].len & shift & GoTo :CreateTestArray-args)
if "[!%~1.ubound!]" EQU "[]" GoTo :CreateTestArray-delimiter-array-skip
if defined %~1.ubound ( set /a _CTA_Delimiters.ubound-=1 & for /l %%a in (0,1,!%~1.ubound!) do ( set /a _CTA_Delimiters.ubound+=1 & Call :CopyObject %~1[%%a] _CTA_Delimiters[%_CTA_Delimiters.ubound%] ) )
shift & GoTo :CreateTestArray-args 
:CreateTestArray-delimiter-array-skip
for /f "tokens=1,2 delims=-" %%a in ("%~2") do ( set /a _CTA_Min=%%a & set /a _CTA_Max=%%b 2>nul )
if not defined _CTA_Max ( set /a _CTA_Delimiters[%_CTA_Delimiters.ubound%].len=%_CTA_Min% ) else ( call :rnd _CTA_Delimiters[%_CTA_Delimiters.ubound%].len %_CTA_Min% %_CTA_Max% )
set "_CTA_Delimiters[%_CTA_Delimiters.ubound%].setting=%~1"
Call :CreateRandomStringPS !_CTA_Delimiters[%_CTA_Delimiters.ubound%].setting! !_CTA_Delimiters[%_CTA_Delimiters.ubound%].len! _CTA_Delimiters[%_CTA_Delimiters.ubound%] & shift & shift 
if "[%~1]" NEQ "[]" GoTo :CreateTestArray-args
:CreateTestArray-args-skip
set /a _CTA_index=0
:CreateTestArray-loop
set /a _CTA_Base.index=0
:CreateTestArray-base-loop
set /a _CTA_Delimiters.index=0
set "_CTA_CurrentInputPointer=_CTA_Base[%_CTA_Base.index%]"
:CreateTestArray-delimiter-loop
if defined _CTA_Delimiters[%_CTA_Delimiters.index%].InvertPosition ( set /a _CTA_Delimiter_Position=%_CTA_ActualCount%-%_CTA_index%+!_CTA_Delimiters[%_CTA_Delimiters.index%].IndexOffset!-1 ) else ( set /a _CTA_Delimiter_Position=%_CTA_index%+!_CTA_Delimiters[%_CTA_Delimiters.index%].IndexOffset! )
if %_CTA_Delimiter_Position% LSS 0 GoTo :CreateTestArray-delimiter-loop-skip
Call :ReplaceString %_CTA_CurrentInputPointer% %_CTA_OutputArray%[%_CTA_index%] REPEAT "!_CTA_Delimiters[%_CTA_Delimiters.index%].Repeat!" LEN !_CTA_Delimiters[%_CTA_Delimiters.index%].len! %_CTA_Delimiter_Position% _CTA_Delimiters[%_CTA_Delimiters.index%] 
:CreateTestArray-delimiter-loop-skip
set "_CTA_CurrentInputPointer=%_CTA_OutputArray%[%_CTA_index%]" & set /a _CTA_Delimiters.index+=1
if %_CTA_Delimiters.index% LEQ %_CTA_Delimiters.ubound% GoTo :CreateTestArray-delimiter-loop
set /a _CTA_index+=1
if %_CTA_Base.index% LEQ %_CTA_Base.ubound% ( set /a "_CTA_Base.index+=1" ) else ( set /a "_CTA_Base.index=0" )
if %_CTA_index% LSS %_CTA_ActualCount% GoTo :CreateTestArray-loop
set /a %_CTA_OutputArray%.ubound=%_CTA_ActualCount%
echo !%_CTA_OutputArray%.comment!
Call :EchoArray %_CTA_OutputArray%
for /F "delims=" %%a in ('set %_CTA_OutputArray%') do (
	endlocal
	set "%%a"
	)
Call :ClearVariablesByPrefix %_CreateTestArray_prefix% _CreateTestArray
GoTo :EOF

Post Reply