Character code conversion method and device and electronic equipment

By building target encoding mapping arrays and performing array addressing, the inefficient conversion problem caused by file encoding differences between different systems in large information technology systems is solved, efficient character encoding conversion is achieved, and the system's processing capability is improved.

CN119047423APending Publication Date: 2024-11-29CHINA CONSTRUCTION BANK +1
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411101703.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-12
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

When large information technology systems deal with file encoding differences between different systems, traditional transcoding methods are inefficient, resulting in high encoding conversion time and CPU usage.

Method used

By obtaining the encoding type and target encoding type of the original file, a target encoding mapping array is constructed, and the array is used for array addressing, determining the encoding value of the characters to be converted, and efficient character encoding conversion is achieved.

Benefits of technology

It improves the efficiency and accuracy of encoding conversion, reduces the amount of calculation, and reduces CPU usage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119047423A_ABST
    Figure CN119047423A_ABST
Patent Text Reader

Abstract

The invention provides a character code conversion method and device and electronic equipment, and relates to the technical field of character coding. The character code conversion method comprises the steps of obtaining an original file, analyzing the original file, determining a first code type of the original file, and determining a second code type of a to-be-generated target file; obtaining a target code mapping array, and determining a target construction strategy of the target code mapping array; based on the target construction strategy, determining a target object in a target coding mapping array corresponding to a first coding value of a character to be transcoded in the original file; by taking the target object as an addressing condition, carrying out array addressing on the target coding mapping array to obtain a second coding value of the character to be converted; and splicing the second coding values of the to-be-transcoded characters according to the sequence of the to-be-transcoded characters in the original file to generate a target file, thereby realizing efficient character coding conversion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of character encoding technology, and in particular to a character encoding conversion method, device and electronic device. Background Art

[0002] Current large-scale information technology systems need to connect to various peripheral online or batch systems. There may be differences in file encoding between different systems. For example, the International Business Machines (IBM) mainframe system uses the Extended Binary Coded Decimal Interchange Code (EBCDIC), and the open platform generally uses the 8-bit standard code conversion format (8-bit Unicode Transformation Format, UTF-8). Some platforms also use the Chinese Internal Code Specification (GBK) to process Chinese. In order to achieve compatibility processing, the system needs to perform a large amount of code conversion processing in the online message processing and batch file processing during operation.

[0003] With the rapid development of information technology, the amount of data processed by the system has increased significantly. In some large systems, the daily data processing volume can reach hundreds of gigabytes (GB) or even terabytes (TB). Using traditional transcoding processing methods, the processing efficiency is low, and the time consumption and CPU occupancy of encoding conversion are high. Summary of the invention

[0004] The present disclosure aims to solve one of the technical problems in the related art at least to some extent.

[0005] The first embodiment of the present disclosure provides a character encoding conversion method, including:

[0006] Acquire an original file and parse the original file to determine a first encoding type of the original file and determine a second encoding type of a target file to be generated;

[0007] Obtaining a target encoding mapping array and determining a target construction strategy of the target encoding mapping array, wherein the target encoding mapping array includes a mapping relationship between the first encoding type and the second encoding type;

[0008] Based on the target construction strategy, determine that the first code value of the to-be-transcoded character in the original file corresponds to a target object in the target code mapping array, where the target object is an array element of the target code mapping array or a subscript of the array element;

[0009] Using the target object as an addressing condition, performing array addressing on the target code mapping array to obtain a second code value of the character to be converted;

[0010] The second encoding values ​​of the characters to be transcoded are concatenated according to the order of the characters to be transcoded in the original file to generate the target file.

[0011] The second aspect of the present disclosure provides a character encoding conversion device, including:

[0012] A type acquisition module, used to acquire an original file and parse the original file to determine a first encoding type of the original file and a second encoding type of a target file to be generated;

[0013] A strategy acquisition module, used to acquire a target code mapping array and determine a target construction strategy of the target code mapping array, wherein the target code mapping array includes a mapping relationship between the first code type and the second code type;

[0014] An object acquisition module, configured to determine, based on the target construction strategy, that the first encoding value of the character to be transcoded in the original file corresponds to a target object in the target encoding mapping array, wherein the target object is an array element of the target encoding mapping array or a subscript of the array element;

[0015] A code search module, used to perform array addressing on the target code mapping array using the target object as an addressing condition to obtain a second code value of the character to be converted;

[0016] The encoding splicing module is used to splice the second encoding values ​​of the characters to be transcoded according to the order of the characters to be transcoded in the original file to generate the target file.

[0017] The third aspect of the present disclosure provides an electronic device, including:

[0018] at least one processor; and

[0019] a memory communicatively connected to at least one processor; wherein,

