r16968 - gnucash/branches/2.2/src/import-export/qif-import - [r16949] Fixes bug 360058 by rewriting qif-import:get-account-name to avoid use

Andreas Köhler andi5 at cvs.gnucash.org
Thu Feb 28 17:08:18 EST 2008


Author: andi5
Date: 2008-02-28 17:08:18 -0500 (Thu, 28 Feb 2008)
New Revision: 16968
Trac: http://svn.gnucash.org/trac/changeset/16968

Modified:
   gnucash/branches/2.2/src/import-export/qif-import/qif-dialog-utils.scm
Log:
[r16949] Fixes bug 360058 by rewriting qif-import:get-account-name to avoid use
of regular expressions. The new algorithm is simpler and faster anyway.

Committed by cedayiv.


Modified: gnucash/branches/2.2/src/import-export/qif-import/qif-dialog-utils.scm
===================================================================
--- gnucash/branches/2.2/src/import-export/qif-import/qif-dialog-utils.scm	2008-02-28 22:08:04 UTC (rev 16967)
+++ gnucash/branches/2.2/src/import-export/qif-import/qif-dialog-utils.scm	2008-02-28 22:08:18 UTC (rev 16968)
@@ -6,8 +6,6 @@
 ;;;  Bill Gribble <grib at billgribble.com> 20 Feb 2000 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(use-modules (ice-9 regex))
-
 (define (default-stock-acct brokerage security)
   (string-append brokerage (gnc-get-account-separator-string) security))
 
@@ -561,23 +559,21 @@
          (qif-xtn:set-from-acct! xtn new-acct-name)))
    (qif-file:xtns qif-file)))
 
-(define qif-import:account-name-regexp #f)
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;  qif-import:get-account-name
+;;
+;;  Given an account name, return the rightmost subaccount.
+;;  For example, given the account name "foo:bar", "bar" is
+;;  returned (assuming the account separator is ":").
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
 (define (qif-import:get-account-name fullname)
-  (if (not qif-import:account-name-regexp)
-      (let* ((rstr ":([^:]+)$|^([^:]+)$")
-             (newstr (regexp-substitute/global 
-                      #f ":" rstr 'pre (gnc-get-account-separator-string) 'post)))
-        
-        (set! qif-import:account-name-regexp (make-regexp newstr))))
-  
-  (let ((match (regexp-exec qif-import:account-name-regexp fullname)))
-    (if match
-        (begin 
-          (let ((substr (match:substring match 1)))
-            (if substr
-                substr
-                (match:substring match 2))))
+  (let ((lastsep (string-rindex fullname
+                                (string-ref (gnc-get-account-separator-string)
+                                            0))))
+    (if lastsep
+        (substring fullname (+ lastsep 1))
         fullname)))
 
 



More information about the gnucash-changes mailing list