[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to convert an arbitrary string into a filename
From: |
Eli Zaretskii |
Subject: |
Re: How to convert an arbitrary string into a filename |
Date: |
Wed, 26 Apr 2023 16:07:42 +0300 |
> Date: Wed, 26 Apr 2023 13:08:59 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
>
> (defun string-slug (s &optional random)
> "Return slug for Website Revision System by using string S.
>
> RANDOM number may be added on the end."
> (let* ((random (or random nil))
> ;; (case-fold-search t)
> (s (replace-regexp-in-string "[^[:word:]]" " " s))
> (s (replace-regexp-in-string " +" " " s))
> (s (replace-regexp-in-string "ž" "z" s))
> (s (replace-regexp-in-string "Ž" "Z" s))
> (s (replace-regexp-in-string "š" "s" s))
> (s (replace-regexp-in-string "Š" "S" s))
> (s (replace-regexp-in-string "č" "c" s))
> (s (replace-regexp-in-string "Č" "C" s))
> (s (replace-regexp-in-string "Ć" "C" s))
> (s (replace-regexp-in-string "ć" "c" s))
> (s (replace-regexp-in-string "đ" "d" s))
> (s (replace-regexp-in-string "Đ" "D" s))
If you need to convert an accented character to its base character
(i.e. "remove" the accent), Emacs has much more general facilities:
(require 'ucs-normalize)
(substring (ucs-normalize-NFKD-string "Ć") 0 1)
=> "C"
Re: How to convert an arbitrary string into a filename, Marcin Borkowski, 2023/04/26
Re: How to convert an arbitrary string into a filename, Jean Louis, 2023/04/26
Re: How to convert an arbitrary string into a filename, Emanuel Berg, 2023/04/27
Re: How to convert an arbitrary string into a filename, Emanuel Berg, 2023/04/27
Re: How to convert an arbitrary string into a filename, James Thomas, 2023/04/29