[0020] The memory stores instructions that can be executed by at least one processor, and the instructions are executed by at least one processor so that the at least one processor can execute the character encoding conversion method provided in the embodiment of the first aspect of the present disclosure.

[0021] The fourth aspect embodiment of the present disclosure proposes a computer-readable storage medium having computer instructions stored thereon, wherein the computer instructions are used to enable a computer to execute the character encoding conversion method provided in the first aspect embodiment of the present disclosure.

[0022] The fifth aspect embodiment of the present disclosure proposes a computer program product, including a computer program, which, when executed by a processor, implements the character encoding conversion method provided in the first aspect embodiment of the present disclosure.

[0023] The present application can perform array addressing on the target encoding mapping array based on the target object as the addressing condition, thereby realizing the mapping query of the character to be converted and determining the encoding value of the character to be converted after conversion. The target object can be an array element or an array element subscript, thereby realizing efficient character conversion and reducing the amount of calculation for character encoding conversion. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 is a flow chart of a character encoding conversion method provided by an embodiment of the present disclosure;

[0025] Figure 2 is a flowchart of obtaining a target encoding mapping array provided by an embodiment of the present disclosure;

[0026] Figure 3 is a flowchart of another character encoding conversion method provided by an embodiment of the present disclosure;

[0027] Figure 4 is a flowchart of another character encoding conversion method provided by an embodiment of the present disclosure;

[0028] Figure 5 It is a structural block diagram of a character encoding conversion device provided by an embodiment of the present disclosure;

[0029] Figure 6 It is a structural schematic diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION

[0030] Embodiments of the present disclosure are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present disclosure, and should not be construed as limiting the present disclosure.

[0031] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0032] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this application are all authorized by the user or fully authorized by all parties, and the acquisition, storage, use, processing, etc. of data in the technical solution of this application comply with the relevant provisions of laws and regulations.

[0033] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be considered as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0034] The character encoding conversion method, device and electronic device of the embodiments of the present disclosure are described below in conjunction with the accompanying drawings.

[0035] Figure 1 is a flowchart of a character encoding conversion method provided by an embodiment of the present disclosure, such as Figure 1 As shown, the method comprises the following steps:

[0036] S101, obtaining an original file and parsing the original file to determine a first encoding type of the original file and a second encoding type of a target file to be generated.

[0037] In some implementations, the original file is a text file to be processed, and the first encoding type of the text in the original file is obtained by parsing the original file. The first encoding type may be one of GBK, UTF-8 or EBCDIC encoding.

[0038] Optionally, parsing the original file may be to identify a file header flag, and determine the first encoding type of the original file through the file header flag, for example, a UTF-8 encoded file usually starts with EE BB BF.

[0039] In some implementations, the target file is generated by transcoding the original file. The second encoding type in the target file is the target encoding type that needs to be transcoded. The target encoding type can be one of the preset GBK, UTF-8 or EBCDIC encodings, and the first encoding type and the second encoding type are different.

[0040] S102, obtaining a target code mapping array, and determining a target construction strategy of the target code mapping array.

[0041] In some implementations, the target encoding mapping array includes a mapping relationship between a first encoding type and a second encoding type; in this embodiment, the first encoding type and the second encoding type that have a mapping relationship can belong to the same character, that is, for the same character, there is a mapping relationship between its corresponding first encoding type and second encoding type, so that the target encoding mapping array is constructed according to the mapping relationship between the first encoding type and the second encoding type of all characters.

[0042] In some implementations, the target construction strategy may depend on the setting of the index subscript, for example, the target construction strategy includes two strategies: the first encoding type is a subscript, or the second encoding type is a subscript.

[0043] S103, based on the target construction strategy, determining that the first code value of the to-be-transcoded character in the original file corresponds to a target object in the target code mapping array, where the target object is an array element of the target code mapping array, or a subscript of an array element.

[0044] In some implementations, if the target construction strategy is that the first encoding type is a subscript, the target object is an array element of the target encoding mapping array, and the first encoding value of the character to be transcoded in the original file is the subscript of the array element in the target encoding mapping array; in this embodiment, the first encoding value is the encoding value under the first encoding type.

[0045] In some implementations, if the target construction strategy is that the second encoding type is a subscript, the target object is the subscript of the array element of the target encoding mapping array, and the first encoding value of the character to be transcoded in the original file is the array element in the target encoding mapping array.

[0046] S104, using the target object as an addressing condition, performing array addressing on the target code mapping array to obtain a second code value of the character to be converted.

[0047] The addressing conditions mainly involve the method of determining the storage location of data or instructions. It can be understood that the target object is an array element of the target code mapping array, or the subscript of the array element. Therefore, the target object is used as the addressing condition, and the target code mapping array is array addressed. The second code value of the character to be converted may be the subscript of the array element, or the array element; the second code value in this embodiment is the code value under the second code type.

