guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Module name mangling


From: Martin Grabmueller
Subject: Re: Module name mangling
Date: Tue, 23 Jan 2001 20:04:15 +0100

> Date: Fri, 19 Jan 2001 17:20:16 +0100 (MET)
> From: Dirk Herrmann <address@hidden>
> 
> Your code does the right thing (as far as I have understood the discussion
> :-), but it is somewhat too complicated:  To convert a character to a
> hexadecimal number, you can simply to the following:
> 
> (number->string (char->integer #\*) 16)
>  --> "2a"
> 
> By using this pattern the patch should become a little bit simpler.

I have reworked the patch a bit, but I am not sure whether the current
solution is better.  I am still doing bit-twiddling, because (as
Marius already pointed out), the result of the conversion has to be
two characters.

But on a second thought: maybe we only have to care about characters
whose hex representation have two digits? ...

Oh, another problem with `string->number': the resulting hex digits
are all lowercase, which is not common practice for URL-encoding
(don't know about the standard, but web browsers normally use
upper-case characters).

I also removed an unnecessary call to `reverse', speeding up the code
a bit ;-)

Regards,
  'Martin
-- 
Martin Grabmueller              address@hidden
http://www.pintus.de/mgrabmue/  address@hidden on EFnet

===File ~/cvs/guile-core/ice-9/diff0========================
Index: boot-9.scm
===================================================================
RCS file: /cvs/guile/guile-core/ice-9/boot-9.scm,v
retrieving revision 1.221
diff -c -r1.221 boot-9.scm
*** boot-9.scm  2001/01/21 22:11:29     1.221
--- boot-9.scm  2001/01/23 19:01:36
***************
*** 1520,1526 ****
--- 1520,1553 ----
  (define (local-define names val) (nested-define! (current-module) names val))
  (define (local-remove names) (nested-remove! (current-module) names))
  
+ 
+ ;;; Support for URL-encoded module names
+ 
+ (define (string-url-encode string)
+ 
+   (define (integer->hexchar i)
+     (string-ref (number->string i 16) 0))
+ 
+   (define (char-url-encode ch)
+     (cond ((or (char-alphabetic? ch)
+              (char-numeric? ch)
+              (memv ch '(#\_ #\-)))
+          (list ch))
+         (else
+          (list (integer->hexchar (logand (char->integer ch) #xF))
+                (integer->hexchar (logand (ash (char->integer ch) -4) #xF))
+                #\%))))
+ 
+   (let lp ((src (string->list string))
+          (dest '()))
+     (cond ((null? src)
+          (list->string (reverse dest)))
+         (else
+          (lp (cdr src)
+              (append (char-url-encode (car src)) dest))))))
  
+ (define (symbol->url-encoded-string sym)
+   (string-url-encode (symbol->string sym)))
  
  ;;; {The (app) module}
  ;;;
***************
*** 1714,1724 ****
  
  (define (try-module-autoload module-name)
    (let* ((reverse-name (reverse module-name))
!        (name (symbol->string (car reverse-name)))
         (dir-hint-module-name (reverse (cdr reverse-name)))
         (dir-hint (apply string-append
                          (map (lambda (elt)
!                                (string-append (symbol->string elt) "/"))
                               dir-hint-module-name))))
      (resolve-module dir-hint-module-name #f)
      (and (not (autoload-done-or-in-progress? dir-hint name))
--- 1741,1752 ----
  
  (define (try-module-autoload module-name)
    (let* ((reverse-name (reverse module-name))
!        (name (symbol->url-encoded-string (car reverse-name)))
         (dir-hint-module-name (reverse (cdr reverse-name)))
         (dir-hint (apply string-append
                          (map (lambda (elt)
!                                (string-append
!                                 (symbol->url-encoded-string elt) "/"))
                               dir-hint-module-name))))
      (resolve-module dir-hint-module-name #f)
      (and (not (autoload-done-or-in-progress? dir-hint name))
***************
*** 1861,1873 ****
         (let loop ((dirs "")
                    (syms module-name))
           (if (null? (cdr syms))
!              (cons dirs (string-append "lib" (symbol->string (car syms))))
!              (loop (string-append dirs (symbol->string (car syms)) "/")
                     (cdr syms)))))
        (init (make-init-name (apply string-append
                                     (map (lambda (s)
                                            (string-append "_"
!                                                          (symbol->string s)))
                                          module-name)))))
      (let ((subdir (car subdir-and-libname))
          (libname (cdr subdir-and-libname)))
--- 1889,1901 ----
         (let loop ((dirs "")
                    (syms module-name))
           (if (null? (cdr syms))
!              (cons dirs (string-append "lib" (symbol->url-encoded-string (car 
syms))))
!              (loop (string-append dirs (symbol->url-encoded-string (car 
syms)) "/")
                     (cdr syms)))))
        (init (make-init-name (apply string-append
                                     (map (lambda (s)
                                            (string-append "_"
!                                                          
(symbol->url-encoded-string s)))
                                          module-name)))))
      (let ((subdir (car subdir-and-libname))
          (libname (cdr subdir-and-libname)))
============================================================



reply via email to

[Prev in Thread] Current Thread [Next in Thread]