From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E2BEB39484A2 for ; Wed, 16 Nov 2022 00:00:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E2BEB39484A2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668556846; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tvYPmOJMGKC9VHAbduU/bJofv2v0yLl6VgVBI5VSmZM=; b=Rc88e8zu0iOtxewGB/w7a3ErwnieODeMLQ7sMpP+RvHa9ryK1p9bRbaSLYNKHiO9SbJDr7 5WVHhVbZmFRWfT4AIFJLh124o+iEpI6/cgdfpfRf08uWUlBngzBa1PXKkjXxSGbGkfq69o pPWDxnSc1d8iuzBMeWdc7pxJukZLe1g= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-594-ih_i9DIIMoWBkNGBuKdL6w-1; Tue, 15 Nov 2022 19:00:45 -0500 X-MC-Unique: ih_i9DIIMoWBkNGBuKdL6w-1 Received: by mail-qv1-f71.google.com with SMTP id ns11-20020a056214380b00b004c64784249eso4323939qvb.7 for ; Tue, 15 Nov 2022 16:00:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tvYPmOJMGKC9VHAbduU/bJofv2v0yLl6VgVBI5VSmZM=; b=wm3dxhPRk7cgbVzfpfHwYJZJb2EMwRGnSgfRHA8E4kzlw4dTg2dnN0OPzSBxxuBfAi 8pYV6JHila6qyzVfC2CjMqdqmeh0uxrqK/0A8r/EGFF6SdUQD0ZoR6V1Gimj6CX3xkOn W8JFA3rspzTL67tMWJNXMDPj2WD1CjybYhVXg6Cc5QQmLg2Ujy0F+OabYl23uRwDI1S8 BmSe/yxlJXitFtitLc4je7t5T3raQaKj+4fIaiGod6wNPZONkzJjmClJlQjjKaMQbOK/ /FVnAqaARS4CDBGf5ZbEIZOY0Bcj0dWVX19CIDPW7gNMHBugO7d34YdNXxO8grngizhB 2IWQ== X-Gm-Message-State: ANoB5pmTEFeSOi668pVmUiTydKx9GEp+JlQg34vrK5OcqL+5Sys5L8hm A00QQZmFD31DcmNSIU2OK/YSGJLQtg4wr+BFPcu6hZQG1IcC8x3oj+5IDxLq0stbs28l/vqy+lT I6SbqjlI= X-Received: by 2002:a05:622a:4a0d:b0:3a5:c5c1:43ff with SMTP id fv13-20020a05622a4a0d00b003a5c5c143ffmr18820841qtb.312.1668556844972; Tue, 15 Nov 2022 16:00:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf4xcd++nxh9SpP0GpH+cIcLEmnU+IHtm3Li8PLiw9dy4ZhQcC4vTxx5owebP1U6talVOMcaUw== X-Received: by 2002:a05:622a:4a0d:b0:3a5:c5c1:43ff with SMTP id fv13-20020a05622a4a0d00b003a5c5c143ffmr18820814qtb.312.1668556844674; Tue, 15 Nov 2022 16:00:44 -0800 (PST) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id g11-20020ac87f4b000000b0039a9b55b829sm8050974qtk.29.2022.11.15.16.00.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Nov 2022 16:00:44 -0800 (PST) Message-ID: <656d0680-900d-9e7b-09a7-f273b80b5dd7@redhat.com> Date: Tue, 15 Nov 2022 19:00:41 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v3 2/3] libcpp: add a function to determine UTF-8 validity of a C string To: Ben Boeckel , gcc-patches@gcc.gnu.org Cc: nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com References: <20221109021048.2123704-1-ben.boeckel@kitware.com> <20221109021048.2123704-3-ben.boeckel@kitware.com> From: Jason Merrill In-Reply-To: <20221109021048.2123704-3-ben.boeckel@kitware.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 11/8/22 16:10, Ben Boeckel wrote: > This simplifies the interface for other UTF-8 validity detections when a > simple "yes" or "no" answer is sufficient. > > libcpp/ > > * charset.cc: Add `_cpp_valid_utf8_str` which determines whether > a C string is valid UTF-8 or not. > * internal.h: Add prototype for `_cpp_valid_utf8_str`. > > Signed-off-by: Ben Boeckel > --- > libcpp/charset.cc | 20 ++++++++++++++++++++ > libcpp/internal.h | 2 ++ > 2 files changed, 22 insertions(+) > > diff --git a/libcpp/charset.cc b/libcpp/charset.cc > index 324b5b19136..e130bc01f48 100644 > --- a/libcpp/charset.cc > +++ b/libcpp/charset.cc > @@ -1868,6 +1868,26 @@ _cpp_valid_utf8 (cpp_reader *pfile, > return true; > } > > +/* Detect whether a C-string is a valid UTF-8-encoded set of bytes. Returns > + `false` if any contained byte sequence encodes an invalid Unicode codepoint > + or is not a valid UTF-8 sequence. Returns `true` otherwise. */ > + > +extern bool > +_cpp_valid_utf8_str (const char *name) > +{ > + const uchar* in = (const uchar*)name; > + size_t len = strlen(name); You'se missing a space before (. > + cppchar_t cp; > + > + while (*in) > + { > + if (one_utf8_to_cppchar(&in, &len, &cp)) Here too. OK with those fixed. > + return false; > + } > + > + return true; > +} > + > /* Subroutine of convert_hex and convert_oct. N is the representation > in the execution character set of a numeric escape; write it into the > string buffer TBUF and update the end-of-string pointer therein. WIDE > diff --git a/libcpp/internal.h b/libcpp/internal.h > index badfd1b40da..4f2dd4a2f5c 100644 > --- a/libcpp/internal.h > +++ b/libcpp/internal.h > @@ -834,6 +834,8 @@ extern bool _cpp_valid_utf8 (cpp_reader *pfile, > struct normalize_state *nst, > cppchar_t *cp); > > +extern bool _cpp_valid_utf8_str (const char *str); > + > extern void _cpp_destroy_iconv (cpp_reader *); > extern unsigned char *_cpp_convert_input (cpp_reader *, const char *, > unsigned char *, size_t, size_t,