[0048] In some implementations, if the target object is an array element of the target code mapping array, the target code mapping array is array addressed using the target object as the addressing condition, and the second code value of the character to be converted is the subscript of the array element of the target code mapping array.

[0049] In some implementations, if the target object is the subscript of an array element of the target code mapping array, the target code mapping array is array addressed using the target object as the addressing condition, and the second code value of the character to be converted is the array element of the target code mapping array.

[0050] S105, concatenating the second encoding values ​​of the characters to be transcoded according to the order of the characters to be transcoded in the original file to generate a target file.

[0051] It can be understood that after obtaining the second encoding value of each character to be transcoded in the original file, the second encoding values ​​corresponding to each character to be transcoded are spliced ​​according to the order of the characters to be transcoded in the original file to generate a target file, that is, a target file of the second encoding type.

[0052] In this embodiment, the first encoding type of the original file and the second encoding type of the target file to be generated are obtained, and the target encoding mapping array is determined according to the mapping relationship between the first encoding type and the second encoding type, and the target object is determined according to the target construction strategy of the target encoding mapping array, so as to realize the forward mapping and reverse mapping between the first encoding type and the second encoding type, and the target object is used as the addressing condition to perform array addressing on the target encoding mapping array, so as to determine the second encoding value of the character to be converted according to the mapping relationship, and the target file after the characters are converted is obtained by sequentially splicing, so as to improve the efficiency and accuracy of the encoding conversion when actually performing the encoding conversion of the characters, and reduce the calculation amount of the encoding conversion.

[0053] Based on the above embodiment, the process of obtaining the target encoding mapping array is described. Figure 2 is a flowchart of obtaining a target encoding mapping array provided by an embodiment of the present disclosure, such as Figure 2 As shown, the method comprises the following steps:

[0054] S201, obtaining multiple candidate code mapping arrays, and determining candidate code type pairs associated with the candidate code mapping arrays.

[0055] In some implementations, the candidate encoding mapping array is a pre-built mapping array between different encoding types. For example, the candidate encoding mapping array may include: a mapping array between GBK encoding and UTF-8 encoding, a mapping array between GBK encoding and EBCDIC encoding, and a mapping array between UTF-8 and EBCDIC encoding.

[0056] Optionally, a full set of characters can be obtained, and each candidate character in the full set of characters can be traversed to obtain a code value pair of the candidate characters, the code value pair including code values ​​of two encoding types; in this embodiment, the full set of characters refers to characters within the standard code Unicode range that need to be processed in daily Chinese environments, totaling 27,619 characters, including 97 English letters, numbers and symbols, Unicode encoding: 0x0020-0x007F; a total of 20,902 basic Chinese characters, Unicode encoding: 0x4E00-0x9FA5; a total of 38 basic Chinese characters, Unicode encoding: 0x9FA6-0x9FCB; a total of 6,582 characters in extended area A, Unicode encoding: 0x3400-0x4DB5; each candidate character in the full set of characters can be traversed to obtain code values ​​of two different encoding types corresponding to the candidate characters, and the traditional encoding conversion method can be used to transcode the full set of characters to obtain code values ​​of two different encoding types corresponding to the candidate characters, thereby forming a code value pair for the candidate characters to ensure the accuracy of the corresponding code value pairs.

[0057] Furthermore, for each candidate character, one type of code value in the code value pair of the candidate character is used as an array element, and the other type of code value in the code value pair is used as the subscript of the array element, and a mapping relationship between the two coding types of the candidate character is generated to obtain a candidate code mapping array; that is, the two types of code values ​​in the code value pair are respectively numerical elements and subscripts of numerical elements, and the array elements and the subscripts of the array elements are a set of mapping relationships, so that the candidate code mapping array is obtained according to the mapping relationship between the two coding types of all candidate characters.

[0058] In some implementations, incremental characters and / or deleted characters of the full set of characters can also be obtained; for example, additions and / or deletions are made based on the full set of characters according to actual needs, and the incremental characters and / or deleted characters that need to be added or deleted are determined, so that based on the code value pairs of the incremental characters and / or deleted characters, the mapping relationship of the code value pairs of the incremental characters and / or deleted characters in the candidate code mapping array is added, deleted, and updated, thereby realizing flexible updating of the candidate code mapping array.

