all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Marcin Borkowski <mbork@mbork.pl>
Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: How to convert an arbitrary string into a filename
Date: Wed, 26 Apr 2023 13:08:59 +0300	[thread overview]
Message-ID: <ZEj4O22wVnXnZ8a/@protected.localdomain> (raw)
In-Reply-To: <87wn1z8fgo.fsf@mbork.pl>

(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

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



  parent reply	other threads:[~2023-04-26 10:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26  3:55 How to convert an arbitrary string into a filename Marcin Borkowski
2023-04-26  4:03 ` Platon Pronko
2023-04-26  4:42   ` Marcin Borkowski
2023-04-26  5:39     ` Platon Pronko
2023-04-26 18:32       ` Marcin Borkowski
2023-04-26  5:42 ` Yuri Khan
2023-04-26 18:32   ` Marcin Borkowski
2023-04-26 10:08 ` Jean Louis [this message]
2023-04-26 12:30   ` Jean Louis
2023-04-26 13:07   ` Eli Zaretskii
2023-04-27  4:52     ` Jean Louis
2023-04-27  5:53       ` Eli Zaretskii
2023-04-27  8:06         ` Platon Pronko
2023-04-26 18:30   ` Marcin Borkowski
2023-04-26 21:29 ` Emanuel Berg
2023-04-27  6:51   ` Marcin Borkowski
2023-04-26 21:32 ` Emanuel Berg
2023-04-27  6:49   ` Marcin Borkowski
2023-04-29  6:20 ` James Thomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZEj4O22wVnXnZ8a/@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mbork@mbork.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.