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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 5C592389683C for ; Sun, 2 May 2021 19:18:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5C592389683C Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-501--JdjYbhuP6uTbNwrtjnNJw-1; Sun, 02 May 2021 15:18:44 -0400 X-MC-Unique: -JdjYbhuP6uTbNwrtjnNJw-1 Received: by mail-qk1-f198.google.com with SMTP id v7-20020a05620a0a87b02902e02f31812fso3592013qkg.6 for ; Sun, 02 May 2021 12:18:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=H11iPT/axSB19xWhuymTmdIpgMQgMmbHzS3kO3uQFf4=; b=cMHPsdUZMxe/SwrXoZp2Vb3IJajXN3CLz7IfeYgGBmmJqz/kriV/6/cw5wr3sdfH0I Mw4R27TVDpkTFHpuDrYAEgwMt17GoLh6nc5oL2JD/reBBLWJdqk4Rag8o/1ujwvz5Im4 zoKkPQ7vPbsZwkSApDvpHfKTcGVqd4YbgSXGSDRIxSngMmv6eFOXvzBzUenkrbg541J4 ANRLQhmSOOqWldvTaLwLGSnOt8KyeuT9AVPnBmzMZS+adCGyWDwYdCV9S1wCD/XqE7Zi oPVLidS3UWQi6y2oFg0TqOmCrUluCwPfkKwZK/EqI5UaYV6fFRh6YK90exnj81MB24+p 6btA== X-Gm-Message-State: AOAM533qAGd3LsKBA1uMXkfWXtdhKh4Q7K16sWq6JDWD8Ori2s11i/7t 9F1N+aE0DPCTmyHXfYvG3RcFJZ6imY8bc5mUf8grbzuB5WAsXrj46sopWXc28x3jfZ8Q7QcFsOF JMXqKxwlV06FEoy445DAjiSmqqxFDvZ6xxbQp645PcawNYtH1F6JWN+df62Geo9vUDcHc9w== X-Received: by 2002:a05:620a:e10:: with SMTP id y16mr15822334qkm.375.1619983123714; Sun, 02 May 2021 12:18:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOoPAFzzmJve7y2Te/FNzdOlN87TtN76MxECv8ZG1UTTTVbYsfDeToHKsijv/ny7eHaqlsOw== X-Received: by 2002:a05:620a:e10:: with SMTP id y16mr15822318qkm.375.1619983123492; Sun, 02 May 2021 12:18:43 -0700 (PDT) Received: from [192.168.1.16] (198-84-214-74.cpe.teksavvy.com. [198.84.214.74]) by smtp.gmail.com with ESMTPSA id c9sm2841963qtg.89.2021.05.02.12.18.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 02 May 2021 12:18:43 -0700 (PDT) Subject: Re: [PATCH v4 2/4] Update UTF-8 charmap processing. To: Florian Weimer Cc: libc-alpha@sourceware.org References: <20210428130033.3196848-1-carlos@redhat.com> <20210428130033.3196848-3-carlos@redhat.com> <87mtthfakh.fsf@oldenburg.str.redhat.com> <87h7joe76p.fsf@oldenburg.str.redhat.com> From: Carlos O'Donell Organization: Red Hat Message-ID: <5b4c70f3-01d5-c579-980b-62c235f5035b@redhat.com> Date: Sun, 2 May 2021 15:18:41 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <87h7joe76p.fsf@oldenburg.str.redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 May 2021 19:18:49 -0000 On 4/30/21 12:18 AM, Florian Weimer wrote: > * Carlos O'Donell: > >> On 4/29/21 10:07 AM, Florian Weimer wrote: >>> * Carlos O'Donell: >>> >>>> def convert_to_hex(code_point): >>>> '''Converts a code point to a hexadecimal UTF-8 representation >>>> - like /x**/x**/x**.''' >>>> - # Getting UTF8 of Unicode characters. >>>> - # In Python3, .encode('UTF-8') does not work for >>>> - # surrogates. Therefore, we use this conversion table >>>> - surrogates = { >>>> - 0xD800: '/xed/xa0/x80', >>>> - 0xDB7F: '/xed/xad/xbf', >>>> - 0xDB80: '/xed/xae/x80', >>>> - 0xDBFF: '/xed/xaf/xbf', >>>> - 0xDC00: '/xed/xb0/x80', >>>> - 0xDFFF: '/xed/xbf/xbf', >>>> - } >>>> - if code_point in surrogates: >>>> - return surrogates[code_point] >>>> - return ''.join([ >>>> - '/x{:02x}'.format(c) for c in chr(code_point).encode('UTF-8') >>>> - ]) >>>> + ready for use in a locale character map specification e.g. >>>> + /xc2/xaf for MACRON. >>>> + >>>> + ''' >>>> + cp_locale = '' >>>> + cp_bytes = chr(code_point).encode('UTF-8', 'surrogatepass') >>>> + for byte in cp_bytes: >>>> + cp_locale += ''.join('/x{:02x}'.format(byte)) >>>> + return cp_locale >>> >>> I think you should keep the list comprehension. That ''.join() is >>> unnecessary. >> >> Like this? >> >> return ''.join(['/x{:02x}'.format(c) \ >> for c in chr(code_point).encode('UTF-8', 'surrogatepass')]) >> >> (tested works fine and produces the same results) > > Yes, exactly. Thanks. The patch should be fine with this. Fixed. This will be part of the v5 repost. -- Cheers, Carlos.