[0059] Further, the candidate encoding type pair associated with each candidate encoding mapping array is determined; optionally, the array identifier of the candidate encoding mapping array can be extracted from the description information of the candidate encoding mapping array; the array identifier is parsed to extract the encoding type associated with the candidate encoding mapping array, and the candidate encoding type pair is obtained. Optionally, the description information is the relevant information of the candidate encoding mapping array, such as the candidate encoding type information corresponding to the candidate encoding mapping array, and the array identifier is extracted from the description information. The array identifier can be used to reflect the corresponding encoding type, such as the array identifier is GBK, UTF-8 or EBCDIC, etc. The encoding type associated with the candidate encoding mapping array can be obtained by parsing the array identifier, thereby obtaining the candidate encoding type pair; for example, the array identifier of the candidate encoding mapping array is GBK and UTF-8, and the candidate encoding type pair of the candidate encoding mapping array obtained by parsing the array identifier is GBK type and UTF-8 type.

[0060] S202: Match a target encoding type pair including a first encoding type and a second encoding type from candidate encoding type pairs.

[0061] It can be understood that the two encoding types corresponding to the matched target encoding type pair are respectively the first encoding type and the second encoding type.

[0062] S203: Determine the candidate coding mapping array corresponding to the target coding type as the target coding mapping array.

[0063] In this embodiment, code values ​​of different encoding types of the full characters are obtained, and a plurality of candidate code mapping arrays are determined according to the code values ​​of the full characters. The candidate code mapping arrays are used as the basis for character code conversion, and forward or reflected character code mapping is implemented through the candidate code mapping array to reduce the amount of calculation. Further, candidate code type pairs of each candidate code mapping array are determined according to the description information of the candidate code mapping array, so as to match a target code type pair including a first code type and a second code type in the candidate code types, and the candidate code mapping array corresponding to the target code type pair is determined as the target code mapping array, and the characters to be transcoded are encoded based on the target code mapping array to improve the efficiency and accuracy of character code conversion.

[0064] Based on the above embodiments, Figure 3 A flowchart of another character encoding conversion method provided by an embodiment of the present disclosure, such as Figure 3 As shown, the method comprises the following steps:

[0065] S301, obtaining an original file and parsing the original file to determine a first encoding type of the original file and a second encoding type of a target file to be generated.

[0066] In the embodiments of the present disclosure, the implementation method of step S301 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.

[0067] S302, obtaining multiple candidate code mapping arrays, and determining candidate code type pairs associated with the candidate code mapping arrays.

[0068] In the embodiments of the present disclosure, the implementation method of step S302 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.

[0069] S303: Match a target encoding type pair including a first encoding type and a second encoding type from the candidate encoding type pairs.

[0070] In the embodiments of the present disclosure, the implementation method of step S303 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.

[0071] S304: Determine the candidate coding mapping array corresponding to the target coding type as the target coding mapping array.

[0072] In the embodiments of the present disclosure, the implementation method of step S304 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.

[0073] S305, determine the target construction strategy of the target code mapping array, and based on the target construction strategy, determine the target object in the target code mapping array corresponding to the first code value of the character to be transcoded in the original file, where the target object is an array element of the target code mapping array, or a subscript of an array element.

[0074] Optionally, the target construction strategy may include a first construction strategy and a second construction strategy. The first construction strategy indicates that the array elements of the target encoding mapping array are of the second encoding type, and the subscripts of the array elements are of the first encoding type; the second construction strategy indicates that the array elements of the target encoding mapping array are of the first encoding type, and the subscripts of the array elements are of the second encoding type.

[0075] In response to the target construction strategy being the first construction strategy, a target object corresponding to the first encoding value of the character to be transcoded is determined as a subscript of an array element.

[0076] In response to the target construction strategy being the second construction strategy, it is determined that the target object corresponding to the first encoding value of the character to be transcoded is an array element.

[0077] In the embodiments of the present disclosure, the implementation method of step S305 can be implemented by any of the methods in the embodiments of the present disclosure, which is not limited here and will not be described in detail.

[0078] S306, using the target object as an addressing condition, performing array addressing on the target code mapping array to obtain a second code value of the character to be converted.

[0079] When the target construction strategy is the first construction strategy, that is, when the target object is the subscript of an array element, the first encoding value of the character to be transcoded is used as the subscript of the array element to be queried; based on the subscript of the array element to be queried, the subscript of the array element in the target encoding mapping array is queried to obtain the array element indicated by the subscript of the array element to be queried as the data element to be queried; it is determined that the data element to be queried is the second encoding value of the character to be transcoded; that is, when the target object is the subscript of an array element, the first encoding value of the character to be transcoded is determined to be the subscript of the array element to be queried, the subscript of the array element is queried in the target encoding mapping array, and it is determined that the array element indicated by the subscript of the array element to be queried is the second encoding value of the character to be transcoded.

