[edk2] [PATCH v2 2/3] MdePkg/BaseLib: Introduce CharToUpper and AsciiToUpper publicly

Leif Lindholm leif.lindholm at linaro.org
Fri Dec 14 03:18:43 PST 2018


On Fri, Dec 14, 2018 at 04:20:27PM +0800, Shenglei Zhang wrote:
> Introduce two public functions CharToUpper and AsciiToUpper.
> They have the same functions as InternalCharToUpper and
> InternalBaseLibAsciiToUpper.Considering the internal functions will
> be removed,so directly I change their function names to the public ones'.
> https://bugzilla.tianocore.org/show_bug.cgi?id=1369
> 
> v2:Update the commit message and title

Patch revision information does not belong in the commit message.
Please move underneath the --- line, or keep it in the cover letter
please.

I also think the function deletion should be moved to 3/3, where the
declarations are deleted. This was what I meant by my feedback on v1.

Regards,

Leif
 
> Cc: Leif Lindholm <leif.lindholm at linaro.org>
> Cc: Laszlo Ersek <lersek at redhat.com>
> Cc: Michael D Kinney <michael.d.kinney at intel.com>
> Cc: Liming Gao <liming.gao at intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Shenglei Zhang <shenglei.zhang at intel.com>
> ---
>  MdePkg/Include/Library/BaseLib.h    | 40 +++++++++++++++++++++++++++++
>  MdePkg/Library/BaseLib/SafeString.c |  8 +++---
>  MdePkg/Library/BaseLib/String.c     | 35 +++++--------------------
>  3 files changed, 51 insertions(+), 32 deletions(-)
> 
> diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
> index 8cc086983d..b861d82287 100644
> --- a/MdePkg/Include/Library/BaseLib.h
> +++ b/MdePkg/Include/Library/BaseLib.h
> @@ -2720,6 +2720,46 @@ AsciiStrnToUnicodeStrS (
>    OUT     UINTN                     *DestinationLength
>    );
>  
> +/**
> +  Convert a Unicode character to upper case only if
> +  it maps to a valid small-case ASCII character.
> +
> +  This internal function only deal with Unicode character
> +  which maps to a valid small-case ASCII character, i.e.
> +  L'a' to L'z'. For other Unicode character, the input character
> +  is returned directly.
> +
> +  @param  Char  The character to convert.
> +
> +  @retval LowerCharacter   If the Char is with range L'a' to L'z'.
> +  @retval Unchanged        Otherwise.
> +
> +**/
> +CHAR16
> +EFIAPI
> +CharToUpper (
> +  IN      CHAR16                    Char
> +  );
> +
> +/**
> +  Converts a lowercase Ascii character to upper one.
> +
> +  If Chr is lowercase Ascii character, then converts it to upper one.
> +
> +  If Value >= 0xA0, then ASSERT().
> +  If (Value & 0x0F) >= 0x0A, then ASSERT().
> +
> +  @param  Chr   one Ascii character
> +
> +  @return The uppercase value of Ascii character
> +
> +**/
> +CHAR8
> +EFIAPI
> +AsciiToUpper (
> +  IN      CHAR8                     Chr
> +  );
> +
>  /**
>    Converts an 8-bit value to an 8-bit BCD value.
>  
> diff --git a/MdePkg/Library/BaseLib/SafeString.c b/MdePkg/Library/BaseLib/SafeString.c
> index 417497cbc9..17f88b46d8 100644
> --- a/MdePkg/Library/BaseLib/SafeString.c
> +++ b/MdePkg/Library/BaseLib/SafeString.c
> @@ -905,7 +905,7 @@ StrHexToUintnS (
>      String++;
>    }
>  
> -  if (InternalCharToUpper (*String) == L'X') {
> +  if (CharToUpper (*String) == L'X') {
>      if (*(String - 1) != L'0') {
>        *Data = 0;
>        return RETURN_SUCCESS;
> @@ -1036,7 +1036,7 @@ StrHexToUint64S (
>      String++;
>    }
>  
> -  if (InternalCharToUpper (*String) == L'X') {
> +  if (CharToUpper (*String) == L'X') {
>      if (*(String - 1) != L'0') {
>        *Data = 0;
>        return RETURN_SUCCESS;
> @@ -2459,7 +2459,7 @@ AsciiStrHexToUintnS (
>      String++;
>    }
>  
> -  if (InternalBaseLibAsciiToUpper (*String) == 'X') {
> +  if (AsciiToUpper (*String) == 'X') {
>      if (*(String - 1) != '0') {
>        *Data = 0;
>        return RETURN_SUCCESS;
> @@ -2586,7 +2586,7 @@ AsciiStrHexToUint64S (
>      String++;
>    }
>  
> -  if (InternalBaseLibAsciiToUpper (*String) == 'X') {
> +  if (AsciiToUpper (*String) == 'X') {
>      if (*(String - 1) != '0') {
>        *Data = 0;
>        return RETURN_SUCCESS;
> diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c
> index e6df12797d..ced1b3f975 100644
> --- a/MdePkg/Library/BaseLib/String.c
> +++ b/MdePkg/Library/BaseLib/String.c
> @@ -552,7 +552,7 @@ InternalIsDecimalDigitCharacter (
>  **/
>  CHAR16
>  EFIAPI
> -InternalCharToUpper (
> +CharToUpper (
>    IN      CHAR16                    Char
>    )
>  {
> @@ -586,7 +586,7 @@ InternalHexCharToUintn (
>      return Char - L'0';
>    }
>  
> -  return (10 + InternalCharToUpper (Char) - L'A');
> +  return (10 + CharToUpper (Char) - L'A');
>  }
>  
>  /**
> @@ -1166,27 +1166,6 @@ AsciiStrCmp (
>    return *FirstString - *SecondString;
>  }
>  
> -/**
> -  Converts a lowercase Ascii character to upper one.
> -
> -  If Chr is lowercase Ascii character, then converts it to upper one.
> -
> -  If Value >= 0xA0, then ASSERT().
> -  If (Value & 0x0F) >= 0x0A, then ASSERT().
> -
> -  @param  Chr   one Ascii character
> -
> -  @return The uppercase value of Ascii character
> -
> -**/
> -CHAR8
> -EFIAPI
> -InternalBaseLibAsciiToUpper (
> -  IN      CHAR8                     Chr
> -  )
> -{
> -  return (UINT8) ((Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr);
> -}
>  
>  /**
>    Convert a ASCII character to numerical value.
> @@ -1211,7 +1190,7 @@ InternalAsciiHexCharToUintn (
>      return Char - '0';
>    }
>  
> -  return (10 + InternalBaseLibAsciiToUpper (Char) - 'A');
> +  return (10 + AsciiToUpper (Char) - 'A');
>  }
>  
>  
> @@ -1260,13 +1239,13 @@ AsciiStriCmp (
>    ASSERT (AsciiStrSize (FirstString));
>    ASSERT (AsciiStrSize (SecondString));
>  
> -  UpperFirstString  = InternalBaseLibAsciiToUpper (*FirstString);
> -  UpperSecondString = InternalBaseLibAsciiToUpper (*SecondString);
> +  UpperFirstString  = AsciiToUpper (*FirstString);
> +  UpperSecondString = AsciiToUpper (*SecondString);
>    while ((*FirstString != '\0') && (*SecondString != '\0') && (UpperFirstString == UpperSecondString)) {
>      FirstString++;
>      SecondString++;
> -    UpperFirstString  = InternalBaseLibAsciiToUpper (*FirstString);
> -    UpperSecondString = InternalBaseLibAsciiToUpper (*SecondString);
> +    UpperFirstString  = AsciiToUpper (*FirstString);
> +    UpperSecondString = AsciiToUpper (*SecondString);
>    }
>  
>    return UpperFirstString - UpperSecondString;
> -- 
> 2.18.0.windows.1
> 


More information about the edk2-devel mailing list