New Scheme string routines
Charles Day
cedayiv at gmail.com
Thu Jun 5 12:48:53 EDT 2008
On Thu, Jun 5, 2008 at 9:29 AM, Derek Atkins <warlord at mit.edu> wrote:
> Maybe create a new file in src/scm and then you can cause
> it to get loaded by main.scm? I don't think main.scm
> is the right place for these procedures.
>
OK. Should I be naming these procedures with "gnc-" in front to prevent them
from hiding any standard Guile routines that might get released with the
same name?
> -derek
>
>
> Quoting Charles Day <cedayiv at gmail.com>:
>
> To support multi-byte account separators in the QIF importer I have had to
>> write several new Scheme string manipulation routines. They are pretty
>> useful variations on some of the standard routines. I have them working in
>> the QIF importer, but is there a better place to stick them so that they
>> can
>> be used from other modules, such as reports? Perhaps in main.scm?
>>
>> -Charles
>>
>> P.S. For example, here are a three of the Scheme procedures I have
>> written.
>> There are a few more, but this will give you a good idea. If you happen to
>> see any room for performance improvement, let me know.
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ;; string-rcontains
>> ;;
>> ;; Like string-contains, but searches from the right.
>> ;;
>> ;; Example: (string-rcontains "foobarfoobarf" "bar") returns 9.
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>
>> (define (string-rcontains s1 s2)
>> (let ((s2len (string-length s2)))
>> (let loop ((i (string-contains s1 s2))
>> (retval #f))
>> (if i
>> (loop (string-contains s1 s2 (+ i s2len)) i)
>> retval))))
>>
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ;; substring-count
>> ;;
>> ;; Similar to string-count, but searches for a substring rather
>> ;; than a single character.
>> ;;
>> ;; Example: (substring-count "foobarfoobarf" "bar") returns 2.
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>
>> (define (substring-count s1 s2)
>> (let ((s2len (string-length s2)))
>> (let loop ((i (string-contains s1 s2))
>> (retval 0))
>> (if i
>> (loop (string-contains s1 s2 (+ i s2len)) (+ 1 retval))
>> retval))))
>>
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ;; substring-split
>> ;;
>> ;; Similar to string-split, but the delimiter is a string
>> ;; rather than a single character.
>> ;;
>> ;; Example: (substring-split "foobarfoobarf" "bar") returns
>> ;; ("foo" "foo" "f")
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>
>> (define (substring-split s1 s2)
>> (let ((i (string-contains s1 s2)))
>> (if i
>> (cons (substring s1 0 i)
>> (substring-split (substring s1 (+ i (string-length s2))) s2))
>> (list s1))))
>> _______________________________________________
>> gnucash-devel mailing list
>> gnucash-devel at gnucash.org
>> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
>>
>>
>
>
> --
> Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
> Member, MIT Student Information Processing Board (SIPB)
> URL: http://web.mit.edu/warlord/ PP-ASEL-IA N1NWH
> warlord at MIT.EDU PGP key available
>
>
More information about the gnucash-devel
mailing list