A string calling method, electronic equipment and device
By pre-creating string packages containing strings of different encoding forms, and using the target token and string block type values to distinguish and call strings of different encoding forms, the problem of the impact of encoding method conversion in user interface programs affects efficiency, and more efficient user interface program execution is achieved.
Patent Information
- Application Number
- CN202411908471.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-04
AI Technical Summary
When creating a user interface, due to the different encoding methods used by the basic framework and the graphics library, frequent encoding conversion will have a great impact on the execution efficiency of the user interface program.
By pre-creating a string package containing the first and second encoded form strings, the target token and string block type values distinguish and call strings of different encoded forms to avoid encoding conversion when displaying the user interface.
It improves the execution efficiency of user interface programs, reduces memory overhead and allocation and release of temporary buffers, and avoids the problem of memory fragmentation.
Smart Images

Figure CN119760186A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software technology, and in particular to a string calling method, electronic equipment and device. Background Art
[0002] When creating a user interface, you can use the basic framework for managing user interfaces. The basic framework mainly provides interfaces for users to install, uninstall, and use various resources such as strings, fonts, and images. In addition, you can also use the graphics library to help developers quickly and easily create beautiful and feature-rich graphical user interfaces.
[0003] There are often strings in the user interface, and the strings need to be displayed when the user interface is displayed. However, the basic framework and graphics library on which the user interface is based may use different encoding methods. In the process of implementing a user interface (such as the BIOS (Basic Input Output System) Setup interface) based on the graphics library and the basic framework, every time a user interface needs to be displayed, it is necessary to obtain the strings of the user interface from the database of the basic framework and convert the encoding method to correctly display and process these strings. However, frequent encoding method conversion will have a significant impact on the execution efficiency of the user interface program. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a string calling method, electronic device and device to improve the execution efficiency of the user interface program. The specific technical solution is as follows:
[0005] In a first aspect, an embodiment of the present application provides a string calling method, the method comprising:
[0006] Obtain a string package, wherein the string package includes string information, wherein each string block included in the string information records a string, a first target flag token corresponding to the recorded string, and a string block type value of the string block, wherein the string includes a first string in a first encoding form defined in a user interface, and a second string converted from the first string to a second encoding form, wherein the second encoding form is an encoding form supported by an element in the user interface, wherein the first target token corresponding to the first string and the second string converted from the first string are the same, wherein the string block type value in the string block recording the first string is a first type value indicating the first encoding form, and the string block type value in the string block recording the second string is a second type value indicating the second encoding form;
[0007] Get the second target token of the target string to be called;
[0008] When calling the target string in the first encoding form, obtaining a first string block matching the first type value and the second target token from the string package, and calling the string contained in the first string block;
[0009] When calling the target string in the second encoding form, a second string block matching the second type value and the second target token is obtained from the string package, and the string included in the second string block is called.
[0010] In one embodiment of the present application, the string package is generated in the following manner:
[0011] In the process of compiling a program of the user interface, converting a first character string in the first encoding form defined in the user interface into a second character string in the second encoding form;
[0012] The first character string and the second character string are respectively written into different character string blocks in the character string information in the character string package to generate a character string package.
[0013] In one embodiment of the present application, the step of writing the first string and the second string into different string blocks in the string information in the string package to generate the string package includes:
[0014] For each language, the first string and the second string of the language are respectively written into different string blocks in the string information in the string package corresponding to the language to generate a string package corresponding to the language, wherein the first target token corresponding to the first encoded form of the string and the second encoded form of the string representing the same meaning in different languages is the same.
[0015] In one embodiment of the present application, the step of obtaining a first string block matching the first type value and the second target token from the string package includes:
[0016] Using a first string acquisition function defined in the EFI_HII_STRING_PROTOCOL string protocol of the unified extensible firmware interface UEFI human-machine interface infrastructure HII, acquiring a first string block matching the first type value and the second target token from the string packet;
[0017] The obtaining, from the string package, a second string block matching the second type value and the second target token includes:
[0018] A second string acquisition function for calling a string in a second encoding form is used to acquire a second string block matching the second type value and the second target token from the string package.
[0019] In one embodiment of the present application, when the user interface is created based on UEFI HII and lightweight universal graphics library LVGL, the first encoding form is UCS-2 encoding form, and the second encoding form is UTF-8 encoding form.
[0020] In a second aspect, an embodiment of the present application provides an electronic device, the electronic device comprising:
[0021] processor;
[0022] Transceiver;
[0023] A machine-readable storage medium storing machine-executable instructions that can be executed by the processor, the machine-executable instructions causing the processor to perform the following steps:
[0024] Obtain a string package, wherein the string package includes string information, wherein each string block included in the string information records a string, a first target flag token corresponding to the recorded string, and a string block type value of the string block, wherein the string includes a first string in a first encoding form defined in a user interface, and a second string converted from the first string to a second encoding form, wherein the second encoding form is an encoding form supported by an element in the user interface, wherein the first target token corresponding to the first string and the second string converted from the first string are the same, wherein the string block type value in the string block recording the first string is a first type value indicating the first encoding form, and the string block type value in the string block recording the second string is a second type value indicating the second encoding form;
[0025] Get the second target token of the target string to be called;
[0026] When calling the target string in the first encoding form, obtaining a first string block matching the first type value and the second target token from the string package, and calling the string contained in the first string block;
[0027] When calling the target string in the second encoding form, a second string block matching the second type value and the second target token is obtained from the string package, and the string included in the second string block is called.
[0028] In one embodiment of the present application, the machine executable instructions cause the processor to generate a string packet in the following manner:
[0029] In the process of compiling a program of the user interface, converting a first character string in the first encoding form defined in the user interface into a second character string in the second encoding form;
[0030] The first character string and the second character string are respectively written into different character string blocks in the character string information in the character string package to generate a character string package.
[0031] In one embodiment of the present application, the step of writing the first string and the second string into different string blocks in the string information in the string package to generate the string package specifically includes:
[0032] For each language, the first string and the second string of the language are respectively written into different string blocks in the string information in the string package corresponding to the language to generate a string package corresponding to the language, wherein the first target token corresponding to the first encoded form of the string and the second encoded form of the string representing the same meaning in different languages is the same.
[0033] In one embodiment of the present application, obtaining a first string block matching the first type value and the second target token from the string package specifically includes:
[0034] Using a first string acquisition function defined in the EFI_HII_STRING_PROTOCOL string protocol of the unified extensible firmware interface UEFI human-machine interface infrastructure HII, acquiring a first string block matching the first type value and the second target token from the string packet;
[0035] The acquiring, from the string package, a second string block matching the second type value and the second target token specifically includes:
[0036] A second string acquisition function for calling a string in a second encoding form is used to acquire a second string block matching the second type value and the second target token from the string package.
[0037] In one embodiment of the present application, when the user interface is created based on UEFI HII and lightweight universal graphics library LVGL, the first encoding form is UCS-2 encoding form, and the second encoding form is UTF-8 encoding form.
[0038] In a third aspect, an embodiment of the present application provides a string calling device, the device comprising:
[0039] a string package acquisition module, used to acquire a string package, wherein the string package includes string information, each string block included in the string information records a string, a first target flag token corresponding to the recorded string, and a string block type value of the string block, the string includes a first string in a first encoding form defined in a user interface, and a second string converted from the first string to a second encoding form, the second encoding form is an encoding form supported by an element in the user interface, the first target token corresponding to the first string and the second string converted from the first string are the same, the string block type value in the string block recording the first string is a first type value representing the first encoding form, and the string block type value in the string block recording the second string is a second type value representing the second encoding form;
[0040] A target token acquisition module, used to acquire a second target token of a target string to be called;
[0041] A first string calling module is used for obtaining a first string block matching the first type value and the second target token from the string package when calling a target string in a first encoding form, and calling the string included in the first string block;
[0042] The second string calling module is used to obtain a second string block matching the second type value and the second target token from the string package when calling the target string in the second encoding form, and call the string included in the second string block.
[0043] In one embodiment of the present application, the string package is generated by the following modules:
[0044] A coding form conversion module, used for converting a first character string of the first coding form defined in the user interface into a second character string of the second coding form during the process of compiling a program of the user interface;
[0045] The string package generating module is used to write the first string and the second string into different string blocks in the string information in the string package respectively to generate a string package.
[0046] In one embodiment of the present application, the string packet generation module is specifically used to:
[0047] For each language, the first string and the second string of the language are respectively written into different string blocks in the string information in the string package corresponding to the language to generate a string package corresponding to the language, wherein the first target token corresponding to the first encoded form of the string and the second encoded form of the string representing the same meaning in different languages is the same.
[0048] In one embodiment of the present application, the first string calling module is specifically used to, when calling the target string in the first encoding form, use the first string acquisition function defined in the EFI_HII_STRING_PROTOCOL of the UEFI HII, to acquire the first string block matching the first type value and the second target token from the string package, and call the string contained in the first string block;
[0049] The second string calling module is specifically used to, when calling a target string in a second encoding form, adopt a second string acquisition function for calling a string in a second encoding form, obtain a second string block matching the second type value and the second target token from the string package, and call the string contained in the second string block.
[0050] In one embodiment of the present application, when the user interface is created based on UEFI HII and lightweight universal graphics library LVGL, the first encoding form is UCS-2 encoding form, and the second encoding form is UTF-8 encoding form.
[0051] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any method step described in the first aspect is implemented.
[0052] In a fifth aspect, an embodiment of the present application further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the method steps described in the first aspect above.
[0053] Beneficial effects of the embodiments of the present application:
[0054] The string calling method provided in the embodiment of the present application has a string package that stores a first string in a first encoding form and a second string in a second encoding form in advance. And the first target Token corresponding to a first string and a second string obtained after the encoding form of the first string is converted is the same, but the corresponding string block type values are different. Therefore, in the process of calling the string, the target string in two encoding forms can be found through the second target token of the target string, and the two different encoding forms can be distinguished by the string block type value, so that the target string in different encoding forms can be called according to actual needs. Since the encoding form conversion of the string has been completed in advance, therefore, in the subsequent process of calling the string, the string in different encoding forms can be arbitrarily called according to actual needs, without the need to convert the string encoding form when displaying the user interface, thereby improving the execution efficiency of the user interface program. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0056] Figure 1 A schematic diagram of components of a user interface provided in an embodiment of the present application;
[0057] Figure 2 A flowchart of a string calling method provided in an embodiment of the present application;
[0058] Figure 3 A schematic diagram of a string of information provided in an embodiment of the present application;
[0059] Figure 4 A schematic diagram of a flow chart of a first string packet generation method provided in an embodiment of the present application;
[0060] Figure 5 A schematic diagram of a flow chart of a second method for generating a string package provided in an embodiment of the present application;
[0061] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;
[0062] Figure 7 A schematic diagram of the structure of a string calling device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0063] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.
[0064] Since there is a problem in the related art that frequent encoding conversion will have a significant impact on the execution efficiency of the user interface program, in order to solve the above problem, an embodiment of the present application provides a string calling method, electronic device and device.
[0065] See also Figure 1 , which is a component diagram of a user interface provided in an embodiment of the present application.
[0066] As can be seen from the figure, the definition of the user interface can include fonts, images, tables, and strings. The table includes questions, verification expressions, and storage.
[0067] The character string is the part that needs to be converted into encoding format during display and processing.
[0068] In addition, a specific application scenario of an embodiment of the present application is introduced here.
[0069] The present application can be applied to the BIOS Setup interface. BIOS is a set of programs that are fixed to a ROM (Read-Only Memory) chip on the motherboard of a computer. It stores the most important basic input and output programs of the computer, the self-test program after powering on, and the system self-starting program. It can read and write specific information of system settings from CMOS (Complementary Metal Oxide Semiconductor). Its main function is to provide the lowest-level and most direct hardware settings and control for the computer.
[0070] The BIOS Setup interface is a user interface provided by the firmware program embedded on the computer motherboard, which is used to manage and configure the computer's hardware settings. Usually, you enter the BIOS Setup interface by pressing a specific key combination when the computer starts up, such as the Delete key, F2 key, etc. Its appearance can be a text-based menu structure or a modern graphical interface that presents various setting options in the form of graphics or text.
[0071] The BIOS Setup interface can be created based on LVGL (Light and Versatile Graphics Library) and UEFI (Unified Extensible Firmware Interface) HII (Human Interface Infrastructure).
[0072] LVGL is a new GUI (Graphical User Interface) system framework with the advantages of small code size and easy user interface development. It is an open source embedded graphics library. LVGL is lightweight, feature-rich, flexible, and portable, which can help developers quickly and easily create beautiful and feature-rich graphical user interfaces.
[0073] UEFI HII defines a basic framework for managing user interfaces. The HII database mainly provides interfaces for users to install, uninstall, and use various resources such as strings, fonts, and images.
[0074] The strings in UEFI HII are described in the UNI file, and all characters are stored in the UCS-2 (Universal Character Set codedin 2 octets) encoding format for use by HII. The UCS-2 encoding format is a Unicode (unicode) character encoding method with a fixed length of 2 bytes. However, the encoding method used by LVGL is UTF-8 (Unicode Transformation Format-8). This encoding method can support international character sets, including characters in multiple languages including Chinese. UTF-8 uses 1 to 4 bytes to encode each character.
[0075] Specifically, in UTF-8, a US-ASCII character (Unicode ranges from U+0000 to U+007F) only needs 1 byte encoding. Latin, Greek, Cyrillic, Armenian, Hebrew, Arabic, Syriac, and other letters with diacritical marks require 2 bytes (Unicode ranges from U+0080 to U+07FF). Characters in other languages (including Chinese, Japanese, Korean, Southeast Asian, and Middle Eastern characters) include most commonly used characters and use 3 bytes. Characters in other rarely used languages use 4 bytes.
[0076] In the related art, based on the characteristics of the UCS-2 encoding mode and the UTF-8 encoding mode, an encoding mode conversion function is implemented to convert Unicode characters in the UCS-2 encoding mode into UTF-8 characters in the UTF-8 encoding mode.
[0077] See Table 1, which is a character encoding conversion comparison table in the related art.
[0078] Table 1
[0079] Table 1 means that if the value range of Unicode is 00000000 – 0000007F, the last seven digits of the binary number are filled into the "xxxxxxx" in "0xxxxxxx" after converting Unicode into binary to obtain the UTF-8 character. Then the binary number obtained after filling is converted into hexadecimal.
[0080] If the value range of the Unicode character is 00000080 – 000007FF, after converting the Unicode to binary, fill the 6th to 10th binary digits into the "xxxxx" in "110xxxxx", and fill the 0th to 5th binary digits into the "xxxxxx" in 10xxxxxx. If the binary number does not have enough digits, fill the high digits with 0. Then convert the binary number obtained after filling into hexadecimal.
[0081] If the value range of the Unicode character is 00000800 – 0000FFFF, after converting the Unicode to binary, fill the 12th to 15th binary digits into the "xxxx" position in "1110xxxx", fill the 6th to 11th binary digits into the "xxxxxx" position in "10xxxxxx", and fill the 0th to 5th binary digits into the "xxxxxx" position in "10xxxxxx". If the binary number does not have enough digits, add 0 to the high digits. Then convert the binary number obtained after filling into hexadecimal.
[0082] If the range of Unicode characters is 00010000 – 001FFFFF, after converting Unicode to binary, fill the 16th - 18th binary digits into "xxx" in "11110xxx", fill the 12th - 15th binary digits into "xxxx" in "1110xxxx", fill the 6th - 11th binary digits into "xxxxxx" in "10xxxxxx", and fill the 0th - 5th binary digits into "xxxxxx" in "10xxxxxx". If the number of binary digits is insufficient, fill 0s at the high positions. Then convert the filled binary number to hexadecimal.
[0083] For example, taking the Chinese character "妍" as an example, the encoding of "妍" in Unicode is U+598D, and the binary conversion is 101100110001101. The value of this Unicode is in the range of 00000800 – 0000FFFF, and the corresponding UTF-8 format is 1110xxxx 10xxxxxx 10xxxxxx. Fill the binary data of the character "妍" into the x positions in this format from the back to the front, and fill 0s if the number of digits is insufficient. The final UTF-8 character of the character "妍" is 11100101 1010011010001101, which is converted to hexadecimal as: E5A68D.
[0084] As can be seen from the above background content, LVGL uses the UTF-8 encoding method, and UEFI uses the UCS-2 encoding method. In the implementation process of the BIOS Setup based on LVGL, after obtaining the strings from the UEFI HII database, the encoding method needs to be converted to correctly display and process these strings in LVGL, which will cause the problem of significantly affecting the execution efficiency of the user interface program as described above.
[0085] It should be noted that the application scenario described here is only one application scenario of the embodiments of the present application. The present application is not limited to this application scenario. Even when the user interface is not the BIOS Setup interface, or when the user interface is not created based on LVGL and UEFI HII, if there is a conversion of the encoding form of the strings in the user interface, the solution provided by the embodiments of the present application can be adopted.
[0086] See Figure 2 , which is a schematic flowchart of a method for calling strings provided by the embodiments of the present application, including the following steps S201 - step S204.
[0087] S201: Obtain a string package.
[0088] The string package contains string information, and each string block contained in the string information records a string, a first target token (flag) corresponding to the recorded string, and a string block type value of the string block.
[0089] The above-mentioned character string includes a first character string in a first encoding form defined in the user interface, and a second character string obtained by converting the first character string into a second encoding form, the above-mentioned second encoding form is an encoding form supported by the elements in the above-mentioned user interface, the first character string and the second character string converted from the first character string correspond to the same first target token, the string block type value in the string block recording the first character string is a first type value representing the first encoding form, and the string block type value in the string block recording the second character string is a second type value representing the second encoding form.
[0090] That is, in the embodiment of the present application, the first target token corresponding to the first character string and the second character string obtained after the encoding form conversion is the same, and are respectively recorded in different character string blocks in the character string information in the same character string package.
[0091] In addition to the string information, the string package also includes a fixed header and font information. The fixed header can be used to limit the language of the string recorded in the string package, and the font information is used to limit the font of the string recorded in the string package.
[0092] When the user interface is created based on UEFI HII and LVGL, the first encoding format is the UCS-2 encoding format, and the second encoding format is the UTF-8 encoding format.
[0093] In this case, the UEFI Specification defines the fixed header as:
[0094] typedef struct _EFI_HII_STRING_PACKAGE_HDR {
[0095] EFI_HII_PACKAGE_HEADER Header;
[0096] UINT32 HdrSize;
[0097] UINT32 StringInfoOffset;
[0098] CHAR16 LanguageWindow
[16] ;
[0099] EFI_STRING_ID LanguageName;
[0100] CHAR8 Language[ … ];
[0101] } EFI_HII_STRING_PACKAGE_HDR;
[0102] The Language[ … ] indicates the language of the string recorded in the string packet. For the definitions of other fields, please refer to the UEFI Specification and will not be described here.
[0103] In addition, the definition of string information is:
[0104] typedef struct {
[0105] UINT8 BlockType;
[0106] UINT8 BlockBody[];
[0107] } EFI_HII_STRING_BLOCK;
[0108] The string information is encoded as a series of string blocks. Each string block contains a byte header, which stores the first target token (i.e., Block Type above) for identifying the string. The string blocks are processed in order. The first target token of the first string and the second string obtained by converting the encoding form of the first string are the same. Different first strings have different first target tokens. Different first strings have different first target tokens.
[0109] The definition of string block type values in UEFI HII can be found in Table 2 below.
[0110] See Table 2, which is a string block type value table provided in an embodiment of the present application.
[0111] Table 2
[0112] As can be seen from the above table, the string block type value corresponding to a single UCS-2 string using the default font information is 0x14. In the case where the user interface is created based on UEFI HII, the above string block type value is 0x14. In addition, as can be seen from the above table, the current definition of the string block type value does not include the definition of strings in encoding methods other than UCS-2 encoding methods. For this reason, the value of the string block type value can be expanded in this application.
[0113] See Table 3, which is an extended string block type value table provided in an embodiment of the present application.
[0114] Table 3
[0115] It should be noted that the value of 0x18 for the string block type value corresponding to the UTF-8 encoding method is only a possible implementation example. The implementation example of the present application does not limit the specific value, as long as it is different from the values in the aforementioned Table 2, or is equal to the value used for future expansion.
[0116] See also Figure 3 , which is a schematic diagram of a string information provided in an embodiment of the present application.
[0117] As can be seen from the figure, the string information includes n string blocks, namely string block 1 to string block n. Each string block includes the first target token of the string block.
[0118] In one embodiment of the present application, the compilation tool may first convert the string defined in the UNI file into a Unicode string and store it in the AutoGen.c file, and specifically may store it in an array.
[0119] After that, the string defined in the UNI file is converted into a UTF-8 string and put into the array in the AutoGen.c file. Specifically, it is stored in the string information in the string package.
[0120] In addition, the embodiment of the present application provides an interface for obtaining a string. The defined first target token can be defined as a macro and stored in the xxxStrDefs.h file in the same directory as the AutoGen.c file. The required string can then be found based on the defined first target token.
[0121] It should be noted that this application does not limit the names of the aforementioned .c and .h files.
[0122] S202: Obtain a second target token of the target string to be called.
[0123] S203: When calling the target string in the first encoding form, obtain a first string block matching the first type value and the second target token from the string package, and call the string included in the first string block.
[0124] S204: When calling the target string in the second encoding form, obtain a second string block matching the second type value and the second target token from the string package, and call the string included in the second string block.
[0125] In the case where the user interface is created based on UEFI HII and LVGL, the first string block can be obtained through step A, and the second string block can be obtained through step B.
[0126] Step A: adopting the first string acquisition function defined in EFI_HII_STRING_PROTOCOL (Extensible Firmware Interface Human Machine Interface Infrastructure Setting String Protocol) of UEFI HII, acquiring the first string block matching the first type value and the second target token from the string package.
[0127] The first string acquisition function is the GetString function, which is a function defined in the UEFI HII and can be called directly.
[0128] Step B: using a second string acquisition function for calling a string in a second encoding form, to acquire a second string block matching the second type value and the second target token from the string package.
[0129] UEFI HII does not define a function for dispatching UTF-8 strings, so in the embodiment of the present application, a new function GetStringUtf8 can be defined in EFI_HII_STRING_PROTOCOL for dispatching UTF-8 strings.
[0130] Specifically, the first string block that matches the first type value and the second target token is a string block whose type value is the first type value and whose first target token is the second target token.
[0131] The second string block that matches the second type value and the second target token is a string block whose type value is the second type value and whose first target token is the second target token.
[0132] As can be seen from the above, in the embodiment of the present application, there is a string package that stores a first string in a first encoding form and a second string in a second encoding form. And the first target Token corresponding to a first string and a second string obtained after the encoding form of the first string is converted is the same, but the corresponding string block type values are different. Therefore, in the process of calling the string, the target string in two encoding forms can be found through the second target token of the target string, and the two different encoding forms can be distinguished by the string block type value, so that the target string in different encoding forms can be called according to actual needs. Since the encoding form conversion of the string has been completed in advance, therefore, in the subsequent process of calling the string, the string in different encoding forms can be arbitrarily called according to actual needs, without the need to convert the string encoding form when displaying the user interface, thereby improving the execution efficiency of the user interface program.
[0133] In addition, the conversion of string encoding methods involves the allocation and release of temporary buffers. If the related technology is used to frequently convert string encoding methods, memory overhead will increase and memory fragmentation will occur. However, the solution provided by the embodiment of the present application does not require frequent conversion of string encoding methods, so the above problems will not occur.
[0134] See also Figure 4 , which is a flow chart of the first string packet generation method provided in an embodiment of the present application, including the following steps S401-S402.
[0135] S401: in the process of compiling a program of a user interface, converting a first character string in the first encoding form defined in the user interface into a second character string in the second encoding form.
[0136] S402: writing the first character string and the second character string into different character string blocks in the character string information in the character string package respectively to generate a character string package.
[0137] As can be seen from the above, in the embodiment of the present application, the encoding form conversion of the string is completed in the process of compiling the user interface program, and a string package is generated, so that the first string and the second string can be directly called from the string package during the subsequent operation of the user interface.
[0138] In a possible scenario, in order to serve users who use different languages, a character string with the same meaning may be displayed in multiple languages in the user interface, so there are multiple character strings with the same meaning but in different languages.
[0139] For example, there is an English string "Select Language" and a French string "Choisir la Langue", both of which mean "select language". The method of encoding such strings can be seen below. Figure 5 The embodiment shown.
[0140] See also Figure 5 , is a flow chart of a second method for generating a string packet provided in an embodiment of the present application, which is similar to the aforementioned Figure 4 Compared with the embodiment shown, the above step S402 can be implemented by the following step S402A.
[0141] S402A: For each language, write the first character string and the second character string of the language into different character string blocks in the character string information in the character string package corresponding to the language, so as to generate a character string package corresponding to the language.
[0142] The first target tokens corresponding to the character string in the first encoding form and the character string in the second encoding form that represent the same meaning in different languages are the same.
[0143] That is, in the embodiment of the present application, the first target tokens corresponding to character strings in different languages and different encoding forms representing the same meaning are the same.
[0144] For example, in the above example, the tokens corresponding to the English string "SelectLanguage" in the first encoding form and the second encoding form and the French string "Choisir la Langue" in the first encoding form and the second encoding form are the same, such as STR_LANGUAGE_SELECT.
[0145] In addition, as described above, different string packages correspond to different languages, and the fixed header of each string package records the identifier of the language corresponding to the string package.
[0146] As can be seen from the above, the solution provided in the embodiment of the present application can also generate different string packages based on language, so that the solution can be adapted to user interfaces containing strings in different languages.
[0147] After a string package of each language is generated, the string can be called through the following steps C-D.
[0148] Step C: when calling the target string in the first encoding form of the target language, obtain a first string block matching the first type value and the second target token from the string package corresponding to the target language, and call the string contained in the first string block.
[0149] Step D: When calling the target string in the second encoding form of the target language, obtain a second string block that matches the second type value and the second target token from the string package corresponding to the target language, and call the string contained in the second string block.
[0150] Specifically, the string package having the target language identifier recorded in the fixed header may be first found, and then the first string block or the second string block may be obtained from the string package. Specifically, the method of obtaining the first string block or the second string block from the determined string package may refer to the above steps S203 to S204, which will not be described in detail here.
[0151] Corresponding to the aforementioned string calling method, an embodiment of the present application further provides an electronic device.
[0152] See also Figure 6 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, the electronic device comprising:
[0153] Processor 601;
[0154] transceiver 604;
[0155] A machine-readable storage medium 602, wherein the machine-readable storage medium 602 stores machine-executable instructions that can be executed by the processor 601, and the machine-executable instructions cause the processor 601 to perform the following steps:
[0156] Obtain a string package, wherein the string package includes string information, wherein each string block included in the string information records a string, a first target flag token corresponding to the recorded string, and a string block type value of the string block, wherein the string includes a first string in a first encoding form defined in a user interface, and a second string converted from the first string to a second encoding form, wherein the second encoding form is an encoding form supported by an element in the user interface, wherein the first target token corresponding to the first string and the second string converted from the first string are the same, wherein the string block type value in the string block recording the first string is a first type value indicating the first encoding form, and the string block type value in the string block recording the second string is a second type value indicating the second encoding form;
[0157] Get the second target token of the target string to be called;
[0158] When calling the target string in the first encoding form, obtaining a first string block matching the first type value and the second target token from the string package, and calling the string contained in the first string block;
[0159] When calling the target string in the second encoding form, a second string block matching the second type value and the second target token is obtained from the string package, and the string included in the second string block is called.
[0160] like Figure 6 As shown, the network device may further include a communication bus 603. The processor 601, the machine-readable storage medium 602, and the transceiver 604 communicate with each other through the communication bus 603. The communication bus 603 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus 603 may be divided into an address bus, a data bus, a control bus, and the like.
[0161] The transceiver 604 may be a wireless communication module. Under the control of the processor 601 , the transceiver 604 exchanges data with other devices.
[0162] The machine-readable storage medium 602 may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk storage. In addition, the machine-readable storage medium 602 may also be at least one storage device located away from the aforementioned processor.
[0163] The processor 601 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0164] As can be seen from the above, in the embodiment of the present application, there is a string package that stores a first string in a first encoding form and a second string in a second encoding form. And the first target Token corresponding to a first string and a second string obtained after the encoding form of the first string is converted is the same, but the corresponding string block type values are different. Therefore, in the process of calling the string, the target string in two encoding forms can be found through the second target token of the target string, and the two different encoding forms can be distinguished by the string block type value, so that the target string in different encoding forms can be called according to actual needs. Since the encoding form conversion of the string has been completed in advance, therefore, in the subsequent process of calling the string, the string in different encoding forms can be arbitrarily called according to actual needs, without the need to convert the string encoding form when displaying the user interface, thereby improving the execution efficiency of the user interface program.
[0165] In one embodiment of the present application, the machine executable instructions cause the processor to generate a string packet in the following manner:
[0166] In the process of compiling a program of the user interface, converting a first character string in the first encoding form defined in the user interface into a second character string in the second encoding form;
[0167] The first character string and the second character string are respectively written into different character string blocks in the character string information in the character string package to generate a character string package.
[0168] As can be seen from the above, in the embodiment of the present application, the encoding form conversion of the string is completed in the process of compiling the user interface program, and a string package is generated, so that the first string and the second string can be directly called from the string package during the subsequent operation of the user interface.
[0169] In one embodiment of the present application, the step of writing the first string and the second string into different string blocks in the string information in the string package to generate the string package specifically includes:
[0170] For each language, the first string and the second string of the language are respectively written into different string blocks in the string information in the string package corresponding to the language to generate a string package corresponding to the language, wherein the first target token corresponding to the first encoded form of the string and the second encoded form of the string representing the same meaning in different languages is the same.
[0171] As can be seen from the above, the solution provided in the embodiment of the present application can also generate different string packages based on language, so that the solution can be adapted to user interfaces containing strings in different languages.
[0172] In one embodiment of the present application, obtaining a first string block matching the first type value and the second target token from the string package specifically includes:
[0173] Using a first string acquisition function defined in the EFI_HII_STRING_PROTOCOL string protocol of the unified extensible firmware interface UEFI human-machine interface infrastructure HII, acquiring a first string block matching the first type value and the second target token from the string packet;
[0174] The acquiring, from the string package, a second string block matching the second type value and the second target token specifically includes:
[0175] A second string acquisition function for calling a string in a second encoding form is used to acquire a second string block matching the second type value and the second target token from the string package.
[0176] In one embodiment of the present application, when the user interface is created based on UEFI HII and lightweight universal graphics library LVGL, the first encoding form is UCS-2 encoding form, and the second encoding form is UTF-8 encoding form.
[0177] Corresponding to the aforementioned string calling method, an embodiment of the present application also provides a string calling device.
[0178] See also Figure 7 , is a structural diagram of a string calling device provided in an embodiment of the present application, the device comprising:
[0179] The string package acquisition module 701 is used to acquire a string package, wherein the string package includes string information, each string block included in the string information records a string, a first target flag token corresponding to the recorded string, and a string block type value of the string block, the string includes a first string in a first encoding form defined in the user interface, and a second string converted from the first string to a second encoding form, the second encoding form is an encoding form supported by an element in the user interface, the first target token corresponding to the first string and the second string converted from the first string are the same, the string block type value in the string block recording the first string is a first type value representing the first encoding form, and the string block type value in the string block recording the second string is a second type value representing the second encoding form;
[0180] A target token acquisition module 702 is used to acquire a second target token of a target string to be called;
[0181] A first string calling module 703 is used for obtaining a first string block matching the first type value and the second target token from the string package when calling the target string in the first encoding form, and calling the string included in the first string block;
[0182] The second string calling module 704 is used to obtain a second string block matching the second type value and the second target token from the string package when calling the target string in the second encoding form, and call the string included in the second string block.
[0183] As can be seen from the above, in the embodiment of the present application, there is a string package that stores a first string in a first encoding form and a second string in a second encoding form. And the first target Token corresponding to a first string and a second string obtained after the encoding form of the first string is converted is the same, but the corresponding string block type values are different. Therefore, in the process of calling the string, the target string in two encoding forms can be found through the second target token of the target string, and the two different encoding forms can be distinguished by the string block type value, so that the target string in different encoding forms can be called according to actual needs. Since the encoding form conversion of the string has been completed in advance, therefore, in the subsequent process of calling the string, the string in different encoding forms can be arbitrarily called according to actual needs, without the need to convert the string encoding form when displaying the user interface, thereby improving the execution efficiency of the user interface program.
[0184] In one embodiment of the present application, the string package is generated by the following modules:
[0185] A coding form conversion module, used for converting a first character string of the first coding form defined in the user interface into a second character string of the second coding form during the process of compiling a program of the user interface;
[0186] The string package generating module is used to write the first string and the second string into different string blocks in the string information in the string package respectively to generate a string package.
[0187] As can be seen from the above, in the embodiment of the present application, the encoding form conversion of the string is completed in the process of compiling the user interface program, and a string package is generated, so that the first string and the second string can be directly called from the string package during the subsequent operation of the user interface.
[0188] In one embodiment of the present application, the string packet generation module is specifically used to:
[0189] For each language, the first string and the second string of the language are respectively written into different string blocks in the string information in the string package corresponding to the language to generate a string package corresponding to the language, wherein the first target token corresponding to the first encoded form of the string and the second encoded form of the string representing the same meaning in different languages is the same.
[0190] As can be seen from the above, the solution provided in the embodiment of the present application can also generate different string packages based on language, so that the solution can be adapted to user interfaces containing strings in different languages.
[0191] In one embodiment of the present application, the first string calling module 703 is specifically used to, when calling the target string in the first encoding form, use the first string acquisition function defined in the EFI_HII_STRING_PROTOCOL of the UEFI HII, to acquire a first string block matching the first type value and the second target token from the string package, and call the string contained in the first string block;
[0192] The second string calling module 704 is specifically used to, when calling a target string in a second encoding form, use a second string acquisition function for calling a string in a second encoding form, obtain a second string block matching the second type value and the second target token from the string package, and call the string contained in the second string block.
[0193] In one embodiment of the present application, when the user interface is created based on UEFI HII and lightweight universal graphics library LVGL, the first encoding form is UCS-2 encoding form, and the second encoding form is UTF-8 encoding form.
[0194] In another embodiment provided by the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned string calling methods are implemented.
[0195] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any string calling method in the above embodiments.
[0196] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.
[0197] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0198] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the electronic device, device, computer-readable storage medium, and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0199] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.
Claims
1. A string calling method, characterized in that: The method comprises: Obtain a string package, the string package including string information, the string information including at least one string block, each string block recording a string, a first target flag token corresponding to the string, and a string block type value, the string including a first string and a second string converted from the first string to a second encoding form, the string block type value in the string block recording the first string is a first type value representing the first encoding form, and the string block type value in the string block recording the second string is a second type value representing the second encoding form; Get the second target token of the target string to be called; When calling the target string in the first encoding form, obtaining a first string block matching the first type value and the second target token from the string package, and calling the string contained in the first string block; When calling the target string in the second encoding form, a second string block matching the second type value and the second target token is obtained from the string package, and the string included in the second string block is called.
2. The method according to claim 1, characterized in that Before obtaining the string package, the method further includes: In the process of compiling the program of the user interface, according to the encoding forms supported by the elements in the user interface, a first character string in the first encoding form defined in the user interface is converted into a second character string in the second encoding form; The first character string and the second character string are respectively written into different character string blocks in the character string information in the character string package to generate at least one character string package.
3. The method according to claim 2, characterized in that The step of writing the first string and the second string into different string blocks in the string information in the string package to generate at least one string package specifically includes: For each language, the first character string and the second character string of the language are respectively written into different character string blocks in the character string information in the character string package corresponding to the language, so as to generate the character string package corresponding to the language; The first target tokens corresponding to the character string in the first encoding form and the character string in the second encoding form that represent the same meaning in different languages are the same.
4. The method according to claim 1, characterized in that: The obtaining, from the string package, a first string block that matches the first type value and the second target token includes: Using a first string acquisition function defined in an extensible firmware interface human-machine interface basic setting string protocol EFI_HII_STRING_PROTOCOL of a unified extensible firmware interface UEFI human-machine interface infrastructure HII, acquiring a first string block matching the first type value and the second target token from the string package; The obtaining, from the string package, a second string block matching the second type value and the second target token includes: A second string acquisition function for calling a string in a second encoding form is used to acquire a second string block matching the second type value and the second target token from the string package.
5. The method according to any one of claims 1 to 4, characterized in that When the user interface is created based on UEFI HII and a lightweight universal graphics library LVGL, the first encoding form is a UCS-2 encoding form, and the second encoding form is a UTF-8 encoding form.
6. An electronic device, characterized in that: The electronic device comprises: processor; Transceiver; A machine-readable storage medium storing machine-executable instructions that can be executed by the processor, the machine-executable instructions causing the processor to perform the following steps: Obtain a string package, wherein the string package includes string information, wherein each string block included in the string information records a string, a first target flag token corresponding to the recorded string, and a string block type value of the string block, wherein the string includes a first string in a first encoding form defined in a user interface, and a second string converted from the first string to a second encoding form, wherein the second encoding form is an encoding form supported by an element in the user interface, wherein the first target token corresponding to the first string and the second string converted from the first string are the same, wherein the string block type value in the string block recording the first string is a first type value indicating the first encoding form, and the string block type value in the string block recording the second string is a second type value indicating the second encoding form; Get the second target token of the target string to be called; When calling the target string in the first encoding form, obtaining a first string block matching the first type value and the second target token from the string package, and calling the string contained in the first string block; When calling the target string in the second encoding form, a second string block matching the second type value and the second target token is obtained from the string package, and the string included in the second string block is called.
7. The electronic device according to claim 6, characterized in that: The machine executable instructions cause the processor to generate a string packet by: In the process of compiling a program of the user interface, converting a first character string in the first encoding form defined in the user interface into a second character string in the second encoding form; The first character string and the second character string are respectively written into different character string blocks in the character string information in the character string package to generate a character string package.
8. The electronic device according to claim 7, characterized in that: The step of writing the first character string and the second character string into different character string blocks in the character string information in the character string package to generate the character string package specifically includes: For each language, the first string and the second string of the language are respectively written into different string blocks in the string information in the string package corresponding to the language to generate a string package corresponding to the language, wherein the first target token corresponding to the first encoded form of the string and the second encoded form of the string representing the same meaning in different languages is the same.
9. The electronic device according to claim 6, characterized in that: The obtaining, from the string package, a first string block matching the first type value and the second target token specifically includes: Using a first string acquisition function defined in the EFI_HII_STRING_PROTOCOL string protocol of the unified extensible firmware interface UEFI human-machine interface infrastructure HII, acquiring a first string block matching the first type value and the second target token from the string packet; The acquiring, from the string package, a second string block matching the second type value and the second target token specifically includes: A second string acquisition function for calling a string in a second encoding form is used to acquire a second string block matching the second type value and the second target token from the string package.
10. The electronic device according to any one of claims 6 to 9, characterized in that: In the case where the user interface is created based on UEFI HII and lightweight universal graphics library LVGL, the first encoding form is UCS-2 encoding form, and the second encoding form is UTF-8 encoding form.
11. A string calling device, characterized in that: The device comprises: a string package acquisition module, used to acquire a string package, wherein the string package includes string information, each string block included in the string information records a string, a first target flag token corresponding to the recorded string, and a string block type value of the string block, the string includes a first string in a first encoding form defined in a user interface, and a second string converted from the first string to a second encoding form, the second encoding form is an encoding form supported by an element in the user interface, the first target token corresponding to the first string and the second string converted from the first string are the same, the string block type value in the string block recording the first string is a first type value representing the first encoding form, and the string block type value in the string block recording the second string is a second type value representing the second encoding form; A target token acquisition module, used to acquire a second target token of a target string to be called; A first string calling module is used for obtaining a first string block matching the first type value and the second target token from the string package when calling a target string in a first encoding form, and calling the string included in the first string block; The second string calling module is used to obtain a second string block matching the second type value and the second target token from the string package when calling the target string in the second encoding form, and call the string included in the second string block.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 5 are implemented.