Re: [PATCH v4 03/13] parseopt: make OPT_INTEGER support hexadecimal as well
- From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
- Date
- Feb 4, 2012, 04:55 UTC
- Message-ID
- <CACsJy8Ba2qxyT4XqeRmUv63Z3rT1-FmBkZ3tB6YMh6qrXjLP1Q@mail.gmail.com>
- In-Reply-To
- <7vaa4zmsku.fsf@alter.siamese.dyndns.org>
2012/2/4 Junio C Hamano <gitster@pobox.com>:
Show 9 quoted lines
> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes: > >> - *(int *)opt->value = strtol(arg, (char **)&s, 10); >> + if (!prefixcmp(arg, "0x") || !prefixcmp(arg, "0X")) >> + *(int *)opt->value = strtol(arg + 2, (char **)&s, 16); >> + else >> + *(int *)opt->value = strtol(arg, (char **)&s, 10); > > Can't you just do "strtol(arg, (char **)&s, 0)" instead?
I could but that means "01234" is now in base 8 and that's currently accepted as base 10. 0x1234 does not have this problem because current git rejects it.
-- Duy