trim   xtlang


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

Implementation

;; trim whitespace
(bind-func trim
  (lambda (e:String*)
    (let ((s (tref e 1))
          (len (tref e 0)) ;; +1 for cstr
          (i 0)
          (start -1) (end 0))
      (while (and (< i len) (= (pref s i) 32)) (inc i 1))
      (set! start i) (set! i (- len 1))
      (while (and (> i -1) (= (pref s i) 32)) (dec i 1))
      (set! end (+ 1 i))
      ;; (println "s:" start "e:" end (substring e start end))
      (substring e start end))))


Back to Index

Similar Entries