public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Abner Chang" <abner.chang@hpe.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
	"hao.a.wu@intel.com" <hao.a.wu@intel.com>
Cc: "Wang, Jian J" <jian.j.wang@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Leif Lindholm <leif@nuviainc.com>,
	"Wang, Nickle (HPS SW)" <nickle.wang@hpe.com>,
	"O'Hanley, Peter (EXL)" <peter.ohanley@hpe.com>
Subject: Re: [edk2-devel] [PATCH v4 1/6] MdeModulePkg/Ucs2Utf8lib: UCS2 to UFT8 manipulation library
Date: Mon, 7 Dec 2020 07:28:29 +0000	[thread overview]
Message-ID: <CS1PR8401MB114438ADDFE3BA3E891015F9FFCE0@CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <BN8PR11MB36661A80F316DD659B42483CCACE0@BN8PR11MB3666.namprd11.prod.outlook.com>



> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Wu, Hao A
> Sent: Monday, December 7, 2020 3:05 PM
> To: devel@edk2.groups.io; Chang, Abner (HPS SW/FW Technologist)
> <abner.chang@hpe.com>
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Leif Lindholm <leif@nuviainc.com>; Wang,
> Nickle (HPS SW) <nickle.wang@hpe.com>; O'Hanley, Peter (EXL)
> <peter.ohanley@hpe.com>
> Subject: Re: [edk2-devel] [PATCH v4 1/6] MdeModulePkg/Ucs2Utf8lib: UCS2
> to UFT8 manipulation library
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner
> > Chang
> > Sent: Monday, December 7, 2020 1:37 PM
> > To: devel@edk2.groups.io
> > Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A
> > <hao.a.wu@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Leif
> > Lindholm <leif@nuviainc.com>; Nickle Wang <nickle.wang@hpe.com>;
> Peter
> > O'Hanley <peter.ohanley@hpe.com>
> > Subject: [edk2-devel] [PATCH v4 1/6] MdeModulePkg/Ucs2Utf8lib: UCS2 to
> > UFT8 manipulation library
> >
> > This library provides UCS2 to UFT8 or vise versa functions to
> > manipulate
> > UCS2/UTF8 strings. This library is currently used by edk2 port of open
> > source jansson library.
> 
> 
> Really sorry for missing the previous discussion between you and Leif.
> 
> For me, the Ucs2Utf8lib case is kind of similar with the jansson library case for
> the Redfish feature.
> If the current consumer is only the jansson library under the RedfishPkg, I
> would suggest to put the Ucs2Utf8lib under RedfishPkg first.
> We can move this library to a more generic place if there are more
> consumers.
> 
> Best Regards,
> Hao Wu

Hi Hao, I have no problem with this. Will send patches again. 
Thanks