[0080] Optionally, when the target construction strategy is the second construction strategy, that is, when the target object is an array element, the first code value of the character to be transcoded is the array element to be queried; based on the array element to be queried, the array element in the target code mapping array is queried to obtain the subscript associated with the array element to be queried; the subscript associated with the array element to be queried is determined to be the second code value of the character to be transcoded. That is, when the target object is an array element, the first code value to be transcoded is determined to be the array element to be queried, the array element to be queried is queried in the target code mapping array, the subscript associated with the array element to be queried is obtained, and the subscript associated with the array element to be queried is determined to be the second code value of the character to be transcoded.

[0081] See also Figure 4 , Figure 4 A flowchart of another character encoding conversion method provided in an embodiment of the present invention initializes and constructs multiple candidate encoding mapping arrays. After determining the original file to be converted, the characters to be converted in the original file are read, and the characters to be converted are mapped and transcoded based on the determined target encoding mapping array to obtain a second encoding value corresponding to the characters to be converted, until all the characters to be converted in the original file are processed.

[0082] In some implementations, the data volume of the original file can also be obtained, and the method for obtaining the second code value of the character to be transcoded can be determined based on the data volume; in response to the data volume being greater than or equal to the set data volume, the target code mapping array is obtained, and array addressing is performed on the character to be transcoded to obtain the second code value of the character to be transcoded; that is, when the data volume of the original file is large, the target code mapping array is obtained, and the target object is determined to perform array addressing on the target code mapping array, so as to obtain the second code value of each character to be transcoded, thereby improving encoding efficiency.

[0083] In some implementations, in response to the data volume of the original file being greater than or equal to the set data volume, the original file is segmented to obtain multiple file blocks; multiple query threads are started, and the file blocks are distributed to the multiple query threads, and the query threads perform array addressing on the characters to be transcoded in the file blocks. That is, when the data volume of the original file is large, the original file is segmented to obtain multiple file blocks, and multiple query threads are started to synchronously perform array addressing on the characters to be transcoded in the file blocks, so as to obtain the second encoding value of the characters to be transcoded in the file blocks, and the encoding efficiency is improved through synchronous query processing by multiple query threads.

[0084] In some implementations, in response to the data volume being less than the set data volume, the first code value of the character to be transcoded is converted to obtain the standard character code value corresponding to the character to be transcoded; the standard character code value of the character to be transcoded is converted to obtain the second code value of the character to be transcoded. That is, when the data volume of the original file is small, the character to be transcoded can be converted by a traditional encoding method. For example, the character to be transcoded is "Chinese character", the first code value of the character to be transcoded is GBK code, and the second code value is EBCDIC code; the first code value of the character to be transcoded is determined to be: 0xbaba, 0xd7d6; the first code value of the character to be transcoded is converted to the standard character code value, the standard character code value is UNICODE code value, and the standard character code value of the character to be transcoded is: 0x6c49, 0x5b57; further, the EBCDIC code conversion table can be queried using UNICODE code, the conversion table index value is obtained by taking the high bit of UNICODE, and the second code value is obtained according to the index value and the low bit of UNICODE, that is, the EBCDIC code value is: 0x4db9, 0x5c76.

[0085] In some implementations, the UNICODE to EBCDIC encoding transcoding algorithm can be expressed as:

[0086] index = transcoding table [unicode[0]];

[0087] ebcdic encoding = transcoding table [index*512+unicode[1]*2]*0x100+transcoding table [index*512+unicode[1]*2+1];

[0088] Among them, index = transcoding table [unicode [0]] can be understood as obtaining the index value in the transcoding table based on unicode [0]; transcoding table [index * 512 + unicode [1] * 2] uses the found index and the second character unicode [1] of the Unicode code to calculate the position in the transcoding table. 512 is the block size of the transcoding table, and unicode [1] * 2 is because each Unicode character may correspond to two EBCDIC bytes; 0x100 is a hexadecimal number used to calculate the high-order part of the EBCDIC code; transcoding table [index * 512 + unicode [1] * 2 + 1] is used to obtain the low-order part of the EBCDIC code.

[0089] It can be understood that when the second code value is obtained based on array addressing, there is no need to convert the first code value into a standard character code value; for example, for the character "Han", its GBK code is 0xbaba. When encoding the character "Han", there is no need to first convert the first code value into the standard character UNICODE and obtain the calculation process of the second code value by indexing the EBCDIC code conversion table. The array element value corresponding to the target code mapping array array[0xbaba] can be directly queried based on the array addressing process in this embodiment to obtain the second code value 0x4db9.

[0090] In the embodiments of the present disclosure, the implementation method of step S306 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.

[0091] S307, concatenating the second encoding values ​​of the characters to be transcoded according to the order of the characters to be transcoded in the original file to generate a target file.

[0092] In the embodiments of the present disclosure, the implementation method of step S307 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.

