[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 01/18] qapi: Smarter camel_to_upper() to reduce need for 'pre
From: |
Kevin Wolf |
Subject: |
Re: [PATCH 01/18] qapi: Smarter camel_to_upper() to reduce need for 'prefix' |
Date: |
Wed, 31 Jul 2024 11:43:52 +0200 |
Am 30.07.2024 um 10:10 hat Markus Armbruster geschrieben:
> camel_to_upper() converts its argument from camel case to upper case
> with '_' between words. Used for generated enumeration constant
> prefixes.
>
> When some of the words are spelled all caps, where exactly to insert
> '_' is guesswork. camel_to_upper()'s guesses are bad enough in places
> to make people override them with a 'prefix' in the schema.
>
> Rewrite it to guess better:
>
> 1. Insert '_' after a non-upper case character followed by an upper
> case character:
>
> OneTwo -> ONE_TWO
> One2Three -> ONE2_THREE
>
> 2. Insert '_' before the last upper case character followed by a
> non-upper case character:
>
> ACRONYMWord -> ACRONYM_Word
>
> Except at the beginning (as in OneTwo above), or when there is
> already one:
>
> AbCd -> AB_CD
Maybe it's just me, but the exception "at the beginning" (in the sense
of "after the first character") seems to be exactly where I thought
"that looks strange" while going through your list below. In particular,
I'd expect X_DBG_* instead of XDBG_*. I also thought that the Q_*
spelling made more sense, though this might be less clear. But in case
of doubt, less exceptions seems like a good choice.
> + # Copy remainder of ``value`` to ``ret`` with '_' inserted
> + for ch in value[1:]:
> + if ch.isupper() == upc:
> + pass
> + elif upc:
> + # ``ret`` ends in upper case, next char isn't: insert '_'
> + # before the last upper case char unless there is one
> + # already, or it's at the beginning
> + if len(ret) > 2 and ret[-2] != '_':
> + ret = ret[:-1] + '_' + ret[-1]
I think in the code this means I would have expected len(ret) >= 2.
Kevin
- [PATCH 03/18] qapi/block-core: Drop temporary 'prefix', (continued)
- [PATCH 03/18] qapi/block-core: Drop temporary 'prefix', Markus Armbruster, 2024/07/30
- [PATCH 02/18] tests/qapi-schema: Drop temporary 'prefix', Markus Armbruster, 2024/07/30
- [PATCH 08/18] qapi/ui: Drop temporary 'prefix', Markus Armbruster, 2024/07/30
- [PATCH 01/18] qapi: Smarter camel_to_upper() to reduce need for 'prefix', Markus Armbruster, 2024/07/30
- Re: [PATCH 01/18] qapi: Smarter camel_to_upper() to reduce need for 'prefix', Daniel P . Berrangé, 2024/07/30
- Re: [PATCH 01/18] qapi: Smarter camel_to_upper() to reduce need for 'prefix', Markus Armbruster, 2024/07/30
- Re: [PATCH 01/18] qapi: Smarter camel_to_upper() to reduce need for 'prefix', Avihai Horon, 2024/07/30
- Re: [PATCH 01/18] qapi: Smarter camel_to_upper() to reduce need for 'prefix', Markus Armbruster, 2024/07/31
- Re: [PATCH 01/18] qapi: Smarter camel_to_upper() to reduce need for 'prefix', Avihai Horon, 2024/07/31
- Re: [PATCH 01/18] qapi: Smarter camel_to_upper() to reduce need for 'prefix', Markus Armbruster, 2024/07/31
Re: [PATCH 01/18] qapi: Smarter camel_to_upper() to reduce need for 'prefix',
Kevin Wolf <=
[PATCH 04/18] qapi/common: Drop temporary 'prefix', Markus Armbruster, 2024/07/30
[PATCH 10/18] qapi/crypto: Drop unwanted 'prefix', Markus Armbruster, 2024/07/30
[PATCH 09/18] qapi/machine: Rename CpuS390* to S390Cpu, and drop 'prefix', Markus Armbruster, 2024/07/30
[PATCH 15/18] qapi/crypto: Rename QCryptoRSAPaddingAlgorithm to *Algo, and drop prefix, Markus Armbruster, 2024/07/30
[PATCH 14/18] qapi/crypto: Rename QCryptoAkCipherAlgorithm to *Algo, and drop prefix, Markus Armbruster, 2024/07/30