lilypond-user
[Top][All Lists]
Advanced

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

Re: ice-9 i18n string-locale-upcase


From: Jean Abou Samra
Subject: Re: ice-9 i18n string-locale-upcase
Date: Tue, 18 Jan 2022 21:18:11 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1

Le 18/01/2022 à 20:37, Simon Albrecht a écrit :
On 18/01/2022 18:52, Jean Abou Samra wrote:
Because this is documentation for Guile 2
and current releases of LilyPond still have
Guile 1.8.


Thanks for the speedy reply! I wasn’t sure whether the switch to Guile 2 had already been made. I got it to work with the experimental binary you linked to, albeit only after fixing the actual code (see bottom for the revised example).


Did you forget that example? Anyway, I guess you wanted

\version "2.23.5"

#(use-modules (ice-9 i18n))

\markup \column {
  #(string-upcase "üß")
  #(string-locale-upcase "üß" (make-locale (list LC_MESSAGES)
                                           "de_DE"))
}


Backwards compatibility would be great, so I still ask: Do you or does anyone know whether similar functionality is available for Guile 1.8? Although I’m aware that character handling is a major difference between the versions, so I wouldn’t be surprised if not.


Functionality, no. Unicode handling is a feature of
Guile 2 and later (well, and partly a misfeature actually
because it's great to support Unicode, but Guile's string
internals leave to be desired, which make string operations
slow). At best, you can use clumsy workarounds like the
following, with a manually maintained table of replacements ...

\version "2.23.0"

#(define custom-replacements
   '(("ü" . "Ü")
     ("ß" . "SS")
     ("à" . "À")
     ("ê" . "Ê")
     ("ø" . "Ø")
     ;; add entries ...
     ))

#(use-modules (ice-9 match))
#(define upcase-with-clumsy-unicode-workaround
   (let ((table (make-hash-table)))
     (for-each
      (match-lambda
       ((key . value) (hash-set! table key value)))
      custom-replacements)
     (lambda (str)
       (apply string
              (let loop ((chars (string->list str))
                         (acc '()))
                (match chars
                 (()
                  (reverse! acc))
                 ((#\303 next . rest)
                  (loop rest
                        (append (let ((repl (hash-ref table (string #\303 next))))
                                 (if repl
                                     (reverse! (string->list repl))
                                     (list next #\303)))
                                acc)))
                 ((other . rest)
                  (loop rest
                        (cons (char-upcase other)
                              acc)))))))))

\markup \column {
  #(upcase-with-clumsy-unicode-workaround "Je vais à la pêche. üßø")
}


Best,
Jean





reply via email to

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