replace   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/base/base.xtm

Implementation

(bind-func replace
  (lambda (orig:i8* rep:i8* with:i8*)
    (if (null? (strstr orig rep)) (Str orig)
        (let ((origl (strlen orig))
              (repl (strlen rep))
              (withl (strlen with))
              (pos (strstr orig rep))
              (start (- (ptrtoi64 pos) (ptrtoi64 orig)))
              (newstr:i8* (salloc (+ 1 (strlen orig) (- withl repl)))))
          (memset newstr 0 (+ 1 (strlen orig) (- withl repl)))
          (strncpy newstr orig start)
          (strncpy (pref-ptr newstr start) with withl)
          (strncpy (pref-ptr newstr (+ start withl))
                   (pref-ptr orig (+ start repl))
                   (- origl (+ start repl)))
          (Str newstr)))))


Back to Index

Similar Entries

  • multi_replace_all    xtlang
  • regex:replace-all    scheme
  • regex:replace-everything    scheme
  • regex_replace    xtlang
  • regex_replace    xtlang
  • regex_replace    xtlang
  • regex_replace    xtlang
  • regex_replace_all    xtlang
  • regex_replace_all    xtlang
  • regex_replace_all    xtlang
  • regex_replace_all    xtlang
  • replace    xtlang
  • replace    xtlang
  • replace    xtlang
  • replace-all    scheme
  • replace-first    scheme
  • replace_all    xtlang
  • replace_all    xtlang
  • replace_all    xtlang
  • replace_all    xtlang