Retire language conversion APIs from HII library class.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8104 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
rsun3 2009-04-16 08:46:28 +00:00
parent 887c077d91
commit ad5a96ab2d
11 changed files with 823 additions and 340 deletions

View File

@ -480,6 +480,55 @@ InitSetBrowserStrings (
)
;
/**
Convert language code from RFC3066 to ISO639-2.
LanguageRfc3066 contain a single RFC 3066 code such as
"en-US" or "fr-FR".
The LanguageRfc3066 must be a buffer large enough
for ISO_639_2_ENTRY_SIZE characters.
If LanguageRfc3066 is NULL, then ASSERT.
If LanguageIso639 is NULL, then ASSERT.
@param LanguageRfc3066 RFC3066 language code.
@param LanguageIso639 ISO639-2 language code.
@retval EFI_SUCCESS Language code converted.
@retval EFI_NOT_FOUND Language code not found.
**/
EFI_STATUS
EFIAPI
ConvertRfc3066LanguageToIso639Language (
IN CHAR8 *LanguageRfc3066,
OUT CHAR8 *LanguageIso639
)
;
/**
Convert language code from ISO639-2 to RFC3066 and return the converted language.
Caller is responsible for freeing the allocated buffer.
LanguageIso639 contain a single ISO639-2 code such as
"eng" or "fra".
If LanguageIso639 is NULL, then ASSERT.
If LanguageRfc3066 is NULL, then ASSERT.
@param LanguageIso639 ISO639-2 language code.
@return the allocated buffer or NULL, if the language is not found.
**/
CHAR8*
EFIAPI
ConvertIso639LanguageToRfc3066Language (
IN CONST CHAR8 *LanguageIso639
)
;
#include "Utility.h"
#include "ConfigAccess.h"

View File

