From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=0.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id A20841F4B8 for ; Fri, 11 Oct 2024 15:05:00 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=HozWuL3T; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=k2PPbbYF; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1728659097; bh=Sfb/fMve/ztiXWO7n6t7D8j6DcsR8BnskUnKeZQLsKg=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=HozWuL3T1zqproLHPynsn3iWSPxsC+hcj3DIobPk/5MB7Mj7jXrmph5S2OUowW8N6 +tmwVFjY83lzg3Ld5akksOSBtfbtMMWd4TF0pxhDoNnrXbA8emgQLE5MZvUa2uhaJx Ji4QMSSooXwba9AQ2qlQAq7oYvhhe2DkSygWNNP0= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id E88E743FE9 for ; Fri, 11 Oct 2024 15:04:57 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=k2PPbbYF; dkim-atps=neutral Received: from s.wrqvtbkv.outbound-mail.sendgrid.net (s.wrqvtbkv.outbound-mail.sendgrid.net [149.72.123.24]) by nue.mailmanlists.eu (Postfix) with ESMTPS id BA35C43E8C for ; Fri, 11 Oct 2024 15:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=ci/Okp4aV0iycMlZUQ8BM4HffHD0XduxGmZ6Jv+QkRc=; b=k2PPbbYFzNUVzENsR9705t6JV+xW3KtzzAAK98vDoflu29Sccfr8BuJ8KQ44/EnvMdhL F0q3LA9zV1z6vsQ8ow2TmG+cMNTlucrezEOfiFzVYn0CYT3emFNNG9PEk4tJDqkRLXaihW WzPuG+5AYUxu6P8vJd7xeTwp5G6myXlfWY3lLdMBAtfmtbK/8TQ3m0cLd5JYtO+YWe7PuN YPsPD2njLdkNuvzoUcZiSpbVcPz/r7Dmpw6SEONLO/dpXN5y8dn+quFj8C+Uqzic06XkyE QoNS6n420CuamwjgDYSVpnbAeIkGIVa5yOXnftjKMIvzuRJj+kYGZLLCy/zoSmiA== Received: by recvd-7cc7f7d978-rf8ss with SMTP id recvd-7cc7f7d978-rf8ss-1-67093E8E-23 2024-10-11 15:04:46.678979731 +0000 UTC m=+2495270.788901607 Received: from herokuapp.com (unknown) by geopod-ismtpd-24 (SG) with ESMTP id ppPvhJGqR_SylkyUt7PfEA for ; Fri, 11 Oct 2024 15:04:46.658 +0000 (UTC) Date: Fri, 11 Oct 2024 15:04:46 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 20792 X-Redmine-Issue-Author: kddnewton X-Redmine-Issue-Priority: Normal X-Redmine-Sender: byroot X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 96147 X-SG-EID: =?us-ascii?Q?u001=2EKmNZ1u3n1vIpO8NNTdp+Q9c0ai7potxbEDLMO7SOJO=2F4KkRUz0d23466m?= =?us-ascii?Q?naiq=2F5fmA4hb60MdRMUAwHZnjIWVFu=2FrqiBOz5c?= =?us-ascii?Q?nOvkBudsSTiOlY5ePsbODP9a9YyPAiFtTNgBahu?= =?us-ascii?Q?X8izXzFzo1UlrH0TOO7MdmPD7URRa8RgsltWNl7?= =?us-ascii?Q?=2FsL5Nkxpd2cZroXyp+1TndEW6fYg6B=2FAsiMkJR7?= =?us-ascii?Q?fsHNT3=2FodU3k=2F2rIvyR1a8RnY71wJv2e5k4lSZK?= =?us-ascii?Q?MxDe4GkVfmBGm+vRQlk7JdeoeQ=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: GOMVFVCC2A5REWDKXNTF4K5I4VBHDEZ7 X-Message-ID-Hash: GOMVFVCC2A5REWDKXNTF4K5I4VBHDEZ7 X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:119512] [Ruby master Feature#20792] String#forcible_encoding? List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "byroot (Jean Boussier) via ruby-core" Cc: "byroot (Jean Boussier)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20792 has been updated by byroot (Jean Boussier). > as a short-hand for Encoding.find(enc).valid_string?(str). I suspect most of the time you'd check a specific encoding, so `Encoding::UTF_8.valid_sequence?(str)` would be enough. That said I think that what @Eregon mentioned in term of performance makes sense. Most of the time when using such method, the next step will be to dup the string and call `force_encoding` on it. So a higher level method would have the advantage of being able to store the computed coderange on the resulting string. ---------------------------------------- Feature #20792: String#forcible_encoding? https://bugs.ruby-lang.org/issues/20792#change-110127 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- I would like to add a method to String called `forcible_encoding?(encoding)`. This would return true or false depending on whether the receiver can be forced into the given encoding without breaking the string. It would effectively be an alias for: ```ruby def forcible_encoding?(enc) original = encoding result = force_encoding(enc).valid_encoding? force_encoding(original) result end ``` I would like this method because there are extremely rare but possible circumstances where source files are marked as binary but contain UTF-8-encoded characters. In that case I would like to check if it's possible to cleanly force UTF-8 before actually doing it. The code I'm trying to replace is here: https://github.com/ruby/prism/blob/d6e9b8de36b4d18debfe36e4545116539964ceeb/lib/prism/parse_result.rb#L15-L30. The pull request for the code is here: https://github.com/ruby/ruby/pull/11851. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/