[0093] In this embodiment, the encoding values ​​of different encoding types of the full characters are obtained, and multiple candidate encoding mapping arrays are determined according to the encoding values ​​of the full characters. The candidate encoding mapping arrays are used as the basis for character encoding conversion, and the target encoding mapping array and its target construction strategy are obtained. The target object is determined based on different target construction strategies, so that array addressing is performed on the target encoding mapping array based on the target object as an addressing condition. When the target construction strategy is the first construction strategy or the second construction strategy, the second encoding value can be determined, thereby reducing the computational cost during encoding conversion; whether to perform array addressing can also be selected according to the data volume of the original file, and the original file can be divided into multiple file blocks, which can be processed synchronously by multiple query threads to improve the encoding processing efficiency. When the data volume of the original file is small, encoding calculation can be performed based on the traditional encoding algorithm to ensure the encoding accuracy of the original file while improving the encoding efficiency.

[0094] Figure 5 A structural block diagram of a character encoding conversion device provided by an embodiment of the present disclosure, such as Figure 5 As shown, the character encoding conversion device 500 of the embodiment of the present disclosure includes:

[0095] The type acquisition module 501 is used to acquire and parse the original file, determine the first encoding type of the original file, and determine the second encoding type of the target file to be generated;

[0096] A strategy acquisition module 502 is used to acquire a target code mapping array and determine a target construction strategy of the target code mapping array, wherein the target code mapping array includes a mapping relationship between a first code type and a second code type;

[0097] The object acquisition module 503 is used to determine, based on the target construction strategy, the target object in the target code mapping array corresponding to the first code value of the character to be transcoded in the original file, where the target object is an array element of the target code mapping array or a subscript of an array element;

[0098] The code search module 504 is used to perform array addressing on the target code mapping array using the target object as an addressing condition to obtain a second code value of the character to be converted;

[0099] The code splicing module 505 is used to splice the second code values ​​of the characters to be transcoded according to the order of the characters to be transcoded in the original file to generate a target file.

[0100] In some implementations, the policy acquisition module 502 includes:

[0101] Obtain multiple candidate encoding mapping arrays, and determine candidate encoding type pairs associated with the candidate encoding mapping arrays;

[0102] Matching a target encoding type pair including a first encoding type and a second encoding type from among candidate encoding type pairs;

[0103] The candidate encoding mapping array corresponding to the target encoding type is determined as the target encoding mapping array.

[0104] In some implementations, the policy acquisition module 502 includes:

[0105] Extracting an array identifier of the candidate encoding mapping array from the description information of the candidate encoding mapping array;

[0106] The array identifier is parsed, the encoding type associated with the candidate encoding mapping array is extracted, and the candidate encoding type pair is obtained.

[0107] In some implementations, the object acquisition module 503 includes:

[0108] In response to the target construction strategy being the first construction strategy, determining that the target object corresponding to the first encoding value of the character to be transcoded is the subscript of the array element; wherein the first construction strategy indicates that the array element of the target encoding mapping array is the second encoding type, and the subscript of the array element is the first encoding type;

[0109] In response to the target construction strategy being the second construction strategy, the target object corresponding to the first encoding value of the character to be transcoded is determined to be an array element; wherein the second construction strategy indicates that the array element of the target encoding mapping array is the first encoding type, and the subscript of the array element is the second encoding type.

[0110] In some implementations, the encoding splicing module 504 includes:

[0111] The first encoding value of the character to be transcoded is used as the subscript of the array element to be queried;

[0112] Based on the subscript of the array element to be queried, the subscript of the array element in the target code mapping array is queried to obtain the array element indicated by the subscript of the array element to be queried as the data element to be queried;

[0113] Determine that the data element to be queried is a second encoding value of the character to be transcoded.

[0114] In some implementations, the code lookup module 504 includes:

[0115] The first encoding value of the character to be transcoded is used as the array element to be queried;

[0116] Query the array elements in the target encoding mapping array based on the array elements to be queried, and obtain the subscript associated with the array elements to be queried;

[0117] It is determined that the subscript associated with the array element to be queried is the second encoding value of the character to be transcoded.

[0118] In some implementations, the policy acquisition module 502 includes:

[0119] Get all characters, traverse each candidate character in the all characters, and obtain a code value pair of the candidate character, where the code value pair includes code values ​​of two encoding types;

[0120] For each candidate character, one type of code value in the code value pair of the candidate character is used as an array element, and the other type of code value in the code value pair is used as the subscript of the array element to generate a mapping relationship between the two code types of the candidate character to obtain a candidate code mapping array.

[0121] In some implementations, the apparatus 500 further includes:

[0122] Get the incremental characters and / or deleted characters of the full amount of characters;

[0123] Based on the code value pairs of the incremental characters and / or deleted characters, the mapping relationship of the code value pairs of the incremental characters and / or deleted characters in the candidate code mapping array is added, deleted or updated.

[0124] In some implementations, the apparatus 500 further includes:

