From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.1578.1607388336497352135 for ; Mon, 07 Dec 2020 16:45:36 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=qnoHGRPf; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: hao.a.wu@intel.com) IronPort-SDR: lYKy5l8s0DMQ7vYPlhCyu+WarAcnmB0lyWt4kxXCB5mNqWeY/GuT4Nzd5l3kgCMmRPQRUe7OF6 VKECuhjpxODw== X-IronPort-AV: E=McAfee;i="6000,8403,9828"; a="173953903" X-IronPort-AV: E=Sophos;i="5.78,401,1599548400"; d="scan'208";a="173953903" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2020 16:45:35 -0800 IronPort-SDR: gb6BMopV/OLjpF+FQOBl4sxN+TSE7un+P+M9iN3Cb3aqGnuwMDIPHVsYwUhG6N7+YLEwRH946b u4uT0pQ1RJIA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,401,1599548400"; d="scan'208";a="539997993" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by fmsmga006.fm.intel.com with ESMTP; 07 Dec 2020 16:45:35 -0800 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 7 Dec 2020 16:45:34 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 7 Dec 2020 16:45:34 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Mon, 7 Dec 2020 16:45:33 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LhOKkuZrw/sSnYFN3P0wCME0JIb3bIsw+NgGU93N3slT8FVYUEvMQJPLjsgeXHoHpiIHgxU8RyL+JQ5um2yYv1BVPvhCd3qeuuEqdzhcmO5G7u0B6PgA/L9oahJOp6aR1bR0euSybWWp3VCbXKP6Gr5RFZaR6NXGsOxH49QZYibhRRWm0UrMHHHpsVaxOEVdPGZNoGWMOOwaSM1NGAmT92Jmeyi9LfWkvd4x0Ko1X5f70zRfgyHswX2hg/WNFTOHPbMNZxNhwdw8MOve5H3Y7IMIkjkl6b3Md/qvn7kwzA/FOdTw97hFcbgjMSTRPCfUcft6D84hXKzRadgC/gBFpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AYU68ACsCAj3fRk/CXzR7jVgEoDK+QkTXvIRIUCkzQ8=; b=M5IYijiKs6n7Qc3LyOFnyDs3hSIu5rewmw5JPQAXH7VnjMcdfv3QsRlkFVSnnuhTcRA54DlEVHRmDSORFJKauTn6Ogutkk/LcGz7oBbBAkEeZb094DkLkTns+gdztsavEmBECw8DCnQ8E+GEm0rMiu/6Eiwb8QoXFMsLOFEe8IejeSQ1gCHHTTFJDfPpXxrD5ZM4Coi8lmufImAFGIIjDyAGiE2oA0Pan8xoV28SRYNqbUtKDxNfmu7V01sLzZBK13MY+9XLKvdKoXUZ2QKL4ED6fUaSdLlyHydrxtszawWjWZlfTl53spb1Wj1BdiEALIr7fqegwgXIbp1off+xig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AYU68ACsCAj3fRk/CXzR7jVgEoDK+QkTXvIRIUCkzQ8=; b=qnoHGRPfnoln18LR3ospLqVOizXW8egCZxsGDyJLnKq910RF2lGrqAMynWaUnd09EgusHmjGjJFCG/pd+DSiUITWzCxQI9Ur66awl4H/tpR6jHJscjexM8OwD7Sbse3CyQ+QifL//fIwnR7hVoPkBFOj14lhSO9NSA/VPx7fdO0= Received: from BN8PR11MB3666.namprd11.prod.outlook.com (2603:10b6:408:8c::19) by BN6PR11MB4050.namprd11.prod.outlook.com (2603:10b6:405:7e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.21; Tue, 8 Dec 2020 00:45:32 +0000 Received: from BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::4cda:993f:ffc1:f169]) by BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::4cda:993f:ffc1:f169%6]) with mapi id 15.20.3632.022; Tue, 8 Dec 2020 00:45:32 +0000 From: "Wu, Hao A" To: Leif Lindholm CC: "Chang, Abner (HPS SW/FW Technologist)" , "devel@edk2.groups.io" , Liming Gao , "Wang, Jian J" , "Wang, Nickle (HPS SW)" , "O'Hanley, Peter (EXL)" Subject: Re: [edk2-devel] [PATCH v4 1/6] MdeModulePkg/Ucs2Utf8lib: UCS2 to UFT8 manipulation library Thread-Topic: [edk2-devel] [PATCH v4 1/6] MdeModulePkg/Ucs2Utf8lib: UCS2 to UFT8 manipulation library Thread-Index: AQHWzGGbnIp5k2YdTEmEUKndALmf7qnrMygggAAJMoCAAAFZQIAApBqAgAB7p/A= Date: Tue, 8 Dec 2020 00:45:32 +0000 Message-ID: References: <20201207053655.29101-1-abner.chang@hpe.com> <20201207053655.29101-2-abner.chang@hpe.com> <20201207172039.GF1664@vanye> In-Reply-To: <20201207172039.GF1664@vanye> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: nuviainc.com; dkim=none (message not signed) header.d=none;nuviainc.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.218] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6aef1fb9-113e-4d7f-d964-08d89b12915b x-ms-traffictypediagnostic: BN6PR11MB4050: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:127; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: OhgLKFAMaGV9fNcu1HGMSvIJ9Ezw6hqNMmMP1S+ScqZRWw2cZte7lJjvx3IRRl8Woztz8xFMTivO4R1j42e4ik5K8DpNS7SSV79xafcWLx+xXd6M9Rx1VVPNsb977hzdk4uUizkVhkbsIlotLnFaf2D+pKvExLrWz+4SeWnQh9CVBrF2Dpcnp9dwOYGNmfdyIdL9SJaxY7r7n6WCYAUfZ7HJpHGSRupruvTjJ3JJgh/S78v7DOkYNirDm86eDR6wC5gofULCtmYDHLgocHQ+80ai7Im6Fz+t659xn237KFn0tZolAPTQWkfiyeRFyJ59H98QP/FqBElvUkNq9l0QoJ5wVBqWcDs8fVXDf84t7vZsoZd9d60OEf7xWQE++afvW1o39lEsnCWoZWS71WzfFQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR11MB3666.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(396003)(346002)(366004)(39860400002)(66946007)(71200400001)(8676002)(8936002)(55016002)(478600001)(83380400001)(4326008)(6916009)(6506007)(19627235002)(86362001)(186003)(7696005)(64756008)(9686003)(53546011)(30864003)(26005)(76116006)(54906003)(52536014)(2906002)(66556008)(33656002)(316002)(5660300002)(966005)(66476007)(66446008)(559001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?ZU6/J1pioPOgXC9sP2sceSKyLHidBJz/hUnpMUDT/Ou8bmX+EIW3AWEKFyQC?= =?us-ascii?Q?ikxu/XoHLPEOVPeMwDMKCowk6RAXfliGphDo/QusVu+DsaRS4PP42iwXCWu0?= =?us-ascii?Q?6SR7yjQvE0g3DscI2J1FB6f4taLfKgGIUrhQrlhxyM6mNrjMKRT7ymTrjtbU?= =?us-ascii?Q?UtxInq47v+jN+cGV09lvKdPed5uAxGtlKx9mBlp0PjmBdG4GGjWjcV6epOeX?= =?us-ascii?Q?NLL7oDexZPpjxnW5rP6Z7ugfN+EqkrnlFwL71b3kjKwHQnxdt72j0v0OzfhI?= =?us-ascii?Q?EpT3JIKjnvuRF/Qmg6p9TjqJmNEYpVdNgs5IACLAkcc/ha4/vbYYEwC35DAT?= =?us-ascii?Q?hLaCQ+o/ndsEWTilk+BdWqYyRFsnqy4Zq3pA5BPzehVWDINiMakZIfZGtDkg?= =?us-ascii?Q?Sta0EUnLTV7ot8tOB8SCjvVNm6GLV0qOfwZu9JTwKrPDgdRgnyc+zqXwfyNk?= =?us-ascii?Q?edBFJuLOD9Ye0kxqBBnNjSsFrjr3L0uX+Pl9lIkOjYrgPsTIqsOetUHTZn/f?= =?us-ascii?Q?+4+uPi8wavefCJdko+EIaBzkeN6L5B6mfSjl5wSNv41fIRtQhDWANLuwTr+l?= =?us-ascii?Q?Ejhgd4+1Ovf6cFvYHSrmXr82XGl88SHzZEsHoDUT4E3lZIMq/BEBqgO4Pyiv?= =?us-ascii?Q?ctlV1lLesuvNFGGbvrpy5JvHkMrVe/fMbtNT8xakGQYBytgh0Yrj139a+3Ud?= =?us-ascii?Q?r5EVpU4uuT/qYBwpD+OXJziOMXvEvi8TTIS4VlH6tDYlcHhRE+aAKyYlfvSm?= =?us-ascii?Q?Sm7RJResX4RnVs9rtD85VR+gdKzUpUOBXASGc4gThUvWWSXekqZa0MxZyMqE?= =?us-ascii?Q?AJH7G6JqtS6FppQsk3zAYcmo7Gewp6aucqYkKyMPwNfYtQJ9F0w7TFDugG/h?= =?us-ascii?Q?EyhlN14wvvOuZqdfj7VmB8WiLgnYnvRsxU0RFoQJ48eYeeF/iDeiPd2/NwBh?= =?us-ascii?Q?U1mPW1g7/Is+9fmt3T24lmpKdUMq3xXupjDwTrfkltquMQtpQNZucQrqL2Vf?= =?us-ascii?Q?7vBe?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN8PR11MB3666.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6aef1fb9-113e-4d7f-d964-08d89b12915b X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Dec 2020 00:45:32.1548 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 3NeK6jNWFKsw1DbVapOUsFjwdOS0utAVcIiyWW0RR79TTk5HkG60sTSS8d/rbdPFn/ouEBe/T1kjE2NGI8/XwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB4050 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Leif Lindholm > Sent: Tuesday, December 8, 2020 1:21 AM > To: Wu, Hao A > Cc: Chang, Abner (HPS SW/FW Technologist) ; > devel@edk2.groups.io; Liming Gao ; Wang, Jian > J ; Wang, Nickle (HPS SW) ; > O'Hanley, Peter (EXL) > Subject: Re: [edk2-devel] [PATCH v4 1/6] MdeModulePkg/Ucs2Utf8lib: UCS2 > to UFT8 manipulation library >=20 > Hi Hao Wu, >=20 > On Mon, Dec 07, 2020 at 07:34:21 +0000, Wu, Hao A wrote: > > > > 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 RedfishPk= g > 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 > > > > > > Thanks Abner. > > Leif and Liming, do you have comments on this? Thanks. >=20 > I was the one who suggested Abner try to add it to MdeModulePkg, since i= t > sounded to me like a generically useful thing to have. Agree that the library looks like a generic one. I should have been involved in the discussion earlier. Sorry for the late response. >=20 > But I understand the argument that it should not live there until it is = known > to have multiple users, and I am OK with that. Thanks. Best Regards, Hao Wu >=20 > Best Regards, >=20 > Leif >=20 > > Best Regards, > > Hao Wu > > > > > > > > > > > > > > > > > > > > > > > > > Signed-off-by: Abner Chang > > > > > > > > > > Cc: Jian J Wang > > > > > Cc: Hao A Wu > > > > > Cc: Liming Gao > > > > > Cc: Leif Lindholm > > > > > Cc: Nickle Wang > > > > > Cc: Peter O'Hanley > > > > > --- > > > > > .../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.
> > > > > + (C) Copyright 2020 Hewlett Packard Enterprise Development > > > > > + LP
> > > > > + > > > > > + SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > + > > > > > +**/ > > > > > + > > > > > +#ifndef BASE_UCS2UTF8_LIB_H_ > > > > > +#define BASE_UCS2UTF8_LIB_H_ > > > > > + > > > > > +#include > > > > > +#include > > > > > +#include > > > > > +#include #include > > > > > + #include #include > > > > > + > > > > > + > > > > > +/// > > > > > +/// 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 strin= g > address. > > > > Caller > > > > > + is responsible for Free = this string. > > > > > + > > > > > + @retval EFI_INVALID_PARAMETER One or more parameters a= re > > > > 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 encode= d string. > > > > > + @param[out] Ucs2StrAddr The converted UCS2 strin= g > 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 a= re 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.
> > > > > + (C) Copyright 2020 Hewlett Packard Enterprise Development > > > > > + LP
> > > > > + > > > > > + SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > + > > > > > +**/ > > > > > + > > > > > +#include > > > > > + > > > > > +/** > > > > > + 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 dat= a. > > > > > + > > > > > + @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 !=3D NULL); > > > > > + > > > > > + TempChar =3D *Utf8Buffer; > > > > > + if ((TempChar & 0xF0) =3D=3D 0xF0) { > > > > > + > > > > > + // > > > > > + // This format is not for UCS2. > > > > > + // > > > > > + return 0; > > > > > + } > > > > > + > > > > > + Utf8Size =3D 1; > > > > > + if ((TempChar & 0x80) =3D=3D 0x80) { > > > > > + if ((TempChar & 0xC0) =3D=3D 0xC0) { > > > > > + > > > > > + Utf8Size ++; > > > > > + if ((TempChar & 0xE0) =3D=3D 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 U= TF8 > buffer. > > > > > + > > > > > + @param[in] Utf8Buffer The buffer for UTF8 enco= ded data. > > > > > + @param[out] Ucs2Char The converted UCS2 chara= cter. > > > > > + > > > > > + @retval EFI_INVALID_PARAMETER Non-Ascii characters fou= nd > in the > > > > > hexadecimal > > > > > + digits string, and can't= be converted to a UCS2 > > > > > + character. > > > > > + @retval EFI_SUCCESS The UCS2 character has b= een > 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 =3D 0; Index < 4; Index ++) { > > > > > + if ((*(Utf8Buffer + 2 + Index) & 0x80) !=3D 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 =3D (UINT8) AsciiStrHexToUintn (Ucs2CharFormat); > > > > > + > > > > > + // > > > > > + // Get the Second Number, Offset is 4 // CopyMem > > > > > + (Ucs2CharFormat, Utf8Buffer + 4, UNICODE_FORMAT_CHAR_LEN); > > > > > + Num2 =3D (UINT8) AsciiStrHexToUintn (Ucs2CharFormat); > > > > > + > > > > > + // > > > > > + // Ucs2Char is Little-Endian > > > > > + // > > > > > + *((CHAR8 *) Ucs2Char) =3D Num2; > > > > > + *(((CHAR8 *) Ucs2Char) + 1) =3D Num1; > > > > > + > > > > > + return EFI_SUCCESS; > > > > > +} > > > > > + > > > > > +/** > > > > > + Convert a UCS2 character to UTF8 encoding string. > > > > > + > > > > > + @param[in] Ucs2Char The provided UCS2 charac= ter. > > > > > + @param[out] Utf8Buffer The converted UTF8 encod= ed data. > > > > > + > > > > > + @retval Return the size of UTF8 encoding data for this U= CS2 > character. > > > > > + > > > > > +**/ > > > > > +UINT8 > > > > > +UCS2CharToUTF8 ( > > > > > + IN CHAR16 Ucs2Char, > > > > > + OUT CHAR8 *Utf8Buffer > > > > > + ) > > > > > +{ > > > > > + UINT16 Ucs2Number; > > > > > + > > > > > + ASSERT (Utf8Buffer !=3D NULL); > > > > > + > > > > > + Ucs2Number =3D (UINT16) Ucs2Char; if (Ucs2Number <=3D 0x007F= ) { > > > > > + > > > > > + // > > > > > + // UTF8 format: 0xxxxxxx > > > > > + // > > > > > + *Utf8Buffer =3D Ucs2Char & 0x7F; > > > > > + return 1; > > > > > + > > > > > + } else if (Ucs2Number >=3D 0x0080 && Ucs2Number <=3D 0x07FF) = { > > > > > + > > > > > + // > > > > > + // UTF8 format: 110xxxxx 10xxxxxx > > > > > + // > > > > > + *(Utf8Buffer + 1) =3D (Ucs2Char & 0x3F) | 0x80; > > > > > + *Utf8Buffer =3D ((Ucs2Char >> 6) & 0x1F) | 0xC0; > > > > > + return 2; > > > > > + > > > > > + } else { /// Ucs2Number >=3D 0x0800 && Ucs2Number <=3D 0xFFF= F > > > > > + > > > > > + // > > > > > + // UTF8 format: 1110xxxx 10xxxxxx 10xxxxxx > > > > > + // > > > > > + *(Utf8Buffer + 2) =3D (Ucs2Char & 0x3F) | 0x80; > > > > > + *(Utf8Buffer + 1) =3D ((Ucs2Char >> 6) & 0x3F) | 0x80; > > > > > + *Utf8Buffer =3D ((Ucs2Char >> 12) & 0x0F) | 0xE0; > > > > > + return 3; > > > > > + } > > > > > +} > > > > > + > > > > > +/** > > > > > + Convert a UTF8 encoded data to a UCS2 character. > > > > > + > > > > > + @param[in] Utf8Buffer The provided UTF8 encode= d data. > > > > > + @param[out] Ucs2Char The converted UCS2 chara= cter. > > > > > + > > > > > + @retval EFI_INVALID_PARAMETER The UTF8 encoded string = is > not > > > > valid > > > > > or > > > > > + not for UCS2 character. > > > > > + @retval EFI_SUCCESS The converted UCS2 chara= cter. > > > > > + > > > > > +**/ > > > > > +EFI_STATUS > > > > > +UTF8ToUCS2Char ( > > > > > + IN CHAR8 *Utf8Buffer, > > > > > + OUT CHAR16 *Ucs2Char > > > > > + ) > > > > > +{ > > > > > + UINT8 Utf8Size; > > > > > + CHAR8 *Ucs2Buffer; > > > > > + CHAR8 TempChar1; > > > > > + CHAR8 TempChar2; > > > > > + CHAR8 TempChar3; > > > > > + > > > > > + ASSERT (Utf8Buffer !=3D NULL && Ucs2Char !=3D NULL); ZeroMem > > > > > + (Ucs2Char, sizeof (CHAR16)); Ucs2Buffer =3D (CHAR8 *) Ucs2Cha= r; > > > > > + > > > > > + Utf8Size =3D GetUTF8SizeForUCS2 (Utf8Buffer); switch > > > > > + (Utf8Size) { > > > > > + > > > > > + case 1: > > > > > + > > > > > + // > > > > > + // UTF8 format: 0xxxxxxx > > > > > + // > > > > > + TempChar1 =3D *Utf8Buffer; > > > > > + if ((TempChar1 & 0x80) !=3D 0x00) { > > > > > + return EFI_INVALID_PARAMETER; > > > > > + } > > > > > + > > > > > + *Ucs2Buffer =3D TempChar1; > > > > > + *(Ucs2Buffer + 1) =3D 0; > > > > > + break; > > > > > + > > > > > + case 2: > > > > > + > > > > > + // > > > > > + // UTF8 format: 110xxxxx 10xxxxxx > > > > > + // > > > > > + TempChar1 =3D *Utf8Buffer; > > > > > + if ((TempChar1 & 0xE0) !=3D 0xC0) { > > > > > + return EFI_INVALID_PARAMETER; > > > > > + } > > > > > + > > > > > + TempChar2 =3D *(Utf8Buffer + 1); > > > > > + if ((TempChar2 & 0xC0) !=3D 0x80) { > > > > > + return EFI_INVALID_PARAMETER; > > > > > + } > > > > > + > > > > > + *Ucs2Buffer =3D (TempChar1 << 6) + (TempChar2 & 0x3= F); > > > > > + *(Ucs2Buffer + 1) =3D (TempChar1 >> 2) & 0x07; > > > > > + break; > > > > > + > > > > > + case 3: > > > > > + > > > > > + // > > > > > + // UTF8 format: 1110xxxx 10xxxxxx 10xxxxxx > > > > > + // > > > > > + TempChar1 =3D *Utf8Buffer; > > > > > + if ((TempChar1 & 0xF0) !=3D 0xE0) { > > > > > + return EFI_INVALID_PARAMETER; > > > > > + } > > > > > + > > > > > + TempChar2 =3D *(Utf8Buffer + 1); > > > > > + if ((TempChar2 & 0xC0) !=3D 0x80) { > > > > > + return EFI_INVALID_PARAMETER; > > > > > + } > > > > > + > > > > > + TempChar3 =3D *(Utf8Buffer + 2); > > > > > + if ((TempChar3 & 0xC0) !=3D 0x80) { > > > > > + return EFI_INVALID_PARAMETER; > > > > > + } > > > > > + > > > > > + *Ucs2Buffer =3D (TempChar2 << 6) + (TempChar3 & 0x3= F); > > > > > + *(Ucs2Buffer + 1) =3D (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 strin= g > address. > > > > Caller > > > > > + is responsible for Free = this string. > > > > > + > > > > > + @retval EFI_INVALID_PARAMETER One or more parameters a= re > > > > 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 =3D=3D NULL || Utf8StrAddr =3D=3D NULL) { > > > > > + return EFI_INVALID_PARAMETER; } > > > > > + > > > > > + Ucs2StrLength =3D StrLen (Ucs2Str); Utf8StrLength =3D 0; > > > > > + > > > > > + for (Ucs2StrIndex =3D 0; Ucs2StrIndex < Ucs2StrLength; > > > > > + Ucs2StrIndex > > > > > + ++) { > > > > > + > > > > > + ZeroMem (Utf8Buffer, sizeof (Utf8Buffer)); > > > > > + Utf8BufferSize =3D UCS2CharToUTF8 (Ucs2Str[Ucs2StrIndex], > Utf8Buffer); > > > > > + Utf8StrLength +=3D Utf8BufferSize; } > > > > > + > > > > > + Utf8Str =3D AllocateZeroPool (Utf8StrLength + 1); if (Utf8St= r > > > > > + =3D=3D > > > > > + NULL) { > > > > > + return EFI_OUT_OF_RESOURCES; } > > > > > + > > > > > + Utf8StrIndex =3D 0; > > > > > + for (Ucs2StrIndex =3D 0; Ucs2StrIndex < Ucs2StrLength; > > > > > + Ucs2StrIndex > > > > > + ++) { > > > > > + > > > > > + ZeroMem (Utf8Buffer, sizeof (Utf8Buffer)); > > > > > + Utf8BufferSize =3D UCS2CharToUTF8 (Ucs2Str[Ucs2StrIndex], > > > > > + Utf8Buffer); > > > > > + > > > > > + CopyMem (Utf8Str + Utf8StrIndex, Utf8Buffer, Utf8BufferSize= ); > > > > > + Utf8StrIndex +=3D Utf8BufferSize; } > > > > > + > > > > > + Utf8Str[Utf8StrIndex] =3D '\0'; *Utf8StrAddr =3D Utf8Str; > > > > > + > > > > > + return EFI_SUCCESS; > > > > > +} > > > > > + > > > > > +/** > > > > > + Convert a UTF8 encoded string to a UCS2 string. > > > > > + > > > > > + @param[in] Utf8Str The provided UTF8 encode= d string. > > > > > + @param[out] Ucs2StrAddr The converted UCS2 strin= g > 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 a= re 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 =3D=3D NULL || Ucs2StrAddr =3D=3D NULL) { > > > > > + return EFI_INVALID_PARAMETER; } > > > > > + > > > > > + // > > > > > + // It is not an Ascii string, calculate string length. > > > > > + // > > > > > + Utf8StrLength =3D 0; > > > > > + while (*(Utf8Str + Utf8StrLength) !=3D '\0') { > > > > > + Utf8StrLength ++; > > > > > + } > > > > > + > > > > > + // > > > > > + // UCS2 string shall not be longer than the UTF8 string. > > > > > + // > > > > > + Ucs2StrTemp =3D AllocateZeroPool ((Utf8StrLength + 1) * sizeo= f > > > > > + (CHAR16)); if (Ucs2StrTemp =3D=3D NULL) { > > > > > + return EFI_OUT_OF_RESOURCES; } > > > > > + > > > > > + Utf8StrIndex =3D 0; > > > > > + Ucs2StrIndex =3D 0; > > > > > + while (Utf8Str[Utf8StrIndex] !=3D '\0') { > > > > > + > > > > > + if (CompareMem (Utf8Str + Utf8StrIndex, "\\u", 2) =3D=3D 0 = && > > > > > + Utf8StrLength - Utf8StrIndex >=3D UNICODE_FORMAT_LEN) { > > > > > + > > > > > + Status =3D GetUCS2CharByFormat (Utf8Str + Utf8StrIndex, > > > > > + Ucs2StrTemp + > > > > > Ucs2StrIndex); > > > > > + if (!EFI_ERROR (Status)) { > > > > > + > > > > > + Utf8StrIndex +=3D UNICODE_FORMAT_LEN; > > > > > + Ucs2StrIndex ++; > > > > > + } else { > > > > > + > > > > > + StrCpyS (Ucs2StrTemp + Ucs2StrIndex, 3, L"\\u"); > > > > > + > > > > > + Ucs2StrIndex +=3D 2; > > > > > + Utf8StrIndex +=3D 2; > > > > > + } > > > > > + } else { > > > > > + > > > > > + Utf8BufferSize =3D GetUTF8SizeForUCS2 (Utf8Str + Utf8StrI= ndex); > > > > > + if (Utf8BufferSize =3D=3D 0 || Utf8StrLength - Utf8StrInd= ex < > > > > > + Utf8BufferSize) { > > > > > + > > > > > + FreePool (Ucs2StrTemp); > > > > > + return EFI_INVALID_PARAMETER; > > > > > + } > > > > > + > > > > > + Status =3D UTF8ToUCS2Char (Utf8Str + Utf8StrIndex, > > > > > + Ucs2StrTemp > > > > > + + > > > > > Ucs2StrIndex); > > > > > + if (EFI_ERROR (Status)) { > > > > > + > > > > > + FreePool (Ucs2StrTemp); > > > > > + return EFI_INVALID_PARAMETER; > > > > > + } > > > > > + > > > > > + Ucs2StrIndex ++; > > > > > + Utf8StrIndex +=3D Utf8BufferSize; > > > > > + } > > > > > + } > > > > > + > > > > > + *Ucs2StrAddr =3D AllocateZeroPool ((Ucs2StrIndex + 1) * sizeo= f > > > > > + (CHAR16)); if (*Ucs2StrAddr =3D=3D NULL) { > > > > > + > > > > > + FreePool (Ucs2StrTemp); > > > > > + return EFI_OUT_OF_RESOURCES; } > > > > > + > > > > > + StrCpyS (*Ucs2StrAddr, Ucs2StrIndex + 1, Ucs2StrTemp); > > > > > + *(*Ucs2StrAddr + Ucs2StrIndex) =3D 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.
# > > > > > +(C) Copyright 2020 Hewlett Packard Enterprise Development LP > # > > > > > +# SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > +# > > > > > +## > > > > > + > > > > > +[Defines] > > > > > + INF_VERSION =3D 0x0001001b > > > > > + BASE_NAME =3D BaseUcs2Utf8Lib > > > > > + FILE_GUID =3D 536646C3-46D0-4B12-ABC4-CD= E1A33B5256 > > > > > + MODULE_TYPE =3D BASE > > > > > + VERSION_STRING =3D 1.0 > > > > > + LIBRARY_CLASS =3D Ucs2Utf8Lib > > > > > + > > > > > +# > > > > > +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 RISCV= 64 > > > > > +# > > > > > + > > > > > +[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 manipul= ation > > > > > + # 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/B > > > > PeCoffGetEntryPointLib|ase > > > > > PeCoffGetEntryPointLib.inf > > > > > SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf > > > > > + > > > > > > > > > > Ucs2Utf8Lib|MdeModulePkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.i > > > > Ucs2Utf8Lib|nf > > > > > # > > > > > # 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 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >=20 > > > > > > > > >