> 
> 
> >
> > Signed-off-by: Abner Chang <abner.chang@hpe.com>
> >
> > Cc: Jian J Wang <jian.j.wang@intel.com>
> > Cc: Hao A Wu <hao.a.wu@intel.com>
> > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > Cc: Leif Lindholm <leif@nuviainc.com>
> > Cc: Nickle Wang <nickle.wang@hpe.com>
> > Cc: Peter O'Hanley <peter.ohanley@hpe.com>
> > ---
> >  .../Include/Library/BaseUcs2Utf8Lib.h         |  69 +++
> >  .../Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c | 417
> ++++++++++++++++++
> >  .../BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf       |  30 ++
> >  MdeModulePkg/MdeModulePkg.dec                 |   5 +
> >  MdeModulePkg/MdeModulePkg.dsc                 |   2 +
> >  5 files changed, 523 insertions(+)
> >  create mode 100644 MdeModulePkg/Include/Library/BaseUcs2Utf8Lib.h
> >  create mode 100644
> > MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c
> >  create mode 100644
> > MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
> >
> > diff --git a/MdeModulePkg/Include/Library/BaseUcs2Utf8Lib.h
> > b/MdeModulePkg/Include/Library/BaseUcs2Utf8Lib.h
> > new file mode 100644
> > index 0000000000..51ae924929
> > --- /dev/null
> > +++ b/MdeModulePkg/Include/Library/BaseUcs2Utf8Lib.h
> > @@ -0,0 +1,69 @@
> > +/** @file
> > +  UCS2 to UTF8 manipulation library header file.
> > +
> > +  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > +  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
> > +
> > +    SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#ifndef BASE_UCS2UTF8_LIB_H_
> > +#define BASE_UCS2UTF8_LIB_H_
> > +
> > +#include <Base.h>
> > +#include <Uefi.h>
> > +#include <Library/BaseLib.h>
> > +#include <Library/BaseMemoryLib.h>
> > +#include <Library/DebugLib.h>
> > +#include <Library/PrintLib.h>
> > +#include <Library/MemoryAllocationLib.h>
> > +
> > +///
> > +///  L"\u0000"
> > +///
> > +#define UNICODE_FORMAT_LEN         6
> > +#define UNICODE_FORMAT_CHAR_LEN    2
> > +#define UNICODE_FORMAT_CHAR_SIZE   3
> > +
> > +#define UTF8_BUFFER_FOR_UCS2_MAX_SIZE   3
> > +
> > +/**
> > +  Convert a UCS2 string to a UTF8 encoded string.
> > +
> > +  @param[in]    Ucs2Str                The provided UCS2 string.
> > +  @param[out]   Utf8StrAddr            The converted UTF8 string address.
> Caller
> > +                                       is responsible for Free this string.
> > +
> > +  @retval       EFI_INVALID_PARAMETER  One or more parameters are
> invalid.
> > +  @retval       EFI_OUT_OF_RESOURCES   System runs out of resources.
> > +  @retval       EFI_SUCCESS            The UTF8 encoded string has been
> > converted.
> > +
> > +**/
> > +EFI_STATUS
> > +UCS2StrToUTF8 (
> > +  IN  CHAR16     *Ucs2Str,
> > +  OUT CHAR8      **Utf8StrAddr
> > +  );
> > +
> > +/**
> > +  Convert a UTF8 encoded string to a UCS2 string.
> > +
> > +  @param[in]    Utf8Str                The provided UTF8 encoded string.
> > +  @param[out]   Ucs2StrAddr            The converted UCS2 string address.
> > Caller
> > +                                       is responsible for Free this string.
> > +
> > +  @retval       EFI_INVALID_PARAMETER  The UTF8 encoded string is not
> valid
> > to
> > +                                       convert to UCS2 string.
> > +                                       One or more parameters are invalid.
> > +  @retval       EFI_OUT_OF_RESOURCES   System runs out of resources.
> > +  @retval       EFI_SUCCESS            The UCS2 string has been converted.
> > +
> > +**/
> > +EFI_STATUS
> > +UTF8StrToUCS2 (
> > +  IN  CHAR8      *Utf8Str,
> > +  OUT CHAR16     **Ucs2StrAddr
> > +  );
> > +
> > +#endif
> > diff --git a/MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c
> > b/MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c
> > new file mode 100644
> > index 0000000000..6cff109a5c
> > --- /dev/null
> > +++ b/MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c
> > @@ -0,0 +1,417 @@
> > +/** @file
> > +  UCS2 to UTF8 manipulation library.
> > +
> > +  Copyright (c) 2018 - 2019, Intel Corporation. All rights
> > + reserved.<BR>
> > +  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
> > +
> > +    SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#include <Library/BaseUcs2Utf8Lib.h>
> > +
> > +/**
> > +  Since each UCS2 character can be represented by 1-3 UTF8 encoded
> > +characters,
> > +  this function is used to retrieve the UTF8 encoding size for a UCS2
> > character.
> > +
> > +  @param[in]   Utf8Buffer       The buffer for UTF8 encoded data.
> > +
> > +  @retval      Return the size of UTF8 encoding string or 0 if it is not for
> > +               UCS2 format.
> > +
> > +**/
> > +UINT8
> > +GetUTF8SizeForUCS2 (
> > +  IN    CHAR8      *Utf8Buffer
> > +  )
> > +{
> > +  CHAR8    TempChar;
> > +  UINT8    Utf8Size;
> > +
> > +  ASSERT (Utf8Buffer != NULL);
> > +
> > +  TempChar = *Utf8Buffer;
> > +  if ((TempChar & 0xF0) == 0xF0) {
> > +
> > +    //
> > +    // This format is not for UCS2.
> > +    //
> > +    return 0;
> > +  }
> > +
> > +  Utf8Size = 1;
> > +  if ((TempChar & 0x80) == 0x80) {
> > +    if ((TempChar & 0xC0) == 0xC0) {
> > +
> > +      Utf8Size ++;
> > +      if ((TempChar & 0xE0) == 0xE0) {
> > +
> > +        Utf8Size ++;
> > +      }
> > +    }
> > +  }
> > +
> > +  return Utf8Size;
> > +}
> > +
> > +/**
> > +  Since each UCS2 character can be represented by the format: \uXXXX,
> > +this function
> > +  is used to retrieve the UCS2 character from a Unicode format.
> > +  Call MUST make sure there are at least 6 Bytes in the input UTF8 buffer.
> > +
> > +  @param[in]    Utf8Buffer             The buffer for UTF8 encoded data.
> > +  @param[out]   Ucs2Char               The converted UCS2 character.
> > +
> > +  @retval       EFI_INVALID_PARAMETER  Non-Ascii characters found in the
> > hexadecimal
> > +                                       digits string, and can't be converted to a UCS2
> > +                                       character.
> > +  @retval       EFI_SUCCESS            The UCS2 character has been retrieved.
> > +
> > +**/
> > +EFI_STATUS
> > +GetUCS2CharByFormat (
> > +  IN    CHAR8      *Utf8Buffer,
> > +  OUT   CHAR16     *Ucs2Char
> > +  )
> > +{
> > +  UINT8     Num1;
> > +  UINT8     Num2;
> > +  UINT8     Index;
> > +  CHAR8     Ucs2CharFormat[UNICODE_FORMAT_CHAR_SIZE];  /// two
> > Hexadecimal digits Ascii string, like "3F"
> > +
> > +  for (Index = 0; Index < 4; Index ++) {
> > +    if ((*(Utf8Buffer + 2 + Index) & 0x80) != 0x00) {
> > +      return EFI_INVALID_PARAMETER;
> > +    }
> > +  }
> > +
> > +  ZeroMem (Ucs2CharFormat, UNICODE_FORMAT_CHAR_SIZE);
> > +
> > +  //
> > +  // Get the First Number, Offset is 2  //  CopyMem (Ucs2CharFormat,
> > + Utf8Buffer + 2,
> > UNICODE_FORMAT_CHAR_LEN);
> > +  Num1 = (UINT8) AsciiStrHexToUintn (Ucs2CharFormat);
> > +
> > +  //
> > +  // Get the Second Number, Offset is 4  //  CopyMem (Ucs2CharFormat,
> > + Utf8Buffer + 4, UNICODE_FORMAT_CHAR_LEN);
> > +  Num2 = (UINT8) AsciiStrHexToUintn (Ucs2CharFormat);
> > +
> > +  //
> > +  // Ucs2Char is Little-Endian
> > +  //
> > +  *((CHAR8 *) Ucs2Char)        = Num2;
> > +  *(((CHAR8 *) Ucs2Char) + 1) = Num1;
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> > +/**
> > +  Convert a UCS2 character to UTF8 encoding string.
> > +
> > +  @param[in]    Ucs2Char               The provided UCS2 character.
> > +  @param[out]   Utf8Buffer             The converted UTF8 encoded data.
> > +
> > +  @retval      Return the size of UTF8 encoding data for this UCS2 character.
> > +
> > +**/
> > +UINT8
> > +UCS2CharToUTF8 (
> > +  IN  CHAR16     Ucs2Char,
> > +  OUT CHAR8      *Utf8Buffer
> > +  )
> > +{
> > +  UINT16    Ucs2Number;
> > +
> > +  ASSERT (Utf8Buffer != NULL);
> > +
> > +  Ucs2Number = (UINT16) Ucs2Char;
> > +  if (Ucs2Number <= 0x007F) {
> > +
> > +    //
> > +    // UTF8 format: 0xxxxxxx
> > +    //
> > +    *Utf8Buffer = Ucs2Char & 0x7F;
> > +    return 1;
> > +
> > +  } else if (Ucs2Number >= 0x0080 && Ucs2Number <= 0x07FF) {
> > +
> > +    //
> > +    // UTF8 format: 110xxxxx 10xxxxxx
> > +    //
> > +    *(Utf8Buffer + 1) = (Ucs2Char & 0x3F) | 0x80;
> > +    *Utf8Buffer       = ((Ucs2Char >> 6) & 0x1F) | 0xC0;
> > +    return 2;
> > +
> > +  } else {  /// Ucs2Number >= 0x0800 && Ucs2Number <= 0xFFFF
> > +
> > +    //
> > +    // UTF8 format: 1110xxxx 10xxxxxx 10xxxxxx
> > +    //
> > +    *(Utf8Buffer + 2) = (Ucs2Char & 0x3F) | 0x80;
> > +    *(Utf8Buffer + 1) = ((Ucs2Char >> 6) & 0x3F) | 0x80;
> > +    *Utf8Buffer       = ((Ucs2Char >> 12) & 0x0F) | 0xE0;
> > +    return 3;
> > +  }
> > +}
> > +
> > +/**
> > +  Convert a UTF8 encoded data to a UCS2 character.
> > +
> > +  @param[in]    Utf8Buffer             The provided UTF8 encoded data.
> > +  @param[out]   Ucs2Char               The converted UCS2 character.
> > +
> > +  @retval       EFI_INVALID_PARAMETER  The UTF8 encoded string is not
> valid
> > or
> > +                                       not for UCS2 character.
> > +  @retval       EFI_SUCCESS            The converted UCS2 character.
> > +
> > +**/
> > +EFI_STATUS
> > +UTF8ToUCS2Char (
> > +  IN   CHAR8      *Utf8Buffer,
> > +  OUT  CHAR16     *Ucs2Char
> > +  )
> > +{
> > +  UINT8    Utf8Size;
> > +  CHAR8    *Ucs2Buffer;
> > +  CHAR8    TempChar1;
> > +  CHAR8    TempChar2;
> > +  CHAR8    TempChar3;
> > +
> > +  ASSERT (Utf8Buffer != NULL && Ucs2Char != NULL);  ZeroMem
> > + (Ucs2Char, sizeof (CHAR16));  Ucs2Buffer = (CHAR8 *) Ucs2Char;
> > +
> > +  Utf8Size = GetUTF8SizeForUCS2 (Utf8Buffer);  switch (Utf8Size) {
> > +
> > +    case 1:
> > +
> > +      //
> > +      // UTF8 format: 0xxxxxxx
> > +      //
> > +      TempChar1 = *Utf8Buffer;
> > +      if ((TempChar1 & 0x80) != 0x00) {
> > +        return EFI_INVALID_PARAMETER;
> > +      }
> > +
> > +      *Ucs2Buffer       = TempChar1;
> > +      *(Ucs2Buffer + 1) = 0;
> > +      break;
> > +
> > +    case 2:
> > +
> > +      //
> > +      // UTF8 format: 110xxxxx 10xxxxxx
> > +      //
> > +      TempChar1 = *Utf8Buffer;
> > +      if ((TempChar1 & 0xE0) != 0xC0) {
> > +        return EFI_INVALID_PARAMETER;
> > +      }
> > +
> > +      TempChar2 = *(Utf8Buffer + 1);
> > +      if ((TempChar2 & 0xC0) != 0x80) {
> > +        return EFI_INVALID_PARAMETER;
> > +      }
> > +
> > +      *Ucs2Buffer       = (TempChar1 << 6) + (TempChar2 & 0x3F);
> > +      *(Ucs2Buffer + 1) = (TempChar1 >> 2) & 0x07;
> > +      break;
> > +
> > +    case 3:
> > +
> > +      //
> > +      // UTF8 format: 1110xxxx 10xxxxxx 10xxxxxx
> > +      //
> > +      TempChar1 = *Utf8Buffer;
> > +      if ((TempChar1 & 0xF0) != 0xE0) {
> > +        return EFI_INVALID_PARAMETER;
> > +      }
> > +
> > +      TempChar2 = *(Utf8Buffer + 1);
> > +      if ((TempChar2 & 0xC0) != 0x80) {
> > +        return EFI_INVALID_PARAMETER;
> > +      }
> > +
> > +      TempChar3 = *(Utf8Buffer + 2);
> > +      if ((TempChar3 & 0xC0) != 0x80) {
> > +        return EFI_INVALID_PARAMETER;
> > +      }
> > +
> > +      *Ucs2Buffer       = (TempChar2 << 6) + (TempChar3 & 0x3F);
> > +      *(Ucs2Buffer + 1) = (TempChar1 << 4) + ((TempChar2 >> 2) &
> > + 0x0F);
> > +
> > +      break;
> > +
> > +    default:
> > +
> > +      return EFI_INVALID_PARAMETER;
> > +  }
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> > +/**
> > +  Convert a UCS2 string to a UTF8 encoded string.
> > +
> > +  @param[in]    Ucs2Str                The provided UCS2 string.
> > +  @param[out]   Utf8StrAddr            The converted UTF8 string address.
> Caller
> > +                                       is responsible for Free this string.
> > +
> > +  @retval       EFI_INVALID_PARAMETER  One or more parameters are
> invalid.
> > +  @retval       EFI_OUT_OF_RESOURCES   System runs out of resources.
> > +  @retval       EFI_SUCCESS            The UTF8 encoded string has been
> > converted.
> > +
> > +**/
> > +EFI_STATUS
> > +UCS2StrToUTF8 (
> > +  IN  CHAR16     *Ucs2Str,
> > +  OUT CHAR8      **Utf8StrAddr
> > +  )
> > +{
> > +  UINTN    Ucs2StrIndex;
> > +  UINTN    Ucs2StrLength;
> > +  CHAR8    *Utf8Str;
> > +  UINTN    Utf8StrLength;
> > +  UINTN    Utf8StrIndex;
> > +  CHAR8    Utf8Buffer[UTF8_BUFFER_FOR_UCS2_MAX_SIZE];
> > +  UINT8    Utf8BufferSize;
> > +
> > +  if (Ucs2Str == NULL || Utf8StrAddr == NULL) {
> > +    return EFI_INVALID_PARAMETER;
> > +  }
> > +
> > +  Ucs2StrLength = StrLen (Ucs2Str);
> > +  Utf8StrLength = 0;
> > +
> > +  for (Ucs2StrIndex = 0; Ucs2StrIndex < Ucs2StrLength; Ucs2StrIndex
> > + ++) {
> > +
> > +    ZeroMem (Utf8Buffer, sizeof (Utf8Buffer));
> > +    Utf8BufferSize = UCS2CharToUTF8 (Ucs2Str[Ucs2StrIndex], Utf8Buffer);
> > +    Utf8StrLength += Utf8BufferSize;
> > +  }
> > +
> > +  Utf8Str = AllocateZeroPool (Utf8StrLength + 1);  if (Utf8Str ==
> > + NULL) {
> > +    return EFI_OUT_OF_RESOURCES;
> > +  }
> > +
> > +  Utf8StrIndex = 0;
> > +  for (Ucs2StrIndex = 0; Ucs2StrIndex < Ucs2StrLength; Ucs2StrIndex
> > + ++) {
> > +
> > +    ZeroMem (Utf8Buffer, sizeof (Utf8Buffer));
> > +    Utf8BufferSize = UCS2CharToUTF8 (Ucs2Str[Ucs2StrIndex],
> > + Utf8Buffer);
> > +
> > +    CopyMem (Utf8Str + Utf8StrIndex, Utf8Buffer, Utf8BufferSize);
> > +    Utf8StrIndex += Utf8BufferSize;
> > +  }
> > +
> > +  Utf8Str[Utf8StrIndex] = '\0';
> > +  *Utf8StrAddr = Utf8Str;
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> > +/**
> > +  Convert a UTF8 encoded string to a UCS2 string.
> > +
> > +  @param[in]    Utf8Str                The provided UTF8 encoded string.
> > +  @param[out]   Ucs2StrAddr            The converted UCS2 string address.
> > Caller
> > +                                       is responsible for Free this string.
> > +
> > +  @retval       EFI_INVALID_PARAMETER  The UTF8 encoded string is not
> valid
> > to
> > +                                       convert to UCS2 string.
> > +                                       One or more parameters are invalid.
> > +  @retval       EFI_OUT_OF_RESOURCES   System runs out of resources.
> > +  @retval       EFI_SUCCESS            The UCS2 string has been converted.
> > +
> > +**/
> > +EFI_STATUS
> > +UTF8StrToUCS2 (
> > +  IN  CHAR8      *Utf8Str,
> > +  OUT CHAR16     **Ucs2StrAddr
> > +  )
> > +{
> > +  EFI_STATUS    Status;
> > +  UINTN         Utf8StrIndex;
> > +  UINTN         Utf8StrLength;
> > +  UINTN         Ucs2StrIndex;
> > +  UINT8         Utf8BufferSize;
> > +  CHAR16        *Ucs2StrTemp;
> > +
> > +  if (Utf8Str == NULL || Ucs2StrAddr == NULL) {
> > +    return EFI_INVALID_PARAMETER;
> > +  }
> > +
> > +  //
> > +  // It is not an Ascii string, calculate string length.
> > +  //
> > +  Utf8StrLength = 0;
> > +  while (*(Utf8Str + Utf8StrLength) != '\0') {
> > +    Utf8StrLength ++;
> > +  }
> > +
> > +  //
> > +  // UCS2 string shall not be longer than the UTF8 string.
> > +  //
> > +  Ucs2StrTemp = AllocateZeroPool ((Utf8StrLength + 1) * sizeof
> > + (CHAR16));  if (Ucs2StrTemp == NULL) {
> > +    return EFI_OUT_OF_RESOURCES;
> > +  }
> > +
> > +  Utf8StrIndex = 0;
> > +  Ucs2StrIndex = 0;
> > +  while (Utf8Str[Utf8StrIndex] != '\0') {
> > +
> > +    if (CompareMem (Utf8Str + Utf8StrIndex, "\\u", 2) == 0 &&
> > +      Utf8StrLength - Utf8StrIndex >= UNICODE_FORMAT_LEN) {
> > +
> > +      Status = GetUCS2CharByFormat (Utf8Str + Utf8StrIndex,
> > + Ucs2StrTemp +
> > Ucs2StrIndex);
> > +      if (!EFI_ERROR (Status)) {
> > +
> > +        Utf8StrIndex += UNICODE_FORMAT_LEN;
> > +        Ucs2StrIndex ++;
> > +      } else {
> > +
> > +        StrCpyS (Ucs2StrTemp + Ucs2StrIndex, 3, L"\\u");
> > +
> > +        Ucs2StrIndex += 2;
> > +        Utf8StrIndex += 2;
> > +      }
> > +    } else {
> > +
> > +      Utf8BufferSize = GetUTF8SizeForUCS2 (Utf8Str + Utf8StrIndex);
> > +      if (Utf8BufferSize == 0 || Utf8StrLength - Utf8StrIndex <
> > + Utf8BufferSize) {
> > +
> > +        FreePool (Ucs2StrTemp);
> > +        return EFI_INVALID_PARAMETER;
> > +      }
> > +
> > +      Status = UTF8ToUCS2Char (Utf8Str + Utf8StrIndex, Ucs2StrTemp +
> > Ucs2StrIndex);
> > +      if (EFI_ERROR (Status)) {
> > +
> > +        FreePool (Ucs2StrTemp);
> > +        return EFI_INVALID_PARAMETER;
> > +      }
> > +
> > +      Ucs2StrIndex ++;
> > +      Utf8StrIndex += Utf8BufferSize;
> > +    }
> > +  }
> > +
> > +  *Ucs2StrAddr = AllocateZeroPool ((Ucs2StrIndex + 1) * sizeof
> > + (CHAR16));  if (*Ucs2StrAddr == NULL) {
> > +
> > +    FreePool (Ucs2StrTemp);
> > +    return EFI_OUT_OF_RESOURCES;
> > +  }
> > +
> > +  StrCpyS (*Ucs2StrAddr, Ucs2StrIndex + 1, Ucs2StrTemp);
> > + *(*Ucs2StrAddr + Ucs2StrIndex) = L'\0';  FreePool (Ucs2StrTemp);
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> > diff --git a/MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
> > b/MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
> > new file mode 100644
> > index 0000000000..93efb1fb88
> > --- /dev/null
> > +++ b/MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
> > @@ -0,0 +1,30 @@
> > +## @file
> > +# UCS2 to UTF8 manipulation library.
> > +#
> > +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> #
> > +(C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR> #
> > +#    SPDX-License-Identifier: BSD-2-Clause-Patent
> > +#
> > +##
> > +
> > +[Defines]
> > +  INF_VERSION                    = 0x0001001b
> > +  BASE_NAME                      = BaseUcs2Utf8Lib
> > +  FILE_GUID                      = 536646C3-46D0-4B12-ABC4-CDE1A33B5256
> > +  MODULE_TYPE                    = BASE
> > +  VERSION_STRING                 = 1.0
> > +  LIBRARY_CLASS                  = Ucs2Utf8Lib
> > +
> > +#
> > +#  VALID_ARCHITECTURES           = IA32 X64 ARM AARCH64 RISCV64
> > +#
> > +
> > +[Sources.common]
> > +  BaseUcs2Utf8Lib.c
> > +
> > +[Packages]
> > +  MdePkg/MdePkg.dec
> > +  MdeModulePkg/MdeModulePkg.dec
> > +
> > +
> > diff --git a/MdeModulePkg/MdeModulePkg.dec
> > b/MdeModulePkg/MdeModulePkg.dec index 9b52b34494..1cd8c6392d
> > 100644
> > --- a/MdeModulePkg/MdeModulePkg.dec
> > +++ b/MdeModulePkg/MdeModulePkg.dec
> > @@ -154,6 +154,11 @@
> >    #
> >    VariablePolicyHelperLib|Include/Library/VariablePolicyHelperLib.h
> >
> > +  ##  @libraryclass  This library provides UCS2 to UTF8 manipulation
> > +  #   functions.
> > +  #
> > +  Ucs2Utf8Lib|Include/Library/BaseUcs2Utf8Lib.h
> > +
> >  [Guids]
> >    ## MdeModule package token space guid
> >    # Include/Guid/MdeModulePkgTokenSpace.h
> > diff --git a/MdeModulePkg/MdeModulePkg.dsc
> > b/MdeModulePkg/MdeModulePkg.dsc index 90165ca443..85e2daeeea
> > 100644
> > --- a/MdeModulePkg/MdeModulePkg.dsc
> > +++ b/MdeModulePkg/MdeModulePkg.dsc
> > @@ -43,6 +43,7 @@
> >    PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
> >
> >
> PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Base
> > PeCoffGetEntryPointLib.inf
> >    SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
> > +
> >
> Ucs2Utf8Lib|MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
> >    #
> >    # UEFI & PI
> >    #
> > @@ -212,6 +213,7 @@
> >    MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.inf
> >
> >    MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
> > +  MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
> >    MdeModulePkg/Logo/Logo.inf
> >    MdeModulePkg/Logo/LogoDxe.inf
> >    MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
> > --
> > 2.17.1
> >
> >
> >
> >
> >
> 
> 
> 
> 
> 


  reply	other threads:[~2020-12-07  7:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-07  5:36 [PATCH v4 0/6] jansson edk2 port Abner Chang
2020-12-07  5:36 ` [PATCH v4 1/6] MdeModulePkg/Ucs2Utf8lib: UCS2 to UFT8 manipulation library Abner Chang
2020-12-07  7:05   ` [edk2-devel] " Wu, Hao A
2020-12-07  7:28     ` Abner Chang [this message]
2020-12-07  7:34       ` Wu, Hao A
2020-12-07 17:20         ` Leif Lindholm
2020-12-08  0:45           ` Wu, Hao A
2020-12-08  0:50             ` Abner Chang
2020-12-08  2:59             ` Abner Chang
2020-12-08  4:45           ` 回复: " gaoliming
2020-12-07  5:36 ` [PATCH v4 1/6] MdeModulePkg/Ucs2Utf8lib: UCS " Abner Chang
2020-12-07  5:36 ` [PATCH v4 2/6] edk2: jansson submodule for edk2 JSON library Abner Chang
2020-12-07  5:36 ` [PATCH v4 3/6] RedfishPkg/CrtLib: C runtime library Abner Chang
2020-12-07  5:36 ` [PATCH v4 4/6] RedfishPkg/library: EDK2 port of jansson library Abner Chang
2020-12-07  5:36 ` [PATCH v4 5/6] RedfishPkg: Add EDK2 port of jansson library to build Abner Chang
2020-12-07  5:36 ` [PATCH v4 6/6] .pytool: Add required submodule for JsonLib Abner Chang

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-list 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=CS1PR8401MB114438ADDFE3BA3E891015F9FFCE0@CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM \
    --to=devel@edk2.groups.io \
    /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