From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web09.3052.1607396396205162178 for ; Mon, 07 Dec 2020 18:59:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=hHB/2lNv; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=0611956627=abner.chang@hpe.com) Received: from pps.filterd (m0150242.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0B82r6MC013747; Tue, 8 Dec 2020 02:59:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pps0720; bh=AT8+XCpZV/LpAU0itZ2a3uJj2vyOT0neWoiNEuUi/AM=; b=hHB/2lNvJm6Tgc5Nw9z5E58jBY8igxNUvqQwdlS1hHDBcVtuKryUl5WeClb5Ubb5ty+l H2/YBzy+Vq/CFkesUcN20BFyVSBtQqYMqc3G1pkaVWh5sessn56IbT16jAPcKdZr0sFe kZe1Lj+1bYssLn4RYzaHdte9ShmC0M7OquNjVAtZBJoZlAZoVdG4vheFbgcHueEhfhYq CbPBQ2RXdc03mxHp9J76c3vafA5eq9lFwnFRPWeV4oh6RpBH+VryNsAxbI4l3dJ4pB+Z 10WjPQka+9/wnpTmLOJ/6PSdLyADp4X8KaSeG50LVIHzKKA7mgzBAziz0qmOYmvSwwyb qg== Received: from g4t3425.houston.hpe.com (g4t3425.houston.hpe.com [15.241.140.78]) by mx0a-002e3701.pphosted.com with ESMTP id 358knu5cru-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Dec 2020 02:59:51 +0000 Received: from G1W8106.americas.hpqcorp.net (g1w8106.austin.hp.com [16.193.72.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g4t3425.houston.hpe.com (Postfix) with ESMTPS id D3E83B9; Tue, 8 Dec 2020 02:59:50 +0000 (UTC) Received: from G9W8669.americas.hpqcorp.net (16.220.49.28) by G1W8106.americas.hpqcorp.net (16.193.72.61) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Dec 2020 02:59:39 +0000 Received: from G2W6311.americas.hpqcorp.net (16.197.64.53) by G9W8669.americas.hpqcorp.net (16.220.49.28) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Dec 2020 02:59:39 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (15.241.52.12) by G2W6311.americas.hpqcorp.net (16.197.64.53) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Tue, 8 Dec 2020 02:59:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f0luCMBQrzAWvF06O/1Sg0Wo5lFBR4MjUJncgzuHojoy95NrS1Iy86KXDMGh5t5IAVP2fS2wWuROPLidxumqJuK6VCqmSeogx7uuc8+SQWmoHrCurTUMidDQMbu6MdweV9kENoZl0yc1ly5msOEY5N33EeWpmwtfoKEzryxSDEz0pmnzN27FYas+0HWsKiawNpF/2qxQ7fJLvpnOxza7kBS2C1/Uteh296XFHCcGnlyCBHXNl6IddrP2JU8sP0T9iVRY9WXh2wR8qnruy/FssOKrfr8hpneyR41Vm4WHtINZxWU2F9krR6j5hSVAF2kn7KqR2SGUmRMnpLRRtNx5mA== 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=j4rZ1QBST8nEp15e3qnkXRIzhOZJYR8D8OGPB/TgxjE=; b=a3/KY9SxDJN0l5Kvxa18UQteRl//MNLroZoPp3ZQvO8ednQg3L7wET6WcnGsD7B3FAHhlrYcJ19pG5sipvGR3J2J4ZLXhjnCcYdduuRRortAXKqLl0x6/0fFBNcMq/7yyJwF6FsgS32fpDR2cFuXMJ4WHOhGRPj3CTQXN+Qbk59zjx79a4Xo5yTXJWsbdyqIVrLXrOtxApAlNPRsgQFObIaPK2fSU9YswpFdbqg1JvNF07nLkYtd9I2CNYIZ21EnuxLbvtuJN/YzvNVashDJjqVf3/eDOQYJWRAkSRsNC7QcO+DgNf3ZN0NhBZnP2XUGcz7Mwk4wDZBefjj0B9T55w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none Received: from CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7508::16) by CS1PR8401MB0424.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7510::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17; Tue, 8 Dec 2020 02:59:37 +0000 Received: from CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM ([fe80::a094:ed67:fb40:340e]) by CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM ([fe80::a094:ed67:fb40:340e%10]) with mapi id 15.20.3632.021; Tue, 8 Dec 2020 02:59:37 +0000 From: "Abner Chang" To: "Wu, Hao A" , Leif Lindholm CC: "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: AQHWzGdSODE2j4SORkSZswTYVXEBGKnrPB1ggAAB1YCAAKPQgIAAfEwAgAAlTZA= Date: Tue, 8 Dec 2020 02:59:37 +0000 Message-ID: References: <20201207053655.29101-1-abner.chang@hpe.com> <20201207053655.29101-2-abner.chang@hpe.com> <20201207172039.GF1664@vanye> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=hpe.com; x-originating-ip: [16.242.247.131] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: d879d496-327f-4c91-bf6a-08d89b254cc1 x-ms-traffictypediagnostic: CS1PR8401MB0424: 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: G1MJYpWKtcLZqSl8sW0m0rNnPERuBrpEax4FJbj5bmsn2wQIP6N2DhmbZUOYMhLOgcQscRZi60YeG6DiB4htkQg9LBUpGBhWRHOO968XhcBdcCrOnCe8B/obLjBT7vvp6QQWsAnldwxvs65X2Xyf+qZtbzK8vkJ9iURAiGIER3rF9KREiIqxFhD04PLrEGAd9EsTNaJUOH8YcdFgCt6lMx9du23OoSrfhzGzGTeOnkvOP/3vWRe15P1Uv0vFmA2xyvEbXo/4KFGUM9OiZmnnPihIa7zxjW4wKTq1cJwyjfD/vnJCfc4fChtX4jhW2W1cQL8Eic7/Zy+tu8lcMtsZwBd5A7/9SQqkBAhFI9vtAud0EA+K33bAimFS+dnu1pkRJAM7HjVBFZNecVktGZJ0OA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(39860400002)(136003)(396003)(346002)(366004)(376002)(83380400001)(66476007)(66556008)(26005)(54906003)(5660300002)(186003)(6506007)(110136005)(8676002)(33656002)(64756008)(316002)(76116006)(66946007)(966005)(30864003)(66446008)(55016002)(52536014)(478600001)(9686003)(7696005)(86362001)(2906002)(53546011)(19627235002)(8936002)(4326008)(71200400001)(559001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?d+4DlMWKQkaTJ3NTGtCWtd4UreuUobZdqBqCchX630HH6vzfKdfs6gl4sWxW?= =?us-ascii?Q?ZcY6RrDCGYegGF3uh757J1WS+O40Yu7fkYiyvNRTeUkcYBqTMciE2Y3C7eAX?= =?us-ascii?Q?wGJrakkjpxIRfmQcMvhWKYw4kG6Kqs9lY8McT4MiV27RrSXCALptFYWy3dQB?= =?us-ascii?Q?/2YNt9DhdJI85ztmKXN38WTydNm3/FOu7ff4KgvPD16A1XJCLou9JDcMG9GL?= =?us-ascii?Q?mZqD21a95Xmj/lYf2PKtr99NT7aFGxwN/EWhYFDhbmvzc/gry9QpVkVda53+?= =?us-ascii?Q?Zyfy+JGCpdYQXbeEYj0awiZZVsBLa1kUU0zUxoOR7bzZ+X9KzOfoCooFuXbr?= =?us-ascii?Q?9nYvg4kSZOqZFDMwEUAbEXdDnqjQ6Nr3GDQtdEnTeY/cVuBsHGbm/97U8Ha1?= =?us-ascii?Q?L4/DxcjM5ai40g+YM443Rd6oAYOHrjMAk/28/jH3Pu8m3xzCKc2pMNc15R3s?= =?us-ascii?Q?rMyXS71vwQMm/+zR5MCOhnns/8e4J9B6ItfKzItLSrliXCuBZQS7t45Gb6m6?= =?us-ascii?Q?mrQ5DmRKbVQXAKOI+bKCJ+p6Wjr7O+ozVuBPA3cm2cQZ2HTThzVKkM5jZdfy?= =?us-ascii?Q?Dw61ou14eBEctzpFNoulKxMZQod4gyxbGJsZW+iWf5WyXArOfK0tPXz56ee6?= =?us-ascii?Q?Su57kv+375/F4h94NhJPH97YbsqfJlELhhhcR41o8m5DkXdlM6Zy3SD7pPjU?= =?us-ascii?Q?gp0fPSrEjAmCsthNoiuIffNs59f1h8Jt64RualEmsw7S70OlwzAoSrwNDIai?= =?us-ascii?Q?wNOZ2s8Ti7tMgGY/pzjVWDhs2zfZpP0uGQ72trlQJ0PPGuYHb2eVk49ebWA3?= =?us-ascii?Q?vPBg3iWzxXyAeFHf7O6WZdiT69wvis4rTSm97w7AZXjZlbhy323WEdnBeTwZ?= =?us-ascii?Q?s5kcPFboW6Sy+7uqvGTBomZL2tTBoAmovvdJlQ66bwYWgCGPLew/tu26pjLw?= =?us-ascii?Q?gVHDzHrE1ki8R9sOomkR4CBEIm/eqnVRIsiEp5orN5Y=3D?= X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: d879d496-327f-4c91-bf6a-08d89b254cc1 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Dec 2020 02:59:37.5996 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Cdp1T/DzUAtJ0SMjBFr8K1GQY3oOrcNpo3it+LW5lxYaAnGs3YwR3WV4xwxHplxWTssKWhFHYJHze/Zk/dpvnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR8401MB0424 X-OriginatorOrg: hpe.com X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2020-12-07_19:2020-12-04,2020-12-07 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 clxscore=1015 bulkscore=0 malwarescore=0 impostorscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012080017 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable V5 sent, in which BaseUcs2Utf8Lib is moved to under RedfishPkg. thanks Abner > -----Original Message----- > From: Wu, Hao A [mailto:hao.a.wu@intel.com] > Sent: Tuesday, December 8, 2020 8:46 AM > 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 >=20 > > -----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 > > > > Hi Hao Wu, > > > > 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 > > > > > 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 > > > > > > > > > Thanks Abner. > > > Leif and Liming, do you have comments on this? Thanks. > > > > I was the one who suggested Abner try to add it to MdeModulePkg, since > > it sounded to me like a generically useful thing to have. >=20 >=20 > Agree that the library looks like a generic one. >=20 > I should have been involved in the discussion earlier. > Sorry for the late response. >=20 >=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. >=20 >=20 > Thanks. >=20 > Best Regards, > Hao Wu >=20 >=20 > > > > Best Regards, > > > > Leif > > > > > 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 stri= ng. > > > > > > + @param[out] Utf8StrAddr The converted UTF8 str= ing > > address. > > > > > Caller > > > > > > + is responsible for Fre= e 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 strin= g 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 enco= ded string. > > > > > > + @param[out] Ucs2StrAddr The converted UCS2 str= ing > > address. > > > > > > Caller > > > > > > + is responsible for Fre= e this string. > > > > > > + > > > > > > + @retval EFI_INVALID_PARAMETER The UTF8 encoded strin= g 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 be= en > 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 d= ata. > > > > > > + > > > > > > + @retval Return the size of UTF8 encoding string or 0 i= f 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 forma= t. > > > > > > + Call MUST make sure there are at least 6 Bytes in the input > > > > > > +UTF8 > > buffer. > > > > > > + > > > > > > + @param[in] Utf8Buffer The buffer for UTF8 en= coded data. > > > > > > + @param[out] Ucs2Char The converted UCS2 cha= racter. > > > > > > + > > > > > > + @retval EFI_INVALID_PARAMETER Non-Ascii characters f= ound > > 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 =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 char= acter. > > > > > > + @param[out] Utf8Buffer The converted UTF8 enc= oded > 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 !=3D NULL); > > > > > > + > > > > > > + Ucs2Number =3D (UINT16) Ucs2Char; if (Ucs2Number <=3D 0x00= 7F) > > > > > > + { > > > > > > + > > > > > > + // > > > > > > + // 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 0xF= FFF > > > > > > + > > > > > > + // > > > > > > + // 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 enco= ded data. > > > > > > + @param[out] Ucs2Char The converted UCS2 cha= racter. > > > > > > + > > > > > > + @retval EFI_INVALID_PARAMETER The UTF8 encoded strin= g is > > not > > > > > valid > > > > > > or > > > > > > + not for UCS2 character= . > > > > > > + @retval EFI_SUCCESS The converted UCS2 cha= racter. > > > > > > + > > > > > > +**/ > > > > > > +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); ZeroM= em > > > > > > + (Ucs2Char, sizeof (CHAR16)); Ucs2Buffer =3D (CHAR8 *) > > > > > > + Ucs2Char; > > > > > > + > > > > > > + 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 & 0= x3F); > > > > > > + *(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 & 0= x3F); > > > > > > + *(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 stri= ng. > > > > > > + @param[out] Utf8StrAddr The converted UTF8 str= ing > > address. > > > > > Caller > > > > > > + is responsible for Fre= e 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 strin= g 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 > > > > > > + (Utf8Str =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, Utf8BufferSi= ze); > > > > > > + 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 enco= ded string. > > > > > > + @param[out] Ucs2StrAddr The converted UCS2 str= ing > > address. > > > > > > Caller > > > > > > + is responsible for Fre= e this string. > > > > > > + > > > > > > + @retval EFI_INVALID_PARAMETER The UTF8 encoded strin= g 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 be= en > 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) * > > > > > > + sizeof (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 + Utf8St= rIndex); > > > > > > + if (Utf8BufferSize =3D=3D 0 || Utf8StrLength - Utf8StrI= ndex > > > > > > + < > > > > > > + 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) * > > > > > > + sizeof (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-= CDE1A33B5256 > > > > > > + MODULE_TYPE =3D BASE > > > > > > + VERSION_STRING =3D 1.0 > > > > > > + LIBRARY_CLASS =3D Ucs2Utf8Lib > > > > > > + > > > > > > +# > > > > > > +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 RIS= CV64 > > > > > > +# > > > > > > + > > > > > > +[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/VariablePolicyHelperLi= b. > > > > > > h > > > > > > > > > > > > + ## @libraryclass This library provides UCS2 to UTF8 manip= ulation > > > > > > + # 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 > > > > > > > > > > > >