From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: How to convert an arbitrary string into a filename Date: Wed, 26 Apr 2023 16:07:42 +0300 Message-ID: <83h6t2u6zl.fsf@gnu.org> References: <87wn1z8fgo.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29918"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 26 15:07:52 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1presB-0007bu-F6 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 26 Apr 2023 15:07:51 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prerd-0006O3-G4; Wed, 26 Apr 2023 09:07:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prerb-0006Kk-Pm for help-gnu-emacs@gnu.org; Wed, 26 Apr 2023 09:07:16 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prerb-00083P-Bw for help-gnu-emacs@gnu.org; Wed, 26 Apr 2023 09:07:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=qhD+iUFVLL8ye8V675YLYOIBjie7yxupfr9C302m+Y8=; b=YR6/ewRvcbl0q+Bqlc7+ +3fOvYIwXb2GFRZQGdFddLqPVM0Qb+WJaLoiepAbbuNl3Cpo8IT0HDAMm8mnrYOSnao+Rb9Axf/at pJwk1nNLR3CnzzySxdX/B1T4py1XUGdZNEOIUbpSpI7cIyJAf0Wz+oBEBLBQUUTbMzBglXqnG39gI GzujQ0KhYihrX/1h//fRBHBsmRzucYQOBnAMsvI022k3t8AocZkNMoWEXWaRugM97yOgegF8KsqX8 IBdCOGxZRvsxIopC9SIQKHGatBPfwo5dIXE+YESkJrL7xkBifibIiic4RHsppjwaHaxkrBilBtPfB yT4Wb6/oxPAr6w==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prerZ-0007U5-M6 for help-gnu-emacs@gnu.org; Wed, 26 Apr 2023 09:07:14 -0400 In-Reply-To: (message from Jean Louis on Wed, 26 Apr 2023 13:08:59 +0300) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:143397 Archived-At: > Date: Wed, 26 Apr 2023 13:08:59 +0300 > From: Jean Louis > Cc: Help Gnu Emacs mailing list > > (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"