User:Belove/AOM Sample Rename Patterns: Difference between revisions
Jump to navigation
Jump to search
(→AOM Sample Rename Patterns: new section) |
|||
Line 15: | Line 15: | ||
// working.) | // working.) | ||
function('replacerepeat_', _ | function('replacerepeat_', _ | ||
set('replacerepeat_new_text', _ | |||
replace(param1, param2, param3) _ | replace(param1, param2, param3) _ | ||
) + _ | ) + _ | ||
Line 33: | Line 33: | ||
| <pre>replacerepeat_('[1 2 5 8 ]', ' ', ' ')</pre> || <pre>[1 2 5 8 ]</pre> | | <pre>replacerepeat_('[1 2 5 8 ]', ' ', ' ')</pre> || <pre>[1 2 5 8 ]</pre> | ||
|} | |} | ||
=== replacegreedy() / replacegreedyi() === | === replacegreedy() / replacegreedyi() === |
Revision as of 21:05, 17 January 2016
AOM Sample Rename Patterns
Tested with AOM 0.5.18.276
replacerepeat_()
Recursive replacement for replacerepeat()
replacerepeat_(text, find, replace)
// replacerepeat_(text, find, replace) // -- Repeatedly replaces 'find' in 'text' with 'replace', until 'text' // stops changing. (Substitutes for built-in replacerepeat(), which is not // working.) function('replacerepeat_', _ set('replacerepeat_new_text', _ replace(param1, param2, param3) _ ) + _ if(replacerepeat_new_text<>param1, _ replacerepeat_(replacerepeat_new_text, param2, param3), _ replacerepeat_new_text _ ) _ )
Example usage | Output |
---|---|
replacerepeat_('1a2aa5aaaaa8aAaAaAaA', 'aa', 'a') |
1a2a5a8aAaAaAaA |
replacerepeat_('[1 2 5 8 ]', ' ', ' ') |
[1 2 5 8 ] |
replacegreedy() / replacegreedyi()
Non-recursive, single-pass replacements for replacerepeat().
replacegreedy(text, find, replace)
replacegreedyi(text, find, replace) case-insensitive version
// replacegreedy(text, find, replace) // -- Replaces all occurrences of 'find' in 'text' with 'replace' using a // rolling window approach that results in the replacement of occurrences // that existed in the original text (like the built-in replace() function) // as well as any new occurrences that emerge as a result of the // replacements made. (Substitutes for built-in replacerepeat(), which is // not working.) function('replacegreedy', _ set('replacegreedy_casesensitive', True) + _ replacegreedy_internal(param1, param2, param3) _ ) // replacegreedyi(text, find, replace) // -- Case-insensitive version of replacegreedy() function('replacegreedyi', _ set('replacegreedy_casesensitive', False) + _ replacegreedy_internal(param1, param2, param3) _ ) // replacegreedy_internal(text, find, replace) // -- Do not call directly; called from replacegreedy() / replacegreedyi() function('replacegreedy_internal', _ set('replacegreedy_text_len', length(param1)) + _ set('replacegreedy_find_len', length(param2)) + _ if((replacegreedy_text_len < replacegreedy_find_len) OR (replacegreedy_text_len = 0), _ param1, _ set('replacegreedy_new_text', limit(param1, 1)) + _ for('replacegreedy_text_pos', replacegreedy_find_len, replacegreedy_text_len, _ set('replacegreedy_new_text', _ replacegreedy_new_text + _ copy(param1, replacegreedy_text_pos, 1) _ ) + _ set('replacegreedy_text_found', _ copy(replacegreedy_new_text, _ (length(replacegreedy_new_text) - replacegreedy_find_len) + 1, _ replacegreedy_find_len _ ) _ ) + _ if(if(replacegreedy_casesensitive, _ start(replacegreedy_text_found, param2), _ starti(replacegreedy_text_found, param2) _ ), _ set('replacegreedy_new_text_len', length(replacegreedy_new_text)) + _ set('replacegreedy_new_text', _ if(replacegreedy_new_text_len <> replacegreedy_find_len, _ limit(replacegreedy_new_text, _ replacegreedy_new_text_len - replacegreedy_find_len _ ) + param3, _ replacegreedy_text_found _ ) _ ) _ ) _ ) + _ replacegreedy_new_text _ ) _ )
Example usage | Output |
---|---|
replacegreedy('1a2aa5aaaaa8aAaAaAaA', 'aa', 'a') |
1a2a5a8aAaAaAaA |
replacegreedyi('1a2aa5aaaaa8aAaAaAaA', 'aa', 'a') |
1a2a5a8a |
replacegreedy('[1 2 5 8 ]', ' ', ' ') |
[1 2 5 8 ] |