public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Alex Xu <alex_y_xu@yahoo.ca>
To: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] [New eclass] twisted-r1.eclass
Date: Sat, 03 Aug 2013 15:47:13 -0400	[thread overview]
Message-ID: <51FD5E41.5020700@yahoo.ca> (raw)
In-Reply-To: <51FD5C12.9020901@yahoo.ca>

[-- Attachment #1: Type: text/plain, Size: 1933 bytes --]

On 03/08/13 03:37 PM, Alex Xu wrote:
> On 03/08/13 02:29 PM, Michał Górny wrote:
>> Dnia 2013-08-03, o godz. 17:54:42
>> Ulrich Mueller <ulm@gentoo.org> napisał(a):
>>
>>>>>>>> On Sat, 3 Aug 2013, Michał Górny wrote:
>>>
>>>> 2. The eclass comes with a pure bash-3.2 CamelCase converter for
>>>> changing PNs like 'twisted-foo' into 'TwistedFoo'. The relevant code
>>>> can be moved to eutils as portable replacements for bash-4 ${foo^}
>>>> and friends.
>>>
>>>> 		# obtain octal ASCII code for the first letter.
>>>> 		local ord=$(printf '%o' "'${fl}")
>>>>
>>>> 		# check if it's [a-z]. ASCII codes are locale-safe.
>>>> 		if [[ ${ord} -ge 141 && ${ord} -le 172 ]]; then
>>>> 			# now substract 040 to make it upper-case.
>>>> 			# fun fact: in range 0141..0172, decimal '- 40' is fine.
>>>> 			local ord=$(( ${ord} - 40))
>>>> 			# and convert it back to the character.
>>>> 			fl=$(printf '\'${ord})
>>>> 		fi
>>>
>>> This looks just horrible. You do decimal arithmetic on octal numbers?
>>
>> Yes. Bash wasn't really happy to do octal arithmetic for me. Yet
>> in this particular case, with proper assumptions, decimal arithmetic is
>> practically equivalent.
>>
> 
> 		# obtain decimal ASCII code for the first letter.
> 		local fl=$(printf '%d' "'${w}")
> 
> 		# check if it's [a-z]. ASCII codes are locale-safe.
> 		if [[ ${ord} -ge 97 && ${ord} -le 122 ]]; then
> 			local ord=$(( ${ord} - 32 ))
> 			# and convert it back to the character.
> 			fl=$(printf '\'${ord})
> 		fi
> 
> 		echo -n "${fl}${w:1}"
> 
> Probably var names should be adjusted, I'm not too familiar with bash
> locals.
> 
> printf '%d' "'twisted" outputs "116" as expected, similar to
> printf("%d", *"asdf qwerty") in C.
> 
> Tested in Bash 4.2.45.
> 
> Now time to sit back and wait for it to break in bash
> <obscure-version-here>.
> 

I am dumb. Please disregard the previous message.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2013-08-03 19:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-03 15:13 [gentoo-dev] [New eclass] twisted-r1.eclass Michał Górny
2013-08-03 15:54 ` Ulrich Mueller
2013-08-03 18:29   ` Michał Górny
2013-08-03 19:37     ` Ulrich Mueller
2013-08-03 19:42       ` Michał Górny
2013-08-03 19:37     ` Alex Xu
2013-08-03 19:47       ` Alex Xu [this message]
2013-08-03 19:49       ` Michał Górny
2013-08-03 21:57 ` Michał Górny
2013-08-03 22:28 ` Michał Górny
2013-08-04  5:15 ` [gentoo-dev] " Marien Zwart
2013-08-04  7:34   ` Michał Górny
2013-08-04 12:37 ` [gentoo-dev] " Michał Górny

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=51FD5E41.5020700@yahoo.ca \
    --to=alex_y_xu@yahoo.ca \
    --cc=gentoo-dev@lists.gentoo.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