gnucash unstable: Move gnc:substring-replace-from-to back to utilities.scm

John Ralls jralls at code.gnucash.org
Mon Feb 19 16:27:54 EST 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/36ad5064 (commit)
	from  https://github.com/Gnucash/gnucash/commit/98659344 (commit)



commit 36ad5064e4b2a264897dd5063e5617e6850d4531
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Feb 19 13:27:44 2018 -0800

    Move gnc:substring-replace-from-to back to utilities.scm
    
    It's used in report.scm as well as qif-imp.

diff --git a/gnucash/import-export/qif-imp/string.scm b/gnucash/import-export/qif-imp/string.scm
index 0df34b3..f11cddf 100644
--- a/gnucash/import-export/qif-imp/string.scm
+++ b/gnucash/import-export/qif-imp/string.scm
@@ -75,103 +75,6 @@
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;  gnc:substring-replace
-;;
-;;  Search for all occurrences in string "s1" of string "s2" and
-;;  replace them with string "s3".
-;;
-;;  Example: (gnc:substring-replace "foobarfoobar" "bar" "xyz")
-;;           returns "fooxyzfooxyz".
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(define-public (gnc:substring-replace s1 s2 s3)
-  (let ((s2len (string-length s2)))
-    (let loop ((start1 0)
-               (i (string-contains s1 s2)))
-      (if i
-          (string-append (substring s1 start1 i)
-                         s3
-                         (loop (+ i s2len) (string-contains s1 s2 (+ i s2len))))
-          (substring s1 start1)))))
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;  gnc:substring-replace-from-to
-;;  same as gnc:substring-replace extended by:
-;;  start: from which occurrence onwards the replacement shall start
-;;  end-after: max. number times the replacement should executed
-;;
-;;  Example: (gnc:substring-replace-from-to "foobarfoobarfoobar" "bar" "xyz" 2 2)
-;;           returns "foobarfooxyzfoobar".
-;;
-;; start=1 and end-after<=0 will call gnc:substring-replace (replace all)
-;; start>1 and end-after<=0 will the replace from "start" until end of file
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(define-public (gnc:substring-replace-from-to s1 s2 s3 start end-after)
-  (let (
-         (s2len (string-length s2))
-       )
-
-    ;; if start<=0 and end<=0 => don't do anything
-
-    (if (and
-          (<= start 0)
-          (<= end-after 0)
-        )
-      s1
-    )
-
-    ;; else
-    (begin
-
-      ;; normalize start
-      (if (= start 0)
-        (set! start 1)
-      )
-      ;; start=1 and end<=0 => replace all
-      ;; call gnc:substring-replace for that
-      (if (and (= start 1) (<= end-after 0))
-        (gnc:substring-replace s1 s2 s3)
-
-        ;; else
-        (begin
-          (let loop (
-                      (start1 0)
-                      (i (string-contains s1 s2))
-                    )
-            (if i
-              (begin
-                (set! start (- start 1))
-                (if (or
-                        (> start 0)
-                        (and (> end-after 0)
-                             (<= (+ end-after start) 0)
-                        )
-                    )
-                  (string-append
-                    (substring s1 start1 i)
-                    s2 ;; means: do not change anything
-                    (loop (+ i s2len) (string-contains s1 s2 (+ i s2len)))
-                  )
-                  (string-append
-                    (substring s1 start1 i)
-                    s3
-                    (loop (+ i s2len) (string-contains s1 s2 (+ i s2len)))
-                  )
-                )
-              )
-              ;; else
-              (substring s1 start1)
-            )
-          )
-        )
-      )
-    )
-  )
-)
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;  gnc:string-replace-char
 ;;
 ;;  Replaces all occurrences in string "s" of character "old"
diff --git a/libgnucash/scm/utilities.scm b/libgnucash/scm/utilities.scm
index 23d26da..4a75c02 100644
--- a/libgnucash/scm/utilities.scm
+++ b/libgnucash/scm/utilities.scm
@@ -70,3 +70,101 @@
 
 (define (gnc:debug . items)
   (gnc-scm-log-debug (strify items)))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;  gnc:substring-replace
+;;
+;;  Search for all occurrences in string "s1" of string "s2" and
+;;  replace them with string "s3".
+;;
+;;  Example: (gnc:substring-replace "foobarfoobar" "bar" "xyz")
+;;           returns "fooxyzfooxyz".
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(define-public (gnc:substring-replace s1 s2 s3)
+  (let ((s2len (string-length s2)))
+    (let loop ((start1 0)
+               (i (string-contains s1 s2)))
+      (if i
+          (string-append (substring s1 start1 i)
+                         s3
+                         (loop (+ i s2len) (string-contains s1 s2 (+ i s2len))))
+          (substring s1 start1)))))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;  gnc:substring-replace-from-to
+;;  same as gnc:substring-replace extended by:
+;;  start: from which occurrence onwards the replacement shall start
+;;  end-after: max. number times the replacement should executed
+;;
+;;  Example: (gnc:substring-replace-from-to "foobarfoobarfoobar" "bar" "xyz" 2 2)
+;;           returns "foobarfooxyzfoobar".
+;;
+;; start=1 and end-after<=0 will call gnc:substring-replace (replace all)
+;; start>1 and end-after<=0 will the replace from "start" until end of file
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(define-public (gnc:substring-replace-from-to s1 s2 s3 start end-after)
+  (let (
+         (s2len (string-length s2))
+       )
+
+    ;; if start<=0 and end<=0 => don't do anything
+
+    (if (and
+          (<= start 0)
+          (<= end-after 0)
+        )
+      s1
+    )
+
+    ;; else
+    (begin
+
+      ;; normalize start
+      (if (= start 0)
+        (set! start 1)
+      )
+      ;; start=1 and end<=0 => replace all
+      ;; call gnc:substring-replace for that
+      (if (and (= start 1) (<= end-after 0))
+        (gnc:substring-replace s1 s2 s3)
+
+        ;; else
+        (begin
+          (let loop (
+                      (start1 0)
+                      (i (string-contains s1 s2))
+                    )
+            (if i
+              (begin
+                (set! start (- start 1))
+                (if (or
+                        (> start 0)
+                        (and (> end-after 0)
+                             (<= (+ end-after start) 0)
+                        )
+                    )
+                  (string-append
+                    (substring s1 start1 i)
+                    s2 ;; means: do not change anything
+                    (loop (+ i s2len) (string-contains s1 s2 (+ i s2len)))
+                  )
+                  (string-append
+                    (substring s1 start1 i)
+                    s3
+                    (loop (+ i s2len) (string-contains s1 s2 (+ i s2len)))
+                  )
+                )
+              )
+              ;; else
+              (substring s1 start1)
+            )
+          )
+        )
+      )
+    )
+  )
+)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 24f70dd..b1251f2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -338,6 +338,7 @@ gnucash/import-export/ofx/gnc-plugin-ofx.c
 gnucash/import-export/qif/qif-context.c
 gnucash/import-export/qif/qif-file.c
 gnucash/import-export/qif/qif-objects.c
+gnucash/import-export/qif-imp/.#string.scm
 gnucash/import-export/qif-imp/assistant-qif-import.c
 gnucash/import-export/qif-imp/assistant-qif-import.glade
 gnucash/import-export/qif-imp/dialog-account-picker.c



Summary of changes:
 gnucash/import-export/qif-imp/string.scm | 97 -------------------------------
 libgnucash/scm/utilities.scm             | 98 ++++++++++++++++++++++++++++++++
 po/POTFILES.in                           |  1 +
 3 files changed, 99 insertions(+), 97 deletions(-)



More information about the gnucash-changes mailing list