From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web08.14005.1607610472981763701 for ; Thu, 10 Dec 2020 06:27:53 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=ULO618EF; spf=pass (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=0613ff5add=abner.chang@hpe.com) Received: from pps.filterd (m0150245.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BAEIObF028769; Thu, 10 Dec 2020 14:27:06 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=6hA8lPdO18pnGNJu4Dcimkb+D6fxFt/vIy08t14Hxe8=; b=ULO618EFRdkJXwSzm53j+GvxiQqfXOG0BFmIgKdnWqddeAw8TqnxrRkNIX+c4d0ACOTF YOmoeoumvj9Gqc8BZb67VOsabLyQSeYJHf2jeoU6yNUb3hhr5BjGQZnyFcS6OvCvE9UN nV3hazVX6B5i7j33bGvKKwsQZ0FbmKJRy80CjFfjys4MxX+8UJ+gR+lj95EAhHOvrday 3uZREP8xIu9LkhQWr4ujDKjBoLCSQJa+BwmMz0Qn1mceFH6PX3i9LWTiYzGkAneO3zcQ 4abGd+tbEXlMtA6wr6oqjsT6Gws6EqkMuDj4V1urGb1l7XPr34EQx1d1ahB8f+EQvxrL Lg== Received: from g2t2353.austin.hpe.com (g2t2353.austin.hpe.com [15.233.44.26]) by mx0b-002e3701.pphosted.com with ESMTP id 35a90dma20-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Dec 2020 14:27:05 +0000 Received: from G1W8107.americas.hpqcorp.net (g1w8107.austin.hp.com [16.193.72.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g2t2353.austin.hpe.com (Postfix) with ESMTPS id 177BD94; Thu, 10 Dec 2020 14:27:02 +0000 (UTC) Received: from G9W8453.americas.hpqcorp.net (2002:10d8:a0d3::10d8:a0d3) by G1W8107.americas.hpqcorp.net (2002:10c1:483b::10c1:483b) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 10 Dec 2020 14:27:02 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (15.241.52.11) by G9W8453.americas.hpqcorp.net (16.216.160.211) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Thu, 10 Dec 2020 14:27:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CFNbdPHAygSZP0SYFlxFiPlx82lIHi6qgtogQgFKOpNf3MpjVcS9kkZFip4V+s26p2fxQQ3fPfsmUEiFXCYvr8v4sKzxy9qB6sfnLHIlrO0giapVYe7UXoinTbUpQcDbJbRdhRtCtahO3lZzXbNeZZvE/On7VjtZAEsaV7+9CU/OoSp/QcnGPL2QYvut91gFSpAK6rKaKT3M2eQpzJgUHxSV2vCkd6bdMCS3cOtiJyTpIiwKmyyggrw8v6w3zq58nsACw6qjcDVg+Qj47bdGvjZCVxLgUw+xcBe2rD3cNp9+RrT9SKD2/SuHJ6bj2AJNX8iQHX84W3ulkdYyrz5R9g== 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=yb0+cMeYIPKSfyXQvkbSAii99iSbFLRAJIhM2xiWcvc=; b=fC2Cayzyh0XgN4a+kOhIF+iDu3uEsBIaPmaBwBJqH5kqCODQV7PCM8GpiJLFY9V16kUiNyZGFiHdyzWVuYlCcPPP7wVatwdhVNc/H7lgJ+ZguXe7CzlhODjEf5vwdpI1kcn5y5UVkzI8e0wpe7K/Qetqd09VJuMCMSX0yPOD8pbhx4r/cEQREw412FTmtihMPymIicJP9qBY+2/RTE+cCmIfftqN3M8KUEqKf2+ZTV/lubBOlFKr0zSufGQGHXoVPMtUi2hLB90L/3dZ0pZ1QrO8PiejyhOgt+6zBxsXAjnJ5uaUubfczbs7+oCVBJLi+UAKXP4eM239yqHCrokRUw== 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 CS1PR8401MB1285.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:750a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.14; Thu, 10 Dec 2020 14:27:01 +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.3654.017; Thu, 10 Dec 2020 14:27:01 +0000 From: "Abner Chang" To: Samer El-Haj-Mahmoud , "devel@edk2.groups.io" CC: Liming Gao , Leif Lindholm , "Wang, Nickle (HPS SW)" , "O'Hanley, Peter (EXL)" Subject: Re: [edk2-devel] [PATCH v5 1/6] RedfishPkg/Ucs2Utf8lib: UCS2 to UFT8 manipulation library Thread-Topic: [edk2-devel] [PATCH v5 1/6] RedfishPkg/Ucs2Utf8lib: UCS2 to UFT8 manipulation library Thread-Index: AQHWzvs7wn9FNvJ9RUyyH8Z6l6BMxanwYDfg Date: Thu, 10 Dec 2020 14:27:01 +0000 Message-ID: References: <20201208021048.9104-1-abner.chang@hpe.com> <20201208021048.9104-2-abner.chang@hpe.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=hpe.com; x-originating-ip: [165.225.116.142] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 71ca16c9-6bbc-40f1-22b5-08d89d17a8ab x-ms-traffictypediagnostic: CS1PR8401MB1285: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:605; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: eHfy00B5vVZVdmlpMpW+7iiS2pGCS2oprIU7ShoGp2t+k60mQf7mbUoLP2EK9UzD5sdZCmtL8nSI8lLmRiAh0OSs8UnH1lH1AGx9wncv/xuGb79wW+xO7/eL8OY34bD/k8klSmJ06eV3RhboqJ+C2Z1rAEGkGYPwxXjX06xc2lQWBlrGioOto16O98NQ8BIIeA6H1/MwTn8I+nzRPQVDOhKIx2pQIGKThnos90kFydkW1+1CZK4roJSteaQiTbPbBh5Lz85kYTKHbI7ZajWT/YOYSQNB4vCBj28/XfiF9UzYXkLbZnV9/ZkHPd9Kil6TO5mQ8DqIQPbPvOnoMI+S43COwma8a1U75J4C+Exzmm/W1A44R39Ri8TgaDOwHlTwUhU//SudTQ5PYM0OOQbx/Q== 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:(376002)(346002)(136003)(366004)(110136005)(508600001)(30864003)(966005)(4326008)(5660300002)(19627235002)(76116006)(71200400001)(55236004)(7696005)(54906003)(83380400001)(53546011)(6506007)(8676002)(86362001)(8936002)(2906002)(9686003)(66556008)(66476007)(66446008)(33656002)(55016002)(66946007)(64756008)(186003)(52536014)(26005)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: 3KgR91ETMuUpZ9f2SM8VV1GX/XG8dsQpoDeDkX0NFOmQyN4dj7jD40lcOckYp4WLguQaAb7tiMT4EK0JcoNkAfQl6eFDYs7NM1kVAoRDUtkH12lTq0LZZEZkYQYtveAULDD3snTHcqPYILp5kNa4PbfHfXyzUkqb7PhHUUuUXMu3PsIVl4Vx4BBO0xfbaCobJGBSe/U5cJfpzjNcP68fG0oLCUMNyorFe+mWLM9ykADDrSmB4AXHQpJYc1hn6eSIPXvAvGkWAc6dkVrokqid/ksBhf8/26zINnofD+QnptCmbn+JIVmwmBQv7v4Hoi1PTYyEZ/MW9X0XQZp4J7mNEYvQLmyd+dFcDTS/GtWbYP9wpkqaIYJMUDe+6G1JSUfnnMy970UwecPO5sLGwaaMrXloXoRsNl3PfimQMyBA/rZWJRYTkvliJTXIJNnG5vbHGNL+zVBG0eeM0DuV8C18AlAM8VDoTlnRuk8NYuUy6032g4H7135YZZm1W+akhoqK/5/H3zSorO+Ey+T3SajlL1bqC9UMRhafXeONNKbDoqztMqIoWoHeIwj1CfAA/QXoMnMf9Smov1VLFd0Px95OO+dQx7iYDP/lLqQ+URXU08jnN7HWGIP1FxgsksTYT4WP5OCjFdmyJkJG+ZA4P27rd6t+bfsY3lpCBrnhFJXR6l12vodM/RsMbhCKlgzPYoMMt6fbFUuUGiljkVzfDrqZZRc2ERj/tBNCsB00fpP+lXmhfvQj8jraJjxiT1MouUlt X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 71ca16c9-6bbc-40f1-22b5-08d89d17a8ab X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Dec 2020 14:27:01.1102 (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: UOuf5i4VTuacyC2OZFHKjtZgXT02SgXauJMKeQgNI6O7qMZIc557tMGdLoaiamBKcAKsWIqS1hlFa+poUSs0lw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR8401MB1285 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-10_05:2020-12-09,2020-12-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 adultscore=0 mlxscore=0 priorityscore=1501 clxscore=1011 bulkscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012100090 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hah hah Samer, this file was originally went with JsonLib. Leif suggested t= o move UCS2-UTF8 functions to a separated lib under MdeModulePkg which was= a good idea as you mentioned. However the package steward would like to ke= ep this library in RedfishPkg and move it to under MdeModulePkg until more = use cases request this lib, this makes sense as well. I think we need a fight :) Abner > -----Original Message----- > From: Samer El-Haj-Mahmoud [mailto:Samer.El-Haj-Mahmoud@arm.com] > Sent: Thursday, December 10, 2020 9:49 PM > To: devel@edk2.groups.io; Chang, Abner (HPS SW/FW Technologist) > > Cc: Liming Gao ; Leif Lindholm > ; Wang, Nickle (HPS SW) ; > O'Hanley, Peter (EXL) ; Samer El-Haj-Mahmoud > > Subject: RE: [edk2-devel] [PATCH v5 1/6] RedfishPkg/Ucs2Utf8lib: UCS2 to > UFT8 manipulation library >=20 > Does this really need to be in RedfishPkg? Both UCS-S and UTF8 are stand= ard > and common formats, so It seems like a useful string manipulation librar= y > that may have other use cases? Maybe move it to MdeModulePkg? >=20 > > -----Original Message----- > > From: devel@edk2.groups.io On Behalf Of Abner > > Chang via groups.io > > Sent: Monday, December 7, 2020 9:11 PM > > To: devel@edk2.groups.io > > Cc: Liming Gao ; Leif Lindholm > > ; Nickle Wang ; Peter > O'Hanley > > > > Subject: [edk2-devel] [PATCH v5 1/6] RedfishPkg/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. > > > > Signed-off-by: Abner Chang > > > > Cc: Liming Gao > > Cc: Leif Lindholm > > Cc: Nickle Wang > > Cc: Peter O'Hanley > > --- > > RedfishPkg/Include/Library/BaseUcs2Utf8Lib.h | 69 +++ > > .../Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c | 417 > ++++++++++++++++++ > > .../BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf | 31 ++ > > RedfishPkg/RedfishLibs.dsc.inc | 1 + > > RedfishPkg/RedfishPkg.dec | 4 + > > RedfishPkg/RedfishPkg.dsc | 1 + > > 6 files changed, 523 insertions(+) > > create mode 100644 RedfishPkg/Include/Library/BaseUcs2Utf8Lib.h > > create mode 100644 > > RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c > > create mode 100644 > > RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf > > > > diff --git a/RedfishPkg/Include/Library/BaseUcs2Utf8Lib.h > > b/RedfishPkg/Include/Library/BaseUcs2Utf8Lib.h > > new file mode 100644 > > index 0000000000..51ae924929 > > --- /dev/null > > +++ b/RedfishPkg/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 string addr= ess. > Caller > > + is responsible for Free this s= tring. > > + > > + @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 be= en > > 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 stri= ng. > > + @param[out] Ucs2StrAddr The converted UCS2 string addr= ess. > > Caller > > + is responsible for Free this s= tring. > > + > > + @retval EFI_INVALID_PARAMETER The UTF8 encoded string is not > valid > > to > > + convert to UCS2 string. > > + One or more parameters are inv= alid. > > + @retval EFI_OUT_OF_RESOURCES System runs out of resources. > > + @retval EFI_SUCCESS The UCS2 string has been conve= rted. > > + > > +**/ > > +EFI_STATUS > > +UTF8StrToUCS2 ( > > + IN CHAR8 *Utf8Str, > > + OUT CHAR16 **Ucs2StrAddr > > + ); > > + > > +#endif > > diff --git a/RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c > > b/RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.c > > new file mode 100644 > > index 0000000000..6cff109a5c > > --- /dev/null > > +++ b/RedfishPkg/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 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 !=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 UTF8 bu= ffer. > > + > > + @param[in] Utf8Buffer The buffer for UTF8 encoded da= ta. > > + @param[out] Ucs2Char The converted UCS2 character. > > + > > + @retval EFI_INVALID_PARAMETER Non-Ascii characters found in = the > > hexadecimal > > + digits string, and can't be co= nverted to a UCS2 > > + character. > > + @retval EFI_SUCCESS The UCS2 character has been re= trieved. > > + > > +**/ > > +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 character. > > + @param[out] Utf8Buffer The converted UTF8 encoded dat= a. > > + > > + @retval Return the size of UTF8 encoding data for this UCS2 ch= aracter. > > + > > +**/ > > +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 0xFFFF > > + > > + // > > + // 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 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 !=3D NULL && Ucs2Char !=3D NULL); ZeroMem > > + (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 & 0x3F); > > + *(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 & 0x3F); > > + *(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 string addr= ess. > Caller > > + is responsible for Free this s= tring. > > + > > + @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 be= en > > 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], Utf8Buf= fer); > > + 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, 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 encoded stri= ng. > > + @param[out] Ucs2StrAddr The converted UCS2 string addr= ess. > > Caller > > + is responsible for Free this s= tring. > > + > > + @retval EFI_INVALID_PARAMETER The UTF8 encoded string is not > valid > > to > > + convert to UCS2 string. > > + One or more parameters are inv= alid. > > + @retval EFI_OUT_OF_RESOURCES System runs out of resources. > > + @retval EFI_SUCCESS The UCS2 string has been conve= rted. > > + > > +**/ > > +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 + Utf8StrIndex); > > + if (Utf8BufferSize =3D=3D 0 || Utf8StrLength - Utf8StrIndex < > > + 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/RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf > > b/RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf > > new file mode 100644 > > index 0000000000..ccd02ee320 > > --- /dev/null > > +++ b/RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf > > @@ -0,0 +1,31 @@ > > +## @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-CDE1A33B= 5256 > > + MODULE_TYPE =3D BASE > > + VERSION_STRING =3D 1.0 > > + LIBRARY_CLASS =3D Ucs2Utf8Lib > > + > > +# > > +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 RISCV64 > > +# > > + > > +[Sources.common] > > + BaseUcs2Utf8Lib.c > > + > > +[Packages] > > + MdePkg/MdePkg.dec > > + MdeModulePkg/MdeModulePkg.dec > > + RedfishPkg/RedfishPkg.dec > > + > > + > > diff --git a/RedfishPkg/RedfishLibs.dsc.inc > > b/RedfishPkg/RedfishLibs.dsc.inc index e780b5c270..d4c08e18ac 100644 > > --- a/RedfishPkg/RedfishLibs.dsc.inc > > +++ b/RedfishPkg/RedfishLibs.dsc.inc > > @@ -11,5 +11,6 @@ > > # > > ## > > !if $(REDFISH_ENABLE) =3D=3D TRUE > > + Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf > > !endif > > > > diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec > > index b38e9b4789..aecc1f4a3a 100644 > > --- a/RedfishPkg/RedfishPkg.dec > > +++ b/RedfishPkg/RedfishPkg.dec > > @@ -20,6 +20,10 @@ > > ## @libraryclass Platform Redfish Host Interface Library > > # Platform implementation-specific Redfish Host Interface. > > > > RedfishPlatformHostInterfaceLib|Include/Library/RedfishHostInterfaceLi > > RedfishPlatformHostInterfaceLib|b.h > > + ## @libraryclass This library provides UCS2 to UTF8 manipulation > > + # functions. > > + # > > + Ucs2Utf8Lib|Include/Library/BaseUcs2Utf8Lib.h > > > > [Protocols] > > ## Include/Protocol/RedfishDiscover.h > > diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc > > index > > 94e7127bc6..d198a94b73 100644 > > --- a/RedfishPkg/RedfishPkg.dsc > > +++ b/RedfishPkg/RedfishPkg.dsc > > @@ -43,5 +43,6 @@ > > > > [Components] > > > > RedfishPkg/Library/PlatformHostInterfaceLibNull/PlatformHostInterfaceL > > ibN > > ull.inf > > + RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf > > > > !include RedfishPkg/Redfish.dsc.inc > > -- > > 2.17.1 > > > > > > > >=20 > > >=20 > IMPORTANT NOTICE: The contents of this email and any attachments are > confidential and may also be privileged. If you are not the intended rec= ipient, > please notify the sender immediately and do not disclose the contents to= any > other person, use it for any purpose, or store or copy the information i= n any > medium. Thank you.