From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: solarflare.com, ip: 67.231.154.164, mailfrom: tzhao@solarflare.com) Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) by groups.io with SMTP; Fri, 30 Aug 2019 04:34:07 -0700 X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (uk.solarflare.com [193.34.186.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mx1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id 5B68B780069; Fri, 30 Aug 2019 11:34:06 +0000 (UTC) Received: from [10.17.20.221] (10.17.20.221) by ukex01.SolarFlarecom.com (10.17.10.4) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 30 Aug 2019 12:33:59 +0100 From: "Tom Zhao" Subject: [PATCH v2 1/1] MdePkg: UefiLib: Add a function to check if a language is supported To: CC: Liming Gao , Michael D Kinney Message-ID: <7fd22bc9-2a47-6e04-8541-fb73577f0cc0@solarflare.com> Date: Fri, 30 Aug 2019 12:33:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 X-Originating-IP: [10.17.20.221] X-ClientProxiedBy: ocex03.SolarFlarecom.com (10.20.40.36) To ukex01.SolarFlarecom.com (10.17.10.4) X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1010-24878.003 X-TM-AS-Result: No-2.553000-8.000000-10 X-TMASE-MatchedRID: vdeff2Q33gV6bMYbioM9qS34IE4ZChe2NV9S7O+u3Kbg91xayX4L823g 0eMGSIkiXTVY05/KKkVhMEy40NN7RyHhSBQfglfsA9lly13c/gGv1lSTXS1ExSS30GKAkBxWw/Y kY/SyDMZASDh6kBpr/Z2oLZ8u2T3ETX7PJ/OU3vK9oxGQAU8pjd0H8LFZNFG76sBnwpOylLOKGo 2JfK7OA+jnEIAlI8J+mb5fzXEq8z0DopQxqZzKvU+PxfaC4LM3ut7rusTQskyxBSj+6feB8WjyK 9EmhcweonhnweL/z8RazAigVxdXeiNlTYIDFiQj+C4IK5rEYL08DQfgROz55X7cGd19dSFd X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--2.553000-8.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1010-24878.003 X-MDID: 1567164847-g91pG9rB1TCk Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=2100 Add a function that checks if a target language is in the supported languages list. Refactor UefiLib to use this function where appropriate internally. Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Zhao --- MdePkg/Include/Library/UefiLib.h | 16 ++++++ MdePkg/Library/UefiLib/UefiLib.c | 59 +++++++++++++------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h index 1650f30ddbc6..9dd170cbe2bf 100644 --- a/MdePkg/Include/Library/UefiLib.h +++ b/MdePkg/Include/Library/UefiLib.h @@ -461,6 +461,22 @@ EfiTestChildHandle ( IN CONST EFI_GUID *ProtocolGuid ); +/** + * This function checks the supported languages list for a target language + * + * @param SupportedLanguages The supported languages + * @param TargetLanguage The target language + * + * @return Returns EFI_SUCCESS if the language is supported, + * EFI_UNSUPPORTED otherwise + */ +EFI_STATUS +EFIAPI +IsLanguageSupported ( + IN CONST CHAR8 *SupportedLanguages, + IN CONST CHAR8 *TargetLanguage + ); + /** This function looks up a Unicode string in UnicodeStringTable. diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c index daa4af762e62..56281d25fd99 100644 --- a/MdePkg/Library/UefiLib/UefiLib.c +++ b/MdePkg/Library/UefiLib/UefiLib.c @@ -640,6 +640,35 @@ EfiTestChildHandle ( return Status; } +/** + * This function checks the supported languages list for a target language + * + * @param SupportedLanguages The supported languages + * @param TargetLanguage The target language + * + * @return Returns EFI_SUCCESS if the language is supported, + * EFI_UNSUPPORTED otherwise + */ +EFI_STATUS +EFIAPI +IsLanguageSupported ( + IN CONST CHAR8 *SupportedLanguages, + IN CONST CHAR8 *TargetLanguage + ) +{ + UINTN Index; + while (*SupportedLanguages != 0) { + for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++); + if ((AsciiStrnCmp(SupportedLanguages, TargetLanguage, Index) == 0) && (TargetLanguage[Index] == 0)) { + return EFI_SUCCESS; + } + SupportedLanguages += Index; + for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++); + } + + return EFI_UNSUPPORTED; +} + /** This function looks up a Unicode string in UnicodeStringTable. @@ -800,24 +829,19 @@ LookupUnicodeString2 ( // Make sure Language is in the set of Supported Languages // Found = FALSE; - while (*SupportedLanguages != 0) { - if (Iso639Language) { + if (Iso639Language) { + while (*SupportedLanguages != 0) { if (CompareIso639LanguageCode (Language, SupportedLanguages)) { Found = TRUE; break; } SupportedLanguages += 3; - } else { - for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++); - if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) { - Found = TRUE; - break; - } - SupportedLanguages += Index; - for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++); } + } else { + Found = !IsLanguageSupported(Language, SupportedLanguages); } + // // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED // @@ -1099,24 +1123,17 @@ AddUnicodeString2 ( // Make sure Language is a member of SupportedLanguages // Found = FALSE; - while (*SupportedLanguages != 0) { - if (Iso639Language) { + if (Iso639Language) { + while (*SupportedLanguages != 0) { if (CompareIso639LanguageCode (Language, SupportedLanguages)) { Found = TRUE; break; } SupportedLanguages += 3; - } else { - for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++); - if (AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) { - Found = TRUE; - break; - } - SupportedLanguages += Index; - for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++); } + } else { + Found = !IsLanguageSupported(Language, SupportedLanguages); } - // // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED // -- 2.21.0