help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to convert an arbitrary string into a filename


From: Marcin Borkowski
Subject: Re: How to convert an arbitrary string into a filename
Date: Wed, 26 Apr 2023 20:30:07 +0200
User-agent: mu4e 1.1.0; emacs 30.0.50

On 2023-04-26, at 12:08, Jean Louis <bugs@gnu.support> wrote:

> (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))
>          (s (replace-regexp-in-string "^[[:space:]]+" "" s))
>          (s (replace-regexp-in-string "[[:space:]]+$" "" s))
>          (s (replace-regexp-in-string " " "-" s))
>        (s (if random (concat s "-" (number-to-string (random-number))) s)))
>     s))
>
> (string-slug "Hello there, how are you?") ➜ "Hello-there-how-are-you"
>
> From:
>
> GNU Emacs package: rcd-utilities.el:
> https://gnu.support/gnu-emacs/packages/rcd-utilities-el.html

Thanks, though - as Eli said - this is very specific.  Most of these
letters have 0 probability of appearing in _my_ files, and most letters
from (Polish alphabet \setminus English alphabet) are not there
anyway...

Best,

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

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