@ -25,6 +25,150 @@ ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {
{"fra", "fr-FR"},
};
//
// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes
// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
// The last 2 CHAR8 values are the ISO 639-1 code.
//
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] =
"\
aaraa\
abkab\
afraf\
amham\
araar\
asmas\
aymay\
azeaz\
bakba\
belbe\
benbn\
bihbh\
bisbi\
bodbo\
brebr\
bulbg\
catca\
cescs\
corkw\
cosco\
cymcy\
danda\
deude\
dzodz\
ellel\
engen\
epoeo\
estet\
euseu\
faofo\
fasfa\
fijfj\
finfi\
frafr\
fryfy\
gaiga\
gdhgd\
glggl\
grngn\
gujgu\
hauha\
hebhe\
hinhi\
hrvhr\
hunhu\
hyehy\
ikuiu\
ileie\
inaia\
indid\
ipkik\
islis\
itait\
jawjw\
jpnja\
kalkl\
kankn\
kasks\
katka\
kazkk\
khmkm\
kinrw\
kirky\
korko\
kurku\
laolo\
latla\
lavlv\
linln\
litlt\
ltzlb\
malml\
marmr\
mkdmk\
mlgmg\
mltmt\
molmo\
monmn\
mrimi\
msams\
myamy\
nauna\
nepne\
nldnl\
norno\
ocioc\
ormom\
panpa\
polpl\
porpt\
pusps\
quequ\
rohrm\
ronro\
runrn\
rusru\
sagsg\
sansa\
sinsi\
slksk\
slvsl\
smise\
smosm\
snasn\
sndsd\
somso\
sotst\
spaes\
sqisq\
srpsr\
sswss\
sunsu\
swasw\
swesv\
tamta\
tattt\
telte\
tgktg\
tgltl\
thath\
tsnts\
tuktk\
twitw\
uigug\
ukruk\
urdur\
uzbuz\
vievi\
volvo\
wolwo\
xhoxh\
yidyi\
zhaza\
zhozh\
zulzu\
";
CHAR8 *
ConvertIso639ToRfc3066 (
CHAR8 *Iso638Lang
@ -51,6 +195,78 @@ ConvertIso639ToRfc3066 (
return (CHAR8 *) NULL;
}
/**
Convert language code from RFC3066 to ISO639-2.
@param LanguageRfc3066 RFC3066 language code.
@param LanguageIso639 ISO639-2 language code.
@retval EFI_SUCCESS Language code converted.
@retval EFI_NOT_FOUND Language code not found.
**/
EFI_STATUS
EFIAPI
ConvertRfc3066LanguageToIso639Language (
IN CHAR8 *LanguageRfc3066,
OUT CHAR8 *LanguageIso639
)
{
UINTN Index;
if ((LanguageRfc3066[2] != '-') && (LanguageRfc3066[2] != 0)) {
CopyMem (LanguageIso639, LanguageRfc3066, 3);
return EFI_SUCCESS;
}
for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {
if (CompareMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2) == 0) {
CopyMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3);
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Convert language code from ISO639-2 to RFC3066 and return the converted language.
Caller is responsible for freeing the allocated buffer.
LanguageIso639 contain a single ISO639-2 code such as
"eng" or "fra".
If LanguageIso639 is NULL, then ASSERT.
If LanguageRfc3066 is NULL, then ASSERT.
@param LanguageIso639 ISO639-2 language code.
@return the allocated buffer or NULL, if the language is not found.
**/
CHAR8*
EFIAPI
ConvertIso639LanguageToRfc3066Language (
IN CONST CHAR8 *LanguageIso639
)
{
UINTN Index;
CHAR8 *Rfc3066Language;
for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {
if (CompareMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3) == 0) {
Rfc3066Language = AllocateZeroPool (3);
if (Rfc3066Language != NULL) {
Rfc3066Language = CopyMem (Rfc3066Language, &Iso639ToRfc3066ConversionTable[Index + 3], 2);
}
return Rfc3066Language;
}
}
return NULL;
}
/**
Test if all of the characters in a string have corresponding font characters.

View File

@ -30,6 +30,7 @@ Module Name:
#include <Library/UefiLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/HiiLib.h>
#include <Library/BaseMemoryLib.h>
///
@ -37,6 +38,187 @@ Module Name:
///
#define ISO_639_2_ENTRY_SIZE 3
//
// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes
// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
// The last 2 CHAR8 values are the ISO 639-1 code.
//
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] =
"\
aaraa\
abkab\
afraf\
amham\
araar\
asmas\
aymay\
azeaz\
bakba\
belbe\
benbn\
bihbh\
bisbi\
bodbo\
brebr\
bulbg\
catca\
cescs\
corkw\
cosco\
cymcy\
danda\
deude\
dzodz\
ellel\
engen\
epoeo\
estet\
euseu\
faofo\
fasfa\
fijfj\
finfi\
frafr\
fryfy\
gaiga\
gdhgd\
glggl\
grngn\
gujgu\
hauha\
hebhe\
hinhi\
hrvhr\
hunhu\
hyehy\
ikuiu\
ileie\
inaia\
indid\
ipkik\
islis\
itait\
jawjw\
jpnja\
kalkl\
kankn\
kasks\
katka\
kazkk\
khmkm\
kinrw\
kirky\
korko\
kurku\
laolo\
latla\
lavlv\
linln\
litlt\
ltzlb\
malml\
marmr\
mkdmk\
mlgmg\
mltmt\
molmo\
monmn\
mrimi\
msams\
myamy\
nauna\
nepne\
nldnl\
norno\
ocioc\
ormom\
panpa\
polpl\
porpt\
pusps\
quequ\
rohrm\
ronro\
runrn\
rusru\
sagsg\
sansa\
sinsi\
slksk\
slvsl\
smise\
smosm\
snasn\
sndsd\
somso\
sotst\
spaes\
sqisq\
srpsr\
sswss\
sunsu\
swasw\
swesv\
tamta\
tattt\
telte\
tgktg\
tgltl\
thath\
tsnts\
tuktk\
twitw\
uigug\
ukruk\
urdur\
uzbuz\
vievi\
volvo\
wolwo\
xhoxh\
yidyi\
zhaza\
zhozh\
zulzu\
";
/**
Convert language code from ISO639-2 to RFC3066 and return the converted language.
Caller is responsible for freeing the allocated buffer.
LanguageIso639 contain a single ISO639-2 code such as
"eng" or "fra".
If LanguageIso639 is NULL, then ASSERT.
If LanguageRfc3066 is NULL, then ASSERT.
@param LanguageIso639 ISO639-2 language code.
@return the allocated buffer or NULL, if the language is not found.
**/
CHAR8*
EFIAPI
ConvertIso639LanguageToRfc3066Language (
IN CONST CHAR8 *LanguageIso639
)
{
UINTN Index;
CHAR8 *Rfc3066Language;
for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {
if (CompareMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3) == 0) {
Rfc3066Language = AllocateZeroPool (3);
if (Rfc3066Language != NULL) {
Rfc3066Language = CopyMem (Rfc3066Language, &Iso639ToRfc3066ConversionTable[Index + 3], 2);
}
return Rfc3066Language;
}
}
return NULL;
}
/**
Performs a case-insensitive comparison of two Null-terminated Unicode
strings.

View File

@ -53,6 +53,7 @@
UefiLib
MemoryAllocationLib
HiiLib
BaseMemoryLib
[Protocols]
gEfiUnicodeCollation2ProtocolGuid

View File

@ -30,6 +30,7 @@ Module Name:
#include <Library/UefiLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/HiiLib.h>
#include <Library/BaseMemoryLib.h>
///
@ -37,6 +38,183 @@ Module Name:
///
#define ISO_639_2_ENTRY_SIZE 3
//
// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes
// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
// The last 2 CHAR8 values are the ISO 639-1 code.
//
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] =
"\
aaraa\
abkab\
afraf\
amham\
araar\
asmas\
aymay\
azeaz\
bakba\
belbe\
benbn\
bihbh\
bisbi\
bodbo\
brebr\
bulbg\
catca\
cescs\
corkw\
cosco\
cymcy\
danda\
deude\
dzodz\
ellel\
engen\
epoeo\
estet\
euseu\
faofo\
fasfa\
fijfj\
finfi\
frafr\
fryfy\
gaiga\
gdhgd\
glggl\
grngn\
gujgu\
hauha\
hebhe\
hinhi\
hrvhr\
hunhu\
hyehy\
ikuiu\
ileie\
inaia\
indid\
ipkik\
islis\
itait\
jawjw\
jpnja\
kalkl\
kankn\
kasks\
katka\
kazkk\
khmkm\
kinrw\
kirky\
korko\
kurku\
laolo\
latla\
lavlv\
linln\
litlt\
ltzlb\
malml\
marmr\
mkdmk\
mlgmg\
mltmt\
molmo\
monmn\
mrimi\
msams\
myamy\
nauna\
nepne\
nldnl\
norno\
ocioc\
ormom\
panpa\
polpl\
porpt\
pusps\
quequ\
rohrm\
ronro\
runrn\
rusru\
sagsg\
sansa\
sinsi\
slksk\
slvsl\
smise\
smosm\
snasn\
sndsd\
somso\
sotst\
spaes\
sqisq\
srpsr\
sswss\
sunsu\
swasw\
swesv\
tamta\
tattt\
telte\
tgktg\
tgltl\
thath\
tsnts\
tuktk\
twitw\
uigug\
ukruk\
urdur\
uzbuz\
vievi\
volvo\
wolwo\
xhoxh\
yidyi\
zhaza\
zhozh\
zulzu\
";
/**
Convert language code from RFC3066 to ISO639-2.
@param LanguageRfc3066 RFC3066 language code.
@param LanguageIso639 ISO639-2 language code.
@retval EFI_SUCCESS Language code converted.
@retval EFI_NOT_FOUND Language code not found.
**/
EFI_STATUS
EFIAPI
ConvertRfc3066LanguageToIso639Language (
IN CHAR8 *LanguageRfc3066,
OUT CHAR8 *LanguageIso639
)
{
UINTN Index;
if ((LanguageRfc3066[2] != '-') && (LanguageRfc3066[2] != 0)) {
CopyMem (LanguageIso639, LanguageRfc3066, 3);
return EFI_SUCCESS;
}
for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {
if (CompareMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2) == 0) {
CopyMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3);
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Performs a case-insensitive comparison of two Null-terminated Unicode

View File

@ -53,6 +53,7 @@
UefiLib
MemoryAllocationLib
HiiLib
BaseMemoryLib
[Protocols]
gEfiUnicodeCollation2ProtocolGuid

View File

@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "Bds.h"
#include "FrontPage.h"
#include "Language.h"
EFI_GUID mFrontPageGuid = FRONT_PAGE_FORMSET_GUID;

View File

@ -15,6 +15,150 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "Language.h"
#include "FrontPage.h"
//
// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes
// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
// The last 2 CHAR8 values are the ISO 639-1 code.
//
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] =
"\
aaraa\
abkab\
afraf\
amham\
araar\
asmas\
aymay\
azeaz\
bakba\
belbe\
benbn\
bihbh\
bisbi\
bodbo\
brebr\
bulbg\
catca\
cescs\
corkw\
cosco\
cymcy\
danda\
deude\
dzodz\
ellel\
engen\
epoeo\
estet\
euseu\
faofo\
fasfa\
fijfj\
finfi\
frafr\
fryfy\
gaiga\
gdhgd\
glggl\
grngn\
gujgu\
hauha\
hebhe\
hinhi\
hrvhr\
hunhu\
hyehy\
ikuiu\
ileie\
inaia\
indid\
ipkik\
islis\
itait\
jawjw\
jpnja\
kalkl\
kankn\
kasks\
katka\
kazkk\
khmkm\
kinrw\
kirky\
korko\
kurku\
laolo\
latla\
lavlv\
linln\
litlt\
ltzlb\
malml\
marmr\
mkdmk\
mlgmg\
mltmt\
molmo\
monmn\
mrimi\
msams\
myamy\
nauna\
nepne\
nldnl\
norno\
ocioc\
ormom\
panpa\
polpl\
porpt\
pusps\
quequ\
rohrm\
ronro\
runrn\
rusru\
sagsg\
sansa\
sinsi\
slksk\
slvsl\
smise\
smosm\
snasn\
sndsd\
somso\
sotst\
spaes\
sqisq\
srpsr\
sswss\
sunsu\
swasw\
swesv\
tamta\
tattt\
telte\
tgktg\
tgltl\
thath\
tsnts\
tuktk\
twitw\
uigug\
ukruk\
urdur\
uzbuz\
vievi\
volvo\
wolwo\
xhoxh\
yidyi\
zhaza\
zhozh\
zulzu\
";
#define NARROW_GLYPH_NUMBER 8
#define WIDE_GLYPH_NUMBER 75
@ -270,6 +414,40 @@ ExportFonts (
ASSERT (HiiHandle != NULL);
}
/**
Convert language code from RFC3066 to ISO639-2.
@param LanguageRfc3066 RFC3066 language code.
@param LanguageIso639 ISO639-2 language code.
@retval EFI_SUCCESS Language code converted.
@retval EFI_NOT_FOUND Language code not found.
**/
EFI_STATUS
EFIAPI
ConvertRfc3066LanguageToIso639Language (
IN CHAR8 *LanguageRfc3066,
OUT CHAR8 *LanguageIso639
)
{
UINTN Index;
if ((LanguageRfc3066[2] != '-') && (LanguageRfc3066[2] != 0)) {
CopyMem (LanguageIso639, LanguageRfc3066, 3);
return EFI_SUCCESS;
}
for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {
if (CompareMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2) == 0) {
CopyMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3);
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Determine the current language that will be used
based on language related EFI Variables.

View File

@ -17,6 +17,23 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "String.h"
/**
Convert language code from RFC3066 to ISO639-2.
@param LanguageRfc3066 RFC3066 language code.
@param LanguageIso639 ISO639-2 language code.
@retval EFI_SUCCESS Language code converted.
@retval EFI_NOT_FOUND Language code not found.
**/
EFI_STATUS
EFIAPI
ConvertRfc3066LanguageToIso639Language (
IN CHAR8 *LanguageRfc3066,
OUT CHAR8 *LanguageIso639
);
/**
Determine the current language that will be used
based on language related EFI Variables.

View File

@ -268,73 +268,6 @@ HiiGetSupportedLanguages (
)
;
/**
Convert language code from RFC3066 to ISO639-2.
LanguageRfc3066 contain a single RFC 3066 code such as
"en-US" or "fr-FR".
The LanguageRfc3066 must be a buffer large enough
for ISO_639_2_ENTRY_SIZE characters.
If LanguageRfc3066 is NULL, then ASSERT.
If LanguageIso639 is NULL, then ASSERT.
@param LanguageRfc3066 RFC3066 language code.
@param LanguageIso639 ISO639-2 language code.
@retval EFI_SUCCESS Language code converted.
@retval EFI_NOT_FOUND Language code not found.
**/
EFI_STATUS
EFIAPI
ConvertRfc3066LanguageToIso639Language (
IN CHAR8 *LanguageRfc3066,
OUT CHAR8 *LanguageIso639
)
;
/**
Convert language code from ISO639-2 to RFC3066 and return the converted language.
Caller is responsible for freeing the allocated buffer.
LanguageIso639 contain a single ISO639-2 code such as
"eng" or "fra".
If LanguageIso639 is NULL, then ASSERT.
If LanguageRfc3066 is NULL, then ASSERT.
@param LanguageIso639 ISO639-2 language code.
@return the allocated buffer or NULL, if the language is not found.
**/
CHAR8*
EFIAPI
ConvertIso639LanguageToRfc3066Language (
IN CONST CHAR8 *LanguageIso639
)
;
/**
Convert language code list from RFC3066 to ISO639-2, e.g. "en-US;fr-FR" will
be converted to "engfra".
If SupportedLanguages is NULL, then ASSERT.
@param SupportedLanguages The RFC3066 language list.
@return The ISO639-2 language list.
**/
CHAR8 *
EFIAPI
Rfc3066ToIso639 (
CHAR8 *SupportedLanguages
)
;
/**
Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing
information that includes a GUID, an optional Unicode string name, and a device

View File

@ -15,153 +15,6 @@
#include "InternalHiiLib.h"
//
// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes
// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
// The last 2 CHAR8 values are the ISO 639-1 code.
//
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] =
"\
aaraa\
abkab\
afraf\
amham\
araar\
asmas\
aymay\
azeaz\
bakba\
belbe\
benbn\
bihbh\
bisbi\
bodbo\
brebr\
bulbg\
catca\
cescs\
corkw\
cosco\
cymcy\
danda\
deude\
dzodz\
ellel\
engen\
epoeo\
estet\
euseu\
faofo\
fasfa\
fijfj\
finfi\
frafr\
fryfy\
gaiga\
gdhgd\
glggl\
grngn\
gujgu\
hauha\
hebhe\
hinhi\
hrvhr\
hunhu\
hyehy\
ikuiu\
ileie\
inaia\
indid\
ipkik\
islis\
itait\
jawjw\
jpnja\
kalkl\
kankn\
kasks\
katka\
kazkk\
khmkm\
kinrw\
kirky\
korko\
kurku\
laolo\
latla\
lavlv\
linln\
litlt\
ltzlb\
malml\
marmr\
mkdmk\
mlgmg\
mltmt\
molmo\
monmn\
mrimi\
msams\
myamy\
nauna\
nepne\
nldnl\
norno\
ocioc\
ormom\
panpa\
polpl\
porpt\
pusps\
quequ\
rohrm\
ronro\
runrn\
rusru\
sagsg\
sansa\
sinsi\
slksk\
slvsl\
smise\
smosm\
snasn\
sndsd\
somso\
sotst\
spaes\
sqisq\
srpsr\
sswss\
sunsu\
swasw\
swesv\
tamta\
tattt\
telte\
tgktg\
tgltl\
thath\
tsnts\
tuktk\
twitw\
uigug\
ukruk\
urdur\
uzbuz\
vievi\
volvo\
wolwo\
xhoxh\
yidyi\
zhaza\
zhozh\
zulzu\
";
/**
This function create a new string in String Package or updates an existing
string in a String Package. If StringId is 0, then a new string is added to
@ -497,129 +350,3 @@ Error:
return String;
}
/**
Convert language code from RFC3066 to ISO639-2.
@param LanguageRfc3066 RFC3066 language code.
@param LanguageIso639 ISO639-2 language code.
@retval EFI_SUCCESS Language code converted.
@retval EFI_NOT_FOUND Language code not found.
**/
EFI_STATUS
EFIAPI
ConvertRfc3066LanguageToIso639Language (
IN CHAR8 *LanguageRfc3066,
OUT CHAR8 *LanguageIso639
)
{
UINTN Index;
if ((LanguageRfc3066[2] != '-') && (LanguageRfc3066[2] != 0)) {
CopyMem (LanguageIso639, LanguageRfc3066, 3);
return EFI_SUCCESS;
}
for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {
if (CompareMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2) == 0) {
CopyMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3);
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Convert language code from ISO639-2 to RFC3066 and return the converted language.
Caller is responsible for freeing the allocated buffer.
LanguageIso639 contain a single ISO639-2 code such as
"eng" or "fra".
If LanguageIso639 is NULL, then ASSERT.
If LanguageRfc3066 is NULL, then ASSERT.
@param LanguageIso639 ISO639-2 language code.
@return the allocated buffer or NULL, if the language is not found.
**/
CHAR8*
EFIAPI
ConvertIso639LanguageToRfc3066Language (
IN CONST CHAR8 *LanguageIso639
)
{
UINTN Index;
CHAR8 *Rfc3066Language;
for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {
if (CompareMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3) == 0) {
Rfc3066Language = AllocateZeroPool (3);
if (Rfc3066Language != NULL) {
Rfc3066Language = CopyMem (Rfc3066Language, &Iso639ToRfc3066ConversionTable[Index + 3], 2);
}
return Rfc3066Language;
}
}
return NULL;
}
/**
Convert language code list from RFC3066 to ISO639-2, e.g. "en-US;fr-FR" will
be converted to "engfra".
@param SupportedLanguages The RFC3066 language list.
@return The ISO639-2 language list.
**/
CHAR8 *
EFIAPI
Rfc3066ToIso639 (
CHAR8 *SupportedLanguages
)
{
CHAR8 *Languages;
CHAR8 *ReturnValue;
CHAR8 *LangCodes;
CHAR8 *LangRfc3066;
CHAR8 LangIso639[ISO_639_2_ENTRY_SIZE];
UINTN LanguageSize;
EFI_STATUS Status;
LanguageSize = AsciiStrSize (SupportedLanguages);
ReturnValue = AllocateZeroPool (LanguageSize);
if (ReturnValue == NULL) {
return ReturnValue;
}
//
// Allocate working buffer to contain substring in SupportedLanguages;
//
LangRfc3066 = AllocatePool (LanguageSize);
if (LangRfc3066 == NULL) {
FreePool (ReturnValue);
return NULL;
}
Languages = ReturnValue;
LangCodes = SupportedLanguages;
while (*LangCodes != 0) {
HiiLibGetNextLanguage (&LangCodes, LangRfc3066);
Status = ConvertRfc3066LanguageToIso639Language (LangRfc3066, LangIso639);
if (!EFI_ERROR (Status)) {
CopyMem (Languages, LangIso639, 3);
Languages = Languages + 3;
}
}
FreePool (LangRfc3066);
return ReturnValue;
}