public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v4 2/4] Update UTF-8 charmap processing.
Date: Thu, 29 Apr 2021 17:02:04 -0400	[thread overview]
Message-ID: <f9a5a986-4f76-8c61-837a-203bdb6fca2f@redhat.com> (raw)
In-Reply-To: <87mtthfakh.fsf@oldenburg.str.redhat.com>

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)

-- 
Cheers,
Carlos.


  reply	other threads:[~2021-04-29 21:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 13:00 [PATCH v4 0/4] Add new C.UTF-8 locale (Bug 17318) Carlos O'Donell
2021-04-28 13:00 ` [PATCH v4 1/4] Add support for processing wide ellipsis ranges in UTF-8 Carlos O'Donell
2021-04-29 14:11   ` Florian Weimer
2021-04-28 13:00 ` [PATCH v4 2/4] Update UTF-8 charmap processing Carlos O'Donell
2021-04-29 14:07   ` Florian Weimer
2021-04-29 21:02     ` Carlos O'Donell [this message]
2021-04-30  4:18       ` Florian Weimer
2021-05-02 19:18         ` Carlos O'Donell
2021-04-28 13:00 ` [PATCH v4 3/4] Regenerate localedata files Carlos O'Donell
2021-04-29 21:03   ` Carlos O'Donell
2021-04-28 13:00 ` [PATCH v4 4/4] Add generic C.UTF-8 locale (Bug 17318) Carlos O'Donell
2021-04-29 14:13   ` Florian Weimer
2021-04-29 20:05     ` Carlos O'Donell
2021-04-30 17:59       ` Carlos O'Donell
2021-04-30 18:20         ` Florian Weimer
2021-05-02 19:18           ` Carlos O'Donell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f9a5a986-4f76-8c61-837a-203bdb6fca2f@redhat.com \
    --to=carlos@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).