[0125] The data volume of the original file is determined, and in response to the data volume being greater than or equal to the set data volume, a target encoding mapping array is obtained, and array addressing is performed on the character to be transcoded to obtain a second encoding value of the character to be transcoded.

[0126] In some implementations, the apparatus 500 further includes:

[0127] In response to the data amount of the original file being greater than or equal to the set data amount, splitting the original file to obtain a plurality of file blocks;

[0128] Multiple query threads are started, and file blocks are distributed to the multiple query threads. The query threads perform array addressing on the characters to be transcoded in the file blocks.

[0129] In this embodiment, the first encoding type of the original file and the second encoding type of the target file to be generated are obtained, and the target encoding mapping array is determined according to the mapping relationship between the first encoding type and the second encoding type, and the target object is determined according to the target construction strategy of the target encoding mapping array, so as to realize the forward mapping and reverse mapping between the first encoding type and the second encoding type, and the target object is used as the addressing condition to perform array addressing on the target encoding mapping array, so as to determine the second encoding value of the character to be converted according to the mapping relationship, and the target file after the characters are converted is obtained by sequentially splicing, so as to improve the efficiency and accuracy of the encoding conversion when actually performing the encoding conversion of the characters, and reduce the calculation amount of the encoding conversion.

[0130] Figure 6 FIG. 1 is a block diagram of an electronic device according to an exemplary embodiment. Figure 6 As shown, the electronic device 600 includes:

[0131] The memory 610 and the processor 620, a bus 630 connecting different components (including the memory 610 and the processor 620), the memory 610 stores a computer program, and when the processor 620 executes the program, the character encoding conversion method described in the embodiment of the present disclosure is implemented.

[0132] Bus 630 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.

[0133] The electronic device 600 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by the electronic device 600, including volatile and non-volatile media, removable and non-removable media.

[0134] The memory 610 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 640 and / or cache memory 650. The electronic device 600 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 660 may be used to read and write non-removable, non-volatile magnetic media ( Figure 6 not shown, usually called a "hard drive"). Although Figure 6 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical medium) may be provided. In these cases, each drive may be connected to bus 630 via one or more data medium interfaces. Memory 610 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present disclosure.

[0135] A program / utility 660 having a set (at least one) of program modules 670 may be stored, for example, in the memory 610, such program modules 670 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 670 generally perform the functions and / or methods of the embodiments described in the present disclosure.

[0136] The electronic device 600 may also communicate with one or more external devices 690 (e.g., keyboard, pointing device, display 691, etc.), one or more devices that enable a user to interact with the electronic device 600, and / or any device that enables the electronic device 600 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 692. Furthermore, the electronic device 600 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) through a network adapter 693. Figure 6 As shown, the network adapter 693 communicates with other modules of the electronic device 600 via the bus 630. It should be understood that although Figure 6 Not shown, other hardware and / or software modules may be used in conjunction with electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0137] The processor 620 executes various functional applications and data processing by running the programs stored in the memory 610 .

[0138] It should be noted that the implementation process and technical principles of the electronic device of this embodiment refer to the aforementioned explanation of the character encoding conversion method of the embodiment of the present disclosure, and will not be repeated here.

[0139] In order to implement the above embodiments, the present disclosure also proposes a computer-readable storage medium.

[0140] When the instructions in the computer-readable storage medium are executed by the processor of the service server, the service server can perform the character encoding conversion method as described above. Optionally, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0141] In order to implement the above embodiments, the present disclosure further provides a computer program product, including a computer program, characterized in that when the computer program is executed by a processor, the character encoding conversion method as described above is implemented.

[0142] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims. It should be understood that the present disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A character encoding conversion method, characterized in that: The method comprises: Acquire an original file and parse the original file to determine a first encoding type of the original file and a second encoding type of a target file to be generated; Obtaining a target encoding mapping array and determining a target construction strategy for the target encoding mapping array, wherein the target encoding mapping array includes a mapping relationship between the first encoding type and the second encoding type; Based on the target construction strategy, determining that the first code value of the to-be-transcoded character in the original file corresponds to a target object in the target code mapping array, where the target object is an array element of the target code mapping array or a subscript of the array element; Using the target object as an addressing condition, performing array addressing on the target code mapping array to obtain a second code value of the character to be converted; The second encoding values ​​of the characters to be transcoded are concatenated according to the order of the characters to be transcoded in the original file to generate the target file.

2. The method according to claim 1, characterized in that The obtaining target encoding mapping array includes: Obtain multiple candidate encoding mapping arrays, and determine candidate encoding type pairs associated with the candidate encoding mapping arrays; Matching a target encoding type pair including the first encoding type and the second encoding type from the candidate encoding type pairs; The candidate code mapping array corresponding to the target code type is determined as the target code mapping array.

