diff options
| author | Bond_009 <Bond.009@outlook.com> | 2020-05-27 20:49:18 +0200 |
|---|---|---|
| committer | Bond_009 <Bond.009@outlook.com> | 2020-05-27 20:49:18 +0200 |
| commit | 7439e095e276034f05a0c9e9c7687b4a0aa1b3e5 (patch) | |
| tree | c1c0a8f64157cac9117e3a885f7308802a5a98d8 /windows/helpers/StrSlash.nsh | |
| parent | 27ce10d0c13bc30fa1b08682e13bab67784b289d (diff) | |
| parent | 777c9c7bc974fafb09e6a5a6b23bd29cf8529af9 (diff) | |
Merge branch 'master' into nullable3
Diffstat (limited to 'windows/helpers/StrSlash.nsh')
| -rw-r--r-- | windows/helpers/StrSlash.nsh | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/windows/helpers/StrSlash.nsh b/windows/helpers/StrSlash.nsh new file mode 100644 index 000000000..b8aa771aa --- /dev/null +++ b/windows/helpers/StrSlash.nsh @@ -0,0 +1,47 @@ +; Adapted from: https://nsis.sourceforge.io/Another_String_Replace_(and_Slash/BackSlash_Converter) (2019-08-31) + +!macro _StrSlashConstructor out in + Push "${in}" + Push "\" + Call StrSlash + Pop ${out} +!macroend + +!define StrSlash '!insertmacro "_StrSlashConstructor"' + +; Push $filenamestring (e.g. 'c:\this\and\that\filename.htm') +; Push "\" +; Call StrSlash +; Pop $R0 +; ;Now $R0 contains 'c:/this/and/that/filename.htm' +Function StrSlash + Exch $R3 ; $R3 = needle ("\" or "/") + Exch + Exch $R1 ; $R1 = String to replacement in (haystack) + Push $R2 ; Replaced haystack + Push $R4 ; $R4 = not $R3 ("/" or "\") + Push $R6 + Push $R7 ; Scratch reg + StrCpy $R2 "" + StrLen $R6 $R1 + StrCpy $R4 "\" + StrCmp $R3 "/" loop + StrCpy $R4 "/" +loop: + StrCpy $R7 $R1 1 + StrCpy $R1 $R1 $R6 1 + StrCmp $R7 $R3 found + StrCpy $R2 "$R2$R7" + StrCmp $R1 "" done loop +found: + StrCpy $R2 "$R2$R4" + StrCmp $R1 "" done loop +done: + StrCpy $R3 $R2 + Pop $R7 + Pop $R6 + Pop $R4 + Pop $R2 + Pop $R1 + Exch $R3 +FunctionEnd |
