StrSlash.nsh 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ; Adapted from: https://nsis.sourceforge.io/Another_String_Replace_(and_Slash/BackSlash_Converter) (2019-08-31)
  2. !macro _StrSlashConstructor out in
  3. Push "${in}"
  4. Push "\"
  5. Call StrSlash
  6. Pop ${out}
  7. !macroend
  8. !define StrSlash '!insertmacro "_StrSlashConstructor"'
  9. ; Push $filenamestring (e.g. 'c:\this\and\that\filename.htm')
  10. ; Push "\"
  11. ; Call StrSlash
  12. ; Pop $R0
  13. ; ;Now $R0 contains 'c:/this/and/that/filename.htm'
  14. Function StrSlash
  15. Exch $R3 ; $R3 = needle ("\" or "/")
  16. Exch
  17. Exch $R1 ; $R1 = String to replacement in (haystack)
  18. Push $R2 ; Replaced haystack
  19. Push $R4 ; $R4 = not $R3 ("/" or "\")
  20. Push $R6
  21. Push $R7 ; Scratch reg
  22. StrCpy $R2 ""
  23. StrLen $R6 $R1
  24. StrCpy $R4 "\"
  25. StrCmp $R3 "/" loop
  26. StrCpy $R4 "/"
  27. loop:
  28. StrCpy $R7 $R1 1
  29. StrCpy $R1 $R1 $R6 1
  30. StrCmp $R7 $R3 found
  31. StrCpy $R2 "$R2$R7"
  32. StrCmp $R1 "" done loop
  33. found:
  34. StrCpy $R2 "$R2$R4"
  35. StrCmp $R1 "" done loop
  36. done:
  37. StrCpy $R3 $R2
  38. Pop $R7
  39. Pop $R6
  40. Pop $R4
  41. Pop $R2
  42. Pop $R1
  43. Exch $R3
  44. FunctionEnd