3. The method according to claim 2, characterized in that The determining of the candidate encoding type pairs associated with the candidate encoding mapping array includes: Extracting the array identifier of the candidate code mapping array from the description information of the candidate code mapping array; The array identifier is parsed, and the encoding type associated with the candidate encoding mapping array is extracted to obtain the candidate encoding type pair.

4. The method according to claim 1, wherein The determining, based on the target construction strategy, that the first encoding value of the to-be-transcoded character in the original file corresponds to the target object in the target encoding mapping array includes: In response to the target construction strategy being the first construction strategy, determining that the target object corresponding to the first encoding value of the character to be transcoded is the subscript of the array element; wherein the first construction strategy indicates that the array element of the target encoding mapping array is the second encoding type, and the subscript of the array element is the first encoding type; In response to the target construction strategy being the second construction strategy, the target object corresponding to the first encoding value of the character to be transcoded is determined to be the array element; wherein, the second construction strategy indicates that the array element of the target encoding mapping array is the first encoding type, and the subscript of the array element is the second encoding type.

5. The method according to claim 4, characterized in that When the target construction strategy is the first construction strategy, array addressing is performed on the target code mapping array using the target object as an addressing condition to obtain the second code value of the character to be converted, including: The first encoding value of the character to be transcoded is used as the subscript of the array element to be queried; Based on the subscript of the array element to be queried, query the subscript of the array element in the target code mapping array to obtain the array element indicated by the subscript of the array element to be queried as the data element to be queried; Determine that the data element to be queried is the second encoding value of the character to be transcoded.

6. The method according to claim 4, characterized in that When the target construction strategy is the second construction strategy, array addressing is performed on the target code mapping array using the target object as an addressing condition to obtain the second code value of the character to be converted, including: The first encoding value of the character to be transcoded is used as the array element to be queried; Querying array elements in the target code mapping array based on the array element to be queried to obtain a subscript associated with the array element to be queried; Determine that the subscript associated with the array element to be queried is the second encoding value of the character to be transcoded.

7. The method according to claim 2, characterized in that The pre-construction process of the candidate encoding mapping array includes: Obtaining a full set of characters, traversing each candidate character in the full set of characters, and obtaining a code value pair for the candidate character, wherein the code value pair includes code values ​​of two encoding types; For each candidate character, one type of code value in the code value pair of the candidate character is used as an array element, and the other type of code value in the code value pair is used as the subscript of the array element to generate a mapping relationship between the two code types of the candidate character to obtain the candidate code mapping array.

8. The method according to claim 7, characterized in that The method further comprises: Obtaining incremental characters and / or deleted characters of the full amount of characters; Based on the code value pairs of the incremental characters and / or deleted characters, the mapping relationships of the code value pairs of the incremental characters and / or deleted characters in the candidate code mapping array are added, deleted, and updated.

9. The method according to any one of claims 1 to 8, characterized in that The method further comprises: The data amount of the original file is determined, and in response to the data amount being greater than or equal to the set data amount, the target encoding mapping array is obtained, and the array addressing is performed on the character to be transcoded to obtain a second encoding value of the character to be transcoded.

10. The method according to any one of claims 1 to 8, characterized in that The method further comprises: In response to the data amount of the original file being greater than or equal to the set data amount, dividing the original file into a plurality of file blocks; A plurality of query threads are started, and the file blocks are distributed to the plurality of query threads, and the query threads perform the array addressing on the characters to be transcoded in the file blocks.

11. A character encoding conversion device, characterized in that: include: a type acquisition module, configured to acquire an original file and parse the original file to determine a first encoding type of the original file and a second encoding type of a target file to be generated; a strategy acquisition module, configured to acquire a target code mapping array and determine a target construction strategy for the target code mapping array, wherein the target code mapping array includes a mapping relationship between the first code type and the second code type; an object acquisition module, configured to determine, based on the target construction strategy, that the first code value of the to-be-transcoded character in the original file corresponds to a target object in the target code mapping array, where the target object is an array element of the target code mapping array or a subscript of the array element; A code search module is used to perform array addressing on the target code mapping array using the target object as an addressing condition to obtain a second code value of the character to be converted; The encoding splicing module is used to splice the second encoding values ​​of the characters to be transcoded according to the order of the characters to be transcoded in the original file to generate the target file.

12. An electronic device, characterized in that: include: a processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 10 when executed by a processor.

14. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 10 when being executed by a processor.

Citation Information

Cited By

  • Embedded device word stock dynamic replacement system and method based on Unicode and GB2312 coding mapping

    CN121030050A

  • Semiconductor machine output data processing method and processing device

    CN121031547A

  • Semiconductor machine output data processing method and processing device

    CN121031547B