From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (EUR02-VE1-obe.outbound.protection.outlook.com [40.107.2.88]) by mx.groups.io with SMTP id smtpd.web12.13001.1607608172619562777 for ; Thu, 10 Dec 2020 05:49:33 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=yI1v0vPL; spf=pass (domain: arm.com, ip: 40.107.2.88, mailfrom: samer.el-haj-mahmoud@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tV622BV0WWsISBdkRgR8lF8FM09m9oLKGvZmT/V5nTQ=; b=yI1v0vPLMFzaezHn4FgnO9n3vWsO2LllGLJuQE7ryzH1cNTKJ2qluyUxMThqUrZz2GuuRGhjj7Qn/7oXYVrg97K6bg0vFCjzLyiMveREeA7P9zISgwdcGq3EIQ17+bnyLnpyJzLkPA2RNas342QLqASP2Ipyb1r8iu9ryeI6dlY= Received: from AM5PR0602CA0005.eurprd06.prod.outlook.com (2603:10a6:203:a3::15) by HE1PR0801MB2108.eurprd08.prod.outlook.com (2603:10a6:3:51::20) 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 13:49:28 +0000 Received: from VE1EUR03FT004.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:a3:cafe::fe) by AM5PR0602CA0005.outlook.office365.com (2603:10a6:203:a3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Thu, 10 Dec 2020 13:49:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT004.mail.protection.outlook.com (10.152.18.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Thu, 10 Dec 2020 13:49:28 +0000 Received: ("Tessian outbound 8b6e0bb22f1c:v71"); Thu, 10 Dec 2020 13:49:27 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: a3f2ac835a9de696 X-CR-MTA-TID: 64aa7808 Received: from 14768c762403.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id BC393E0B-90B3-4C06-8068-AD76BC5918C2.1; Thu, 10 Dec 2020 13:49:11 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 14768c762403.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 10 Dec 2020 13:49:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Evqg5v4au1WITWBe3iBJneOCum2pEnghI56SKnzT3DIPhIzkx9JSQMbymmnPnmsQOnXoYKgF6NLv6MmJNv/sqpnx5a4ryF9R9aKaSiVHILhBl5YQd1KbruLA+NcDOKyblU8joLk4d4/YNMzpcZLaq89/TeVnXHRhXXrvG8EkNuqqXcI/kmMwWvYLHnZWvYLLNMQukfl1AiceqmLS8G1EWjIYqJtoZlfmsC+QLCGJJhkyZWmId4l8jJPM2eEJECSbnQuEYSg/bBoWAQnsm2LxtRNVfSdJTcaSaFav/rbj8O0XPEuEAUCJFLKBQwSA6Eq0ZKiNbjwbqO5YFuA4MKhhYQ== 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=tV622BV0WWsISBdkRgR8lF8FM09m9oLKGvZmT/V5nTQ=; b=KRXrd/q0KanQKtfW8wPwFiPuGCpazwIcOxGvuu5TpVFu2rX9Y+qGHBTMwjQv8lCoWDmhxMavGRIr9WbQF3ULg9KdC+M6sI/V65Uhn7xK9pxe9YOc0OToM8Ym/RaliBkcZ9xR+DkVdlxpoSNJVBP5bKp1yJeTOq/lylaumaeC98jVMibf4mf0T3bJ6iUl0L06dZPAqzS4LSlNNwSm5ylnYZ3kw9/87qodE6JtfXzGMx5FB+7Jk9Wc12H8iHF1fZfVvx/LkCqhlkMmitJIHugULMi3UIHZVDfkaTFkhwp/Q/uittqorXnlbPxoGlnMZlhvpQNbG7rA479OSFM/Zvizpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tV622BV0WWsISBdkRgR8lF8FM09m9oLKGvZmT/V5nTQ=; b=yI1v0vPLMFzaezHn4FgnO9n3vWsO2LllGLJuQE7ryzH1cNTKJ2qluyUxMThqUrZz2GuuRGhjj7Qn/7oXYVrg97K6bg0vFCjzLyiMveREeA7P9zISgwdcGq3EIQ17+bnyLnpyJzLkPA2RNas342QLqASP2Ipyb1r8iu9ryeI6dlY= Received: from DB7PR08MB3260.eurprd08.prod.outlook.com (2603:10a6:5:21::23) by DB8PR08MB5324.eurprd08.prod.outlook.com (2603:10a6:10:11e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12; Thu, 10 Dec 2020 13:49:09 +0000 Received: from DB7PR08MB3260.eurprd08.prod.outlook.com ([fe80::a1f1:ccfd:b17f:a490]) by DB7PR08MB3260.eurprd08.prod.outlook.com ([fe80::a1f1:ccfd:b17f:a490%5]) with mapi id 15.20.3654.012; Thu, 10 Dec 2020 13:49:09 +0000 From: "Samer El-Haj-Mahmoud" To: "devel@edk2.groups.io" , "abner.chang@hpe.com" CC: Liming Gao , Leif Lindholm , Nickle Wang , Peter O'Hanley , Samer El-Haj-Mahmoud 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: AQHWzQ58Fb40FbSVP021F+9KDWsWMqnwXACQ Date: Thu, 10 Dec 2020 13:49:09 +0000 Message-ID: References: <20201208021048.9104-1-abner.chang@hpe.com> <20201208021048.9104-2-abner.chang@hpe.com> In-Reply-To: <20201208021048.9104-2-abner.chang@hpe.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Authentication-Results-Original: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=arm.com; x-originating-ip: [99.132.126.10] x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e113f780-cd84-47b9-41b4-08d89d1269cf x-ms-traffictypediagnostic: DB8PR08MB5324:|HE1PR0801MB2108: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:1303;OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: WuTpNS1KBkEhymovPkLU7sJ1PIowFGxzZlOICsDlpywetrozs3V2aoXRIODqQWldLyC6FfXxBG605CuQRTTJV+MM5pwP8vrmzV/cFpZzISj2K/EjTDA9cLicW6hKW6SrI9r440H20B3UldLtRSxoAhiDszaBuPKWSftuHTk/TsraAA9O+2SMBuWjoeY1gUX58XSNkXzbpmrEg4fagE2hVUKAKcgnviNcdct84P4g4+HSHkjjj7vbmGqei/MeXiBkFkuusbiGKz/uQdXz/jzk8zFgMANbYH+OZ+OuNRkQc0mJDhaqFXmawaU7RX7X4XxG/5w5E88ohhmpP4C1ALZX86fd1q0Vbr0hC06VvkbF5AKZ3tYRFrIL1RL39Ahsd9/Gl+VTeQDN3BoDxHW5y3IGNg== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR08MB3260.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(366004)(346002)(396003)(39850400004)(52536014)(66556008)(7696005)(186003)(30864003)(83380400001)(5660300002)(4326008)(76116006)(2906002)(66446008)(316002)(8936002)(86362001)(55016002)(110136005)(54906003)(33656002)(53546011)(71200400001)(19627235002)(478600001)(6506007)(64756008)(66946007)(66476007)(26005)(8676002)(9686003)(966005)(579004);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?y05xxBwqvjPoA0LcwpNKnB4R2TLGBXuKNIWySNId0sJSwyCi/CKmBlJo5+al?= =?us-ascii?Q?dGAkaED68vsMZVxCh551S+e6EurI60Yi8V3JyTt3orM73FoqPEqFcIBgu99o?= =?us-ascii?Q?jKLAwwRg/ySl8S6CP6KgUIa7JnjOtpqSgCLab/2sWQH/K4E4bU/kKtJW2mpX?= =?us-ascii?Q?yO/ShnzWuVzdysrZzYNjXhx242esX0tzL1yjZNR0Np/8nql43vu+B+C06cFi?= =?us-ascii?Q?cyhb6y9WUeBlHBybAePkN97XxbEcLOZtXfyI97sOyy5i4+MafVGAIJ/q9RE3?= =?us-ascii?Q?cwyEG5xMEWJPDf19ZMkOFAa3U2Bna9m6ByF0pbBAx2wf//TXMgSHQngFLq/8?= =?us-ascii?Q?S5t3Whh/jwrjMWbTOg2x/ORCFr7DSHHa27hAE45thQQAeaXEgfDYP+pK4Wfb?= =?us-ascii?Q?kHNyuDrzyIxEJxMnZ0Xt+ue7VHyi2GHY4LBYK/QHZqlz/7SOE10IC9WRToDE?= =?us-ascii?Q?UhVCDjXbWGiFVGvXlgEywLJF3Q4r3HlrQGw/fnQ1H4bUzJSCXnfE5A7ZNPUl?= =?us-ascii?Q?kBnXjhRUkwmTUW28rDHQ6Jz5Ut181G3RBBhuBpZ5arz28O0+6WI/ftBsiFqA?= =?us-ascii?Q?3Cjn/Iqe4R1jeam0dhnf/ItTnrN1a9qlTMRiGPMj4feL1zgxxAfZ8S5+Hq82?= =?us-ascii?Q?UkhBL+TWpgrYeHqr0JaA2e2Enc+jcSzZyx+JELIUebfXYU7gqG4kxN0H4gIx?= =?us-ascii?Q?u/AXf3dWN9oVt/7DNtgc4CnUlvqx4nBzDbNpNO60UUwV2XDXuBmsi4sCrTUY?= =?us-ascii?Q?9RI04x/VIlkb7A+fIPNfC+30au9V/liYLPoFHSZ4W2KFK3UqtcpjajbPhN73?= =?us-ascii?Q?F8dwwBuKGETUDHZ3yksUmVOXXoOwXINRs6+NXEButLe8Mnd7+4/wKxPGJzHj?= =?us-ascii?Q?aAMx2STm/MR/NZ0sOYDBif8gtT1Ya+aASF9rQwGgCKTWwC2OF0dpkukwz02V?= =?us-ascii?Q?Yr2ouskjTNPwA/7uhjZyo3+1zg2ya6tbboR5cFjgeY4=3D?= MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5324 Original-Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=arm.com; Return-Path: Samer.El-Haj-Mahmoud@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT004.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 6f501e90-5721-4c2a-1ec7-08d89d125e77 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fIfOaHMX/Udjnt9QCxuOOA0/LtkTMF+RcrEheChOvpavt05ixEDcEUldi++nz+N0CMYt3vuR6XexBiJU+dsyRrF1ivpOXNaJwaUY4luGWQx9b4/q+PN9uNrPb6v7o0JCbntgL5ruZNRpljOt2w7DMfFTIE9qTXmYwAzh+v1XDmih1Lfbm3h6eUfMS7jQ7OryJccRcGY3xdNkaNkkTSQs3jyDTyk+lKKlMUTKnKRieekcHjl7W8oaWJJa4Bcu51kAie/6bO1iL0tzjSQjJmmJAuix5fFgHHfxThddGUdchON30hPdwUYzrUkWodeCXgKUgIrb4eRtz+ZJyhQqywzPbAmJ7tRmK29qeMG1l5ZalWTruANbZctXxEZmTog+aQYiTFrksIUH8JXmZHL0rXxx1y2mP9LPEhR+FAJJnxdECwP41Nt/BQGpudOlbKQlQqo8u/42Y6iZluhbh4uWGfT98fFtK4ffqshg5iUwUnDXgCE= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(4636009)(39860400002)(136003)(346002)(376002)(396003)(46966005)(8676002)(86362001)(82310400003)(4326008)(19627235002)(966005)(55016002)(33656002)(9686003)(6506007)(53546011)(5660300002)(30864003)(26005)(186003)(52536014)(336012)(2906002)(47076004)(316002)(356005)(478600001)(83380400001)(7696005)(81166007)(54906003)(70206006)(82740400003)(70586007)(110136005)(8936002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2020 13:49:28.1358 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e113f780-cd84-47b9-41b4-08d89d1269cf X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT004.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB2108 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Does this really need to be in RedfishPkg? Both UCS-S and UTF8 are standard= and common formats, so It seems like a useful string manipulation library = that may have other use cases? Maybe move it to MdeModulePkg? > -----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 UFT= 8 > 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 s= ource > 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 addres= s. Caller > + is responsible for Free this str= ing. > + > + @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 addres= s. > Caller > + is responsible for Free this str= ing. > + > + @retval EFI_INVALID_PARAMETER The UTF8 encoded string is not v= alid > to > + convert to UCS2 string. > + One or more parameters are inval= id. > + @retval EFI_OUT_OF_RESOURCES System runs out of resources. > + @retval EFI_SUCCESS The UCS2 string has been convert= ed. > + > +**/ > +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 no= t 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 buff= er. > + > + @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 th= e > hexadecimal > + digits string, and can't be conv= erted to a UCS2 > + character. > + @retval EFI_SUCCESS The UCS2 character has been retr= ieved. > + > +**/ > +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 data. > + > + @retval Return the size of UTF8 encoding data for this UCS2 char= acter. > + > +**/ > +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 v= alid > 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 (Ucs2Ch= ar, > + 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 addres= s. Caller > + is responsible for Free this str= ing. > + > + @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 =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], Utf8Buffe= r); > + 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 string= . > + @param[out] Ucs2StrAddr The converted UCS2 string addres= s. > Caller > + is responsible for Free this str= ing. > + > + @retval EFI_INVALID_PARAMETER The UTF8 encoded string is not v= alid > to > + convert to UCS2 string. > + One or more parameters are inval= id. > + @retval EFI_OUT_OF_RESOURCES System runs out of resources. > + @retval EFI_SUCCESS The UCS2 string has been convert= ed. > + > +**/ > +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, Ucs2StrTe= mp + > 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-CDE1A33B52= 56 > + 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/RedfishHostInterfaceLib.= 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/PlatformHostInterfaceLib= N > ull.inf > + RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf > > !include RedfishPkg/Redfish.dsc.inc > -- > 2.17.1 > > > >=20 > IMPORTANT NOTICE: The contents of this email and any attachments are confi= dential and may also be privileged. If you are not the intended recipient, = please notify the sender immediately and do not disclose the contents to an= y other person, use it for any purpose, or store or copy the information in= any medium. Thank you.