[PATCH v3 04/31] lib: Add a way to find the postiion of a trailing number
Tom Rini
trini at konsulko.com
Wed Jan 19 16:11:11 CET 2022
On Wed, Jan 19, 2022 at 07:37:23AM -0700, Simon Glass wrote:
> Hi Heinrich,
>
> On Wed, 19 Jan 2022 at 04:33, Heinrich Schuchardt <xypron.glpk at gmx.de> wrote:
> >
> > On 1/19/22 02:42, Simon Glass wrote:
> > > At present it is not possible to find out which part of the string is the
> > > number part and which is before it. Add a new variant which provides this
> > > feature, so we can separate the two in the caller.
> > >
> > > Signed-off-by: Simon Glass <sjg at chromium.org>
> > > ---
> > >
> > > Changes in v3:
> > > - Change the function to return a pointer to the first digit
> > > - Add some tests, including one for 'abc123def456'
> > >
> > > include/vsprintf.h | 18 ++++++++++++++++++
> > > lib/strto.c | 14 ++++++++++++--
> > > test/str_ut.c | 13 ++++++++++++-
> > > 3 files changed, 42 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/include/vsprintf.h b/include/vsprintf.h
> > > index 01d2248e04d..ce7a7aaa1cc 100644
> > > --- a/include/vsprintf.h
> > > +++ b/include/vsprintf.h
> > > @@ -118,6 +118,24 @@ long trailing_strtol(const char *str);
> > > */
> > > long trailing_strtoln(const char *str, const char *end);
> > >
> > > +/**
> > > + * trailing_strtoln_end() - extract trailing integer from a fixed-length string
> > > + *
> > > + * Given a fixed-length string this finds a trailing number on the string
> > > + * and returns it. For example, "abc123" would return 123. Only the
> > > + * characters between @str and @end - 1 are examined. If @end is NULL, it is
> > > + * set to str + strlen(str).
> > > + *
> > > + * @str: String to exxamine
> > > + * @end: Pointer to end of string to examine, or NULL to use the
> > > + * whole string
> > > + * @endp: If non-NULL, this is set to point to the character where the
> > > + * number starts, e.g. for "mmc0" this would be point to the '0'; if no
> > > + * trailing number is found, it is set to the end of the string
> > > + * @return training number if found, else -1
> >
> > Return:
> >
> > https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation
>
> Yes I am slowly getting used to this.
>
> Is there any way to accept both? U=Boot has used @return for years so
> there is lots of itin the code.
Can we just do a coccinelle script to just update the codebase?
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20220119/54b3f91c/attachment.sig>
More information about the U-Boot
mailing list