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: Thu, 27 Apr 2023 08:53:15 +0300 Message-ID: <834jp1ub04.fsf@gnu.org> References: <87wn1z8fgo.fsf@mbork.pl> <83h6t2u6zl.fsf@gnu.org> 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="19733"; 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 Thu Apr 27 07:53:20 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 1pruZE-0004vb-BT for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 27 Apr 2023 07:53:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pruYg-0002Yb-Hw; Thu, 27 Apr 2023 01:52:46 -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 1pruYe-0002X7-By for help-gnu-emacs@gnu.org; Thu, 27 Apr 2023 01:52:44 -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 1pruYe-0000WL-3p for help-gnu-emacs@gnu.org; Thu, 27 Apr 2023 01:52:44 -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=pUrXhvs/amWHY+LIidet+XCcx3IkbLsCQa+YX8eTwGA=; b=ktk0N/ZpJng2guTN0pFU zEHjYhSy8pix/MypZ+noW2dS5v0IIIvaV5z0xJ4XBhCENXHg8LtH8hKC60Q1GjwI0nbY8q4TSGuue xSXH8DY/aOPazHbMiS4Hs6svjx9aq4WPDRQo3Mxxb9YxJXGAE4uHZlMTASbQNYANXLMPanM9yyPxW oQos0aes613mfFwfQGCxzd9IWIE8JTSfHWkRJOlBlla6WmPfJS+dbHEh+b96iy2P4PZNS65nAPFXy 1Jjxbef3lxDcs+7h3wyMozeMpjv60bdOQZi4A2mh4fZkoqDxkCM/nf6LMTpu6q7Gf/dxyn1iyjNqy aFJs9X+bcAR35A==; 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 1pruYd-0007SL-Hb for help-gnu-emacs@gnu.org; Thu, 27 Apr 2023 01:52:43 -0400 In-Reply-To: (message from Jean Louis on Thu, 27 Apr 2023 07:52:55 +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:143411 Archived-At: > Date: Thu, 27 Apr 2023 07:52:55 +0300 > From: Jean Louis > Cc: help-gnu-emacs@gnu.org > > * Eli Zaretskii [2023-04-26 16:09]: > > 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" > > Alright, then like this: > > (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 (substring (ucs-normalize-NFKD-string s) 0 1)) > (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 " OK, here, üößčć") ➜ "" > > It doesn't give good result. Of course. Because you didn't understand how to use ucs-normalize-NFKD-string for your purposes. Please read its doc string, and try to play with it, starting from the example I've shown.