Re: CANONICALIZE how to use?

Sam Steingold <[email protected]> Thu, 13 Apr 2017 10:28:52 -0400
Newsgroups gmane.lisp.clisp.general
Message-ID <[email protected]>
> * Jean Louis <[email protected]> [2017-04-11 23:19:03 +0300]:
>
> If I am not mistaken CANONICALIZE could be used to get ASCII string
> from "Some ČĆŠL ™bigbog file name.html" ?

Yes, but you don't really need it.

Here is what you can do:

--8<---------------cut here---------------start------------->8---
(defun drop-non-ascii-chars (string)
  (if (every (lambda (c) (typep c charset:ascii)) string)
      string
      (let ((ascii #.(make-encoding :charset charset:ascii
                                    :input-error-action :ignore
                                    :output-error-action :ignore)))
        (ext:convert-string-from-bytes
         (ext:convert-string-to-bytes string ascii)
         ascii))))
(drop-non-ascii-chars "Some ČĆŠL ™bigbog file name.html")
==> "Some L bigbog file name.html"
--8<---------------cut here---------------end--------------->8---

See http://www.clisp.org/impnotes/encoding.html

Bruno, is this The Right Way?

PS. `:input-error-action :ignore` is not really necessary

> In documentation I cannot see what is first argument and what is
> second argument.

The doc http://clisp.org/impnotes/macros3.html#canonicalize
seems to be quite clear:

>> (EXT:CANONICALIZE value functions &KEY (test 'EQL) (max-iter 1024))
>> will call functions on value until it stabilizes under test (which
>> should be a valid HASH-TABLE-TEST) and return the stabilized value
>> and the number of iterations the stabilization required.

IOW,

(ext:canonicalize "Some ČĆŠL ™bigbog file name.html"
                  '(drop-non-ascii-chars))

Jean, how would you clarify the doc?

-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.1504
http://steingoldpsychology.com http://www.childpsy.net http://www.memritv.org
http://iris.org.il http://islamexposedonline.com http://no2bds.org
Those who value Life above Freedom are destined to lose both.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-list