Re: [PATCH 3/6] Add functions for parsing integers with size suffixes
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jul 12, 2007, 13:07 UTC
- Message-ID
- <Pine.LNX.4.64.0707121404450.4516@racer.site>
- In-Reply-To
- <1184244952173-git-send-email-bdowning@lavos.net>
Hi,
On Thu, 12 Jul 2007, Brian Downing wrote:
> Split out the nnn{k,m,g} parsing code from git_config_int into
> git_parse_long, so command-line parameters can enjoy the same
> functionality. Also add get_parse_ulong for unsigned values.Nice!
Show 10 quoted lines
> + if (!*end) > + *ret = val; > + else if (!strcasecmp(end, "k")) > + *ret = val * 1024; > + else if (!strcasecmp(end, "m")) > + *ret = val * 1024 * 1024; > + else if (!strcasecmp(end, "g")) > + *ret = val * 1024 * 1024 * 1024; > + else > + return 0;
This could be an own static function, like this:
unsigned long get_unit_factor(const char *end)
{
if (!*end)
return 1;
if (!strcasecmp(end, "k"))
return 1024;
...
error("Unknown unit: %s", end);
return 1;
}to avoid duplicated code.
Ciao, Dscho