public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 1/1] MdePkg: UefiLib: Add a function to check if a language is supported
@ 2019-09-02  9:06 Tom Zhao
  2019-09-04 13:02 ` [edk2-devel] " Liming Gao
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Zhao @ 2019-09-02  9:06 UTC (permalink / raw)
  To: devel; +Cc: Michael D Kinney, Liming Gao

Add a function that checks if a target language is in the supported
languages list. Add some calls to this function where appropriate in
UefiLib.c

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Tom Zhao <tzhao@solarflare.com>
---

Notes:
    v3:
    - Add comment about usage for RFC4646 and ISO-639

 MdePkg/Include/Library/UefiLib.h | 18 ++++++
 MdePkg/Library/UefiLib/UefiLib.c | 61 +++++++++++++-------
 2 files changed, 58 insertions(+), 21 deletions(-)

diff --git a/MdePkg/Include/Library/UefiLib.h
b/MdePkg/Include/Library/UefiLib.h
index 1650f30ddbc6..f72b7b31f2f1 100644
--- a/MdePkg/Include/Library/UefiLib.h
+++ b/MdePkg/Include/Library/UefiLib.h
@@ -461,6 +461,24 @@ EfiTestChildHandle (
   IN CONST EFI_GUID         *ProtocolGuid
   );
 +/**
+ * This function checks the supported languages list for a target language,
+ * This only supports RFC 4646 Languages. To compare ISO 639 languages,
refer
+ * to function CompareIso639LanguageCode()
+ *
+ * @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..a89e327fc6f6 100644
--- a/MdePkg/Library/UefiLib/UefiLib.c
+++ b/MdePkg/Library/UefiLib/UefiLib.c
@@ -640,6 +640,37 @@ EfiTestChildHandle (
   return Status;
 }
 +/**
+ * This function checks the supported languages list for a target language,
+ * This only supports RFC 4646 Languages. To compare ISO 639 languages,
refer
+ * to function CompareIso639LanguageCode()
+ *
+ * @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 +831,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 +1125,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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [PATCH v3 1/1] MdePkg: UefiLib: Add a function to check if a language is supported
  2019-09-02  9:06 [PATCH v3 1/1] MdePkg: UefiLib: Add a function to check if a language is supported Tom Zhao
@ 2019-09-04 13:02 ` Liming Gao
  0 siblings, 0 replies; 2+ messages in thread
From: Liming Gao @ 2019-09-04 13:02 UTC (permalink / raw)
  To: devel@edk2.groups.io, tzhao@solarflare.com; +Cc: Kinney, Michael D

Tom:

Thanks for your update function header with RFC 4646 Languages. Please remove function name 
CompareIso639LanguageCode() in function header. Because this API is UefiLib internal function, 
It is not defined in UefiLib.h. With this update, Reviewed-by: Liming Gao <liming.gao@intel.com>

Thanks
Liming
> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Tom Zhao
> Sent: Monday, September 2, 2019 5:06 PM
> To: devel@edk2.groups.io
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [edk2-devel] [PATCH v3 1/1] MdePkg: UefiLib: Add a function to check if a language is supported
> 
> Add a function that checks if a target language is in the supported
> languages list. Add some calls to this function where appropriate in
> UefiLib.c
> 
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Tom Zhao <tzhao@solarflare.com>
> ---
> 
> Notes:
>     v3:
>     - Add comment about usage for RFC4646 and ISO-639
> 
>  MdePkg/Include/Library/UefiLib.h | 18 ++++++
>  MdePkg/Library/UefiLib/UefiLib.c | 61 +++++++++++++-------
>  2 files changed, 58 insertions(+), 21 deletions(-)
> 
> diff --git a/MdePkg/Include/Library/UefiLib.h
> b/MdePkg/Include/Library/UefiLib.h
> index 1650f30ddbc6..f72b7b31f2f1 100644
> --- a/MdePkg/Include/Library/UefiLib.h
> +++ b/MdePkg/Include/Library/UefiLib.h
> @@ -461,6 +461,24 @@ EfiTestChildHandle (
>    IN CONST EFI_GUID         *ProtocolGuid
>    );
>  +/**
> + * This function checks the supported languages list for a target language,
> + * This only supports RFC 4646 Languages. To compare ISO 639 languages,
> refer
> + * to function CompareIso639LanguageCode()
> + *
> + * @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..a89e327fc6f6 100644
> --- a/MdePkg/Library/UefiLib/UefiLib.c
> +++ b/MdePkg/Library/UefiLib/UefiLib.c
> @@ -640,6 +640,37 @@ EfiTestChildHandle (
>    return Status;
>  }
>  +/**
> + * This function checks the supported languages list for a target language,
> + * This only supports RFC 4646 Languages. To compare ISO 639 languages,
> refer
> + * to function CompareIso639LanguageCode()
> + *
> + * @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 +831,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 +1125,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
> 
> 
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-09-04 13:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-02  9:06 [PATCH v3 1/1] MdePkg: UefiLib: Add a function to check if a language is supported Tom Zhao
2019-09-04 13:02 ` [edk2-devel] " Liming Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox