String decoding method and device, electronic equipment and storage medium

By identifying the high-order Chinese bytes in GBK encoding and skipping the low-order bytes, and combining this with the delimiter position to extract string units, the problem of garbled characters in Chinese string decoding under C language environment is solved, and accurate Chinese decoding is achieved.

CN115952768BActive Publication Date: 2026-05-01SI-TECH INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SI-TECH INFORMATION TECH CO LTD
Filing Date
2022-12-05
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

In a C language compilation environment, GBK encoded Chinese strings are prone to garbled characters when decoding because the strchr function traverses bytes by byte, causing the high and low bytes of Chinese characters to be misinterpreted as English characters, making it impossible to decode correctly.

Method used

By judging the code value of each byte in the string parameter, the high-order Chinese bytes are identified and skipped, the position of the delimiter is identified, string units are extracted according to the preset delimiter position, and decoding is performed based on GBK decoding rules.

Benefits of technology

It accurately identifies the high and low bytes of Chinese characters, avoiding garbled characters and ensuring the correct decoding of Chinese strings.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115952768B_ABST
    Figure CN115952768B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a string decoding method and device, electronic equipment and a storage medium. The method comprises: in the case of receiving a to-be-decoded string parameter, traversing each byte in the to-be-decoded string parameter; when any byte is traversed, reading the code value of the byte, judging whether the byte is a high-position Chinese byte based on the code value of the byte, if it is determined that the byte is a high-position Chinese byte, offsetting the traversal pointer by a first preset offset value; if the byte is not a high-position Chinese byte, judging whether the byte is a byte storing a delimiter, if yes, determining the position of the byte in the to-be-decoded string parameter, and offsetting the traversal pointer by a second preset offset value; in the case of traversing a byte storing a preset end character, the to-be-decoded string parameter traversal ends, and the to-be-decoded string parameter is cut into to-be-decoded character units according to the determined position of the preset delimiter; and decoding each to-be-decoded character unit based on a preset decoding rule.
Need to check novelty before this filing date? Find Prior Art

Description

String decoding methods, devices, electronic equipment and storage media Technical Field

[0001] This application relates to the field of encoding and decoding technology, and in particular to a string decoding method, apparatus, electronic device and storage medium. Background Technology

[0002] During data transmission, the data sender encodes the information into strings and sets delimiters between the strings so that the data receiver can decode the received data and obtain the correct information.

[0003] If the data receiver is in a C language compilation environment, and is splitting and extracting values ​​from Chinese and English strings with GBK character encoding by delimiters, C language generally uses the strchr function to get the position of the delimiter, and then uses the strncpy function to extract the substring.

[0004] In GBK encoding, Chinese characters are typically stored using two bytes, while English characters are typically stored using one byte. However, the strchr function searches byte by byte. If the code value of one byte in a Chinese string matches the code value of an English character, it will output the English character corresponding to the code value of the English character, and will be unable to correctly decode the corresponding Chinese character, resulting in garbled characters. Summary of the Invention

[0005] This application provides a string decoding method, apparatus, electronic device, and storage medium to avoid garbled characters during Chinese byte decoding.

[0006] In a first aspect, embodiments of this application provide a string decoding method, the method comprising:

[0007] Upon receiving a string parameter to be decoded, each byte in the string parameter to be decoded is traversed.

[0008] When traversing to any byte, read the code value of the byte, and determine whether the byte is a high-order Chinese byte based on the code value of the byte. If it is determined that the byte is a high-order Chinese byte, shift the traversal pointer by a first preset offset value.

[0009] If the byte is not a high-order Chinese byte, determine whether the byte is a byte that stores a delimiter. If so, determine the position of the byte in the string parameter to be decoded, and offset the traversal pointer by a second preset offset value.

[0010] When the byte storing the preset end character is reached during the traversal, the traversal of the string parameter to be decoded ends, and the string parameter to be decoded is truncated into a character unit to be decoded according to the position of the determined preset delimiter.

[0011] Each of the character units to be decoded is decoded based on a preset decoding rule.

[0012] Secondly, embodiments of this application provide a string decoding device, the device comprising:

[0013] The traversal module is used to traverse each byte of the string parameter to be decoded when a string parameter to be decoded is received.

[0014] The Chinese character determination module is used to read the code value of any byte when it is traversed, and determine whether the byte is a high-order Chinese byte based on the code value. If the byte is determined to be a high-order Chinese byte, the traversal pointer is offset by a first preset offset value.

[0015] The delimiter determination module is used to determine whether the byte is a byte storing a delimiter if the byte is not a high-order Chinese byte. If so, it determines the position of the byte in the string parameter to be decoded and offsets the traversal pointer by a second preset offset value.

[0016] The byte truncation module is used to truncate the string parameter to be decoded into a character unit to be decoded according to the position of the predetermined preset delimiter when the traversal of the byte storing the preset end character ends.

[0017] The byte decoding module is used to decode each of the character units to be decoded based on preset decoding rules.

[0018] Thirdly, embodiments of this application also provide an electronic device, the electronic device comprising:

[0019] One or more processors;

[0020] Storage device for storing one or more programs.

[0021] When the one or more programs are executed by the one or more processors, the one or more processors implement the string decoding method provided in any embodiment of this application.

[0022] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program thereon, characterized in that, when the program is executed by a processor, it implements the string decoding method provided in any embodiment of this application.

[0023] The technical solution of this application embodiment, upon receiving a string parameter to be decoded, traverses each byte in the string parameter to be decoded; when traversing to any byte, reads the code value of the byte, and determines whether the byte is a high-order Chinese byte based on the code value. If the byte is determined to be a high-order Chinese byte, the traversal pointer is shifted by a first preset offset value; if the byte is not a high-order Chinese byte, determines whether the byte is a byte storing a delimiter. If so, determines the position of the byte in the string parameter to be decoded, and shifts the traversal pointer by a second preset offset value; when traversing to a byte storing a preset end character, the traversal of the string parameter to be decoded ends, and the string parameter to be decoded is truncated into character units to be decoded according to the determined position of the preset delimiter; and each character unit to be decoded is decoded based on a preset decoding rule. Based on this, when traversing any byte in this embodiment, it will first determine whether the byte is a high-order Chinese byte. If so, it will directly shift the traversal pointer by a preset offset and skip the traversal of the next byte. This avoids the situation where low-order Chinese bytes are mistakenly identified as English bytes, thereby making the identification of high and low order Chinese bytes more accurate and avoiding the occurrence of garbled characters in Chinese decoding. Attached Figure Description

[0024] Figure 1 is a flowchart illustrating the string decoding method provided in Embodiment 1 of this application;

[0025] Figure 2 is a schematic diagram of a string decoding device provided in Embodiment 2 of this application;

[0026] Figure 3 is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of this application. Detailed Implementation

[0027] The present application will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the application and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present application, not the entire structure.

[0028] Example 1

[0029] Figure 1 is a schematic flowchart of the string decoding method provided in Embodiment 1 of this application. This embodiment is described from the perspective of a first platform, and the method is applicable to string decoding scenarios. This method can be executed by a string decoding device, which can be implemented in hardware and / or software, and is generally integrated into electronic devices such as computers with data processing capabilities. Specifically, it includes the following steps:

[0030] Step 101: Upon receiving the string parameter to be decoded, iterate through each byte in the string parameter to be decoded.

[0031] It should be noted that the embodiments of this application are applicable to strings encoded using the GBK Chinese encoding rule. In the GBK Chinese encoding rule, a Chinese character field corresponds to two bytes, a high byte and a low byte. The high byte refers to the byte in the higher position among the two bytes that make up the Chinese character field, and the low byte refers to the byte in the lower position among the two bytes that make up the Chinese character field.

[0032] Generally, the range of the high byte is 81–FE (that is, excluding 80 and FF), and a part of the range of the low byte is 40–7E, and the other part is 80–FE. That is to say, the code value of the high byte must be greater than 0x80. Since when decoding a string, traversal starts from the highest byte of the string, for a Chinese character field, its high byte must be traversed first. Therefore, this feature can be used to identify the high Chinese character byte, which will be described in detail later and will not be elaborated here.

[0033] In this step, once the string parameter to be decoded is received, traversal of each byte in the string parameter to be decoded can be started. In a specific example, the string parameter to be decoded can be "Shi Qiao~4403131111111111~Guangzhou~" before encoding, where the delimiter is "~". After encoding, the obtained string can be "CAAFB37E0x0044031311111111110x00B9E3D6DD0x00% / ".

[0034] Step 102: When traversing to any byte, read the code value of the byte, and based on the code value of the byte, determine whether the byte is a high Chinese character byte. If it is determined that the byte is a high Chinese character byte, offset the traversal pointer by a first preset offset value.

[0035] In this step, when determining whether a byte is a high Chinese character byte, the feature pointed out in the foregoing step 101 can be utilized, that is, the code value of a high Chinese character byte must be greater than 0x80. Therefore, 0x80 can be set as the preset threshold, and then the size between the code value of the byte and the preset threshold can be judged to obtain a judgment result. If the judgment result is that the code value of the character is greater than the preset threshold, it is determined that the byte is a high Chinese character byte; if the judgment result is that the code value of the character is less than or equal to the preset threshold, it is determined that the byte is not a high Chinese character byte.

[0036] In a specific example, the string parameter to be decoded is "CAAFB37E0x0044031311111111110x00B9E3D6DD0x00% / ", where two bytes constitute one byte. The first byte to be traversed is "CA". Since "CA" is greater than "0x80", this byte is the high-order Chinese byte. At this point, the traversal pointer can be offset by the first preset offset value.

[0037] It should be noted that the first preset offset value can be "2", meaning an offset of two bytes to skip the traversal of the next byte. In the example above, the next byte to be traversed would be "B3" instead of "AF". This way, "CAAF" can be identified as a high-low byte of a Chinese character, avoiding misidentification of low-level Chinese characters.

[0038] Step 103: If the byte is not a high-order Chinese byte, determine whether the byte is a byte that stores the delimiter. If so, determine the position of the byte in the string parameter to be decoded, and offset the traversal pointer by the second preset offset value.

[0039] If the aforementioned determination indicates that the byte is not a high-order Chinese byte, then it is necessary to determine whether it is a byte storing a delimiter. Specifically, this can be achieved by comparing the code values.

[0040] The delimiter is usually also encoded. In this case, we compare the code value of the byte with the code value of the delimiter. If they are equal, we can determine that the byte is the byte that stores the delimiter. At this time, we need to record the position of the byte in the string parameter to be decoded. This position can be the order of the byte, such as the 9th byte.

[0041] It should be noted that the value of the traversal pointer at this time can be recorded as the position of that byte in the string parameter to be decoded.

[0042] In addition, the traversal pointer is offset in this step in order to continue traversing the next byte. Therefore, the second preset offset value can be "1", which means that the traversal of the next byte can be performed.

[0043] Furthermore, if the byte is not the one storing the preset delimiter, the traversal pointer will be offset by a second preset offset value. Similarly, this offset of the traversal pointer is also for continuing to traverse the next byte, so the second preset offset value can be "1", that is, the traversal of the next byte can proceed.

[0044] Step 104: When the byte storing the preset end character is reached during the traversal, the traversal of the string parameter to be decoded ends, and the string parameter to be decoded is truncated into a character unit to be decoded according to the position of the determined preset delimiter.

[0045] Typically, each string parameter has a preset end character set at the end of its last byte to indicate that the string parameter has ended. When traversing, if the preset end character is encountered, the traversal process of the string parameter to be decoded can be considered to have ended. At this point, the string parameter to be decoded can be truncated according to the position of the preset delimiter recorded above.

[0046] In a specific example, the default delimiter is 0x00. Therefore, the extracted character units to be decoded are: "CAAFB37E", "4403131111111111", and "B9E3D6DD". Among them, "% / " is the default end character.

[0047] It should be noted that in the specific examples above, the main purpose is to skip the traversal of the "7E" byte, so as to avoid it being identified as a separate English byte, and instead identify it as a low-order Chinese byte.

[0048] Step 105: Decode each character unit to be decoded based on the preset decoding rules.

[0049] This step involves identifying the corresponding Chinese character for each character unit to be decoded. For details, please refer to relevant decoding techniques; they will not be elaborated upon here.

[0050] In this embodiment, upon receiving a string parameter to be decoded, each byte in the string parameter is traversed. When any byte is encountered, its code value is read, and based on the code value, it is determined whether the byte is a high-order Chinese byte. If it is determined to be a high-order Chinese byte, the traversal pointer is shifted by a first preset offset value. If the byte is not a high-order Chinese byte, it is determined whether the byte is a byte storing a delimiter. If so, the position of the byte in the string parameter to be decoded is determined, and the traversal pointer is shifted by a second preset offset value. When the byte storing a preset end character is encountered, the traversal of the string parameter to be decoded ends, and the string parameter to be decoded is truncated into character units to be decoded according to the determined position of the preset delimiter. Each character unit to be decoded is then decoded based on a preset decoding rule. Based on this, when traversing any byte in this embodiment, it will first determine whether the byte is a high-order Chinese byte. If so, it will directly shift the traversal pointer by a preset offset and skip the traversal of the next byte. This avoids the situation where low-order Chinese bytes are mistakenly identified as English bytes, thereby making the identification of high and low order Chinese bytes more accurate and avoiding the occurrence of garbled characters in Chinese decoding.

[0051] Example 2

[0052] Figure 2 is a schematic diagram of a string decoding device provided in Embodiment 2 of this application. The string decoding device provided in this embodiment can execute the string decoding method provided in any embodiment of this application, and has the corresponding functional modules and beneficial effects of the execution method. The device can be implemented in software and / or hardware. As shown in Figure 2, the fault location device for BMC abnormal restart specifically includes: a traversal module 201, a Chinese character judgment module 202, a delimiter judgment module 203, a byte truncation module 204, and a byte decoding module 205.

[0053] The traversal module is used to traverse each byte of the string parameter to be decoded when the string parameter to be decoded is received.

[0054] The Chinese character detection module is used to read the code value of any byte when it is traversed, and to determine whether the byte is a high-order Chinese byte based on the code value. If it is determined that the byte is a high-order Chinese byte, the traversal pointer will be offset by the first preset offset value.

[0055] The delimiter determination module is used to determine whether the byte is the byte storing the delimiter if the byte is not a high-order Chinese byte. If it is, the module determines the position of the byte in the string parameter to be decoded and shifts the traversal pointer by a second preset offset value.

[0056] The byte truncation module is used to truncate the string parameter to be decoded into character units according to the position of the predetermined preset delimiter when the byte storing the preset end character is reached during the traversal of the string parameter to be decoded.

[0057] The byte decoding module is used to decode each character unit to be decoded based on preset decoding rules.

[0058] In the technical solution of this application embodiment, when a string parameter to be decoded is received, each byte in the string parameter to be decoded is traversed; when any byte is traversed, the code value of the byte is read, and it is determined whether the byte is a high-order Chinese byte based on the code value. If it is determined that the byte is a high-order Chinese byte, the traversal pointer is offset by a first preset offset value; if the byte is not a high-order Chinese byte, it is determined whether the byte is a byte storing a delimiter. If so, the position of the byte in the string parameter to be decoded is determined, and the traversal pointer is offset by a second preset offset value; when the byte storing a preset end character is traversed, the string parameter to be decoded is traversed, and the string parameter to be decoded is truncated into character units to be decoded according to the determined position of the preset delimiter; each character unit to be decoded is decoded based on a preset decoding rule. Based on this, when traversing any byte in this embodiment, it will first determine whether the byte is a high-order Chinese byte. If so, it will directly shift the traversal pointer by a preset offset and skip the traversal of the next byte. This avoids the situation where low-order Chinese bytes are mistakenly identified as English bytes, thereby making the identification of high and low order Chinese bytes more accurate and avoiding the occurrence of garbled characters in Chinese decoding.

[0059] Furthermore, the Chinese character recognition module includes:

[0060] The threshold comparison unit is used to determine the difference between the byte's code value and a preset threshold, and obtain the judgment result.

[0061] The first judgment unit is used to determine that the byte is a high-order Chinese byte if the judgment result is that the code value of the character is greater than a preset threshold.

[0062] The second judgment unit is used to determine if the code value of a character is less than or equal to a preset threshold, and to determine if the byte is not a high-order Chinese byte.

[0063] Furthermore, the decoding rules are the same as those for GBK encoding, with a preset threshold of 0x80.

[0064] Furthermore, the device also includes:

[0065] The pointer offset module is used to traverse the pointer by a second preset offset value if the byte is not the byte that stores the preset delimiter.

[0066] Example 3

[0067] Figure 3 is a schematic diagram of an electronic device provided in Embodiment 3 of this application. As shown in Figure 3, the electronic device includes a processor 310, a memory 320, an input device 330, and an output device 340. The number of processors 310 in the electronic device can be one or more. Figure 3 shows one processor 310 as an example. The processor 310, memory 320, input device 330, and output device 340 in the electronic device can be connected by a bus or other means. Figure 3 shows a connection via a bus as an example.

[0068] The memory 320, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as the program instructions / modules corresponding to the string decoding method in this embodiment of the invention. The processor 310 executes various functional applications and data processing of the electronic device by running the software programs, instructions, and modules stored in the memory 320, thereby implementing the aforementioned string decoding method.

[0069] Upon receiving a string parameter to be decoded, each byte in the string parameter to be decoded is traversed.

[0070] When traversing to any byte, read the code value of the byte, and determine whether the byte is a high-order Chinese byte based on the code value of the byte. If it is determined that the byte is a high-order Chinese byte, shift the traversal pointer by a first preset offset value.

[0071] If the byte is not a high-order Chinese byte, determine whether the byte is a byte that stores a delimiter. If so, determine the position of the byte in the string parameter to be decoded, and offset the traversal pointer by a second preset offset value.

[0072] When the byte storing the preset end character is reached during the traversal, the traversal of the string parameter to be decoded ends, and the string parameter to be decoded is truncated into a character unit to be decoded according to the position of the determined preset delimiter.

[0073] Each of the character units to be decoded is decoded based on a preset decoding rule.

[0074] Further, determining whether the byte is a high-order Chinese byte based on its code value includes:

[0075] The value of the byte is compared with a preset threshold to obtain a judgment result;

[0076] If the determination result is that the code value of the character is greater than the preset threshold, the byte is determined to be a high-order Chinese byte;

[0077] The determination result is that the code value of the character is less than or equal to the preset threshold, thus determining that the byte is not a high-order Chinese byte.

[0078] Furthermore, the decoding rule is the decoding rule corresponding to GBK encoding, and the preset threshold is 0x80.

[0079] Furthermore, the method also includes:

[0080] If the byte is not the byte that stores the preset delimiter, the traversal pointer is offset by a second preset offset value.

[0081] In this embodiment, when traversing to any byte, it first determines whether the byte is a high-order Chinese byte. If so, it directly shifts the traversal pointer by a preset offset and skips the traversal of the next byte. This avoids the situation where low-order Chinese bytes are mistakenly identified as English bytes, thereby making the identification of high and low order Chinese bytes more accurate and avoiding the occurrence of garbled characters in Chinese decoding.

[0082] The memory 320 may primarily include a program storage area and a data storage area. The program storage area may store the operating system and at least one application program required for a given function; the data storage area may store data created based on terminal usage. Furthermore, the memory 320 may include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 320 may further include memory remotely located relative to the processor 310, which can be connected to the electronic device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0083] Example 4

[0084] Embodiment 4 of this application also provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform a string decoding method, the method comprising:

[0085] Upon receiving a string parameter to be decoded, each byte in the string parameter to be decoded is traversed.

[0086] When traversing to any byte, read the code value of the byte, and determine whether the byte is a high-order Chinese byte based on the code value of the byte. If it is determined that the byte is a high-order Chinese byte, shift the traversal pointer by a first preset offset value.

[0087] If the byte is not a high-order Chinese byte, determine whether the byte is a byte that stores a delimiter. If so, determine the position of the byte in the string parameter to be decoded, and offset the traversal pointer by a second preset offset value.

[0088] When the byte storing the preset end character is reached during the traversal, the traversal of the string parameter to be decoded ends, and the string parameter to be decoded is truncated into a character unit to be decoded according to the position of the determined preset delimiter.

[0089] Each of the character units to be decoded is decoded based on a preset decoding rule.

[0090] Further, determining whether the byte is a high-order Chinese byte based on its code value includes:

[0091] The value of the byte is compared with a preset threshold to obtain a judgment result;

[0092] If the determination result is that the code value of the character is greater than the preset threshold, the byte is determined to be a high-order Chinese byte;

[0093] The determination result is that the code value of the character is less than or equal to the preset threshold, thus determining that the byte is not a high-order Chinese byte.

[0094] Furthermore, the decoding rule is the decoding rule corresponding to GBK encoding, and the preset threshold is 0x80.

[0095] Furthermore, the method also includes:

[0096] If the byte is not the byte that stores the preset delimiter, the traversal pointer is offset by a second preset offset value.

[0097] In this embodiment, when traversing to any byte, it first determines whether the byte is a high-order Chinese byte. If so, it directly shifts the traversal pointer by a preset offset and skips the traversal of the next byte. This avoids the situation where low-order Chinese bytes are mistakenly identified as English bytes, thereby making the identification of high and low order Chinese bytes more accurate and avoiding the occurrence of garbled characters in Chinese decoding.

[0098] Of course, the computer-executable instructions provided in the embodiments of this application are not limited to the above-described method operations, but can also perform related operations in the string decoding method provided in any embodiment of this application.

[0099] Based on the above description of the implementation methods, those skilled in the art can clearly understand that this application can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.

[0100] It is worth noting that in the embodiments of the search device described above, the various units and modules included are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be achieved; in addition, the specific names of each functional unit are only for easy differentiation and are not used to limit the scope of protection of this application.

[0101] Note that the above description is merely a preferred embodiment and the technical principles employed in this application. Those skilled in the art will understand that this application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments. Many other equivalent embodiments may be included without departing from the concept of this application, and the scope of this application is determined by the scope of the appended claims.

Claims

1. A string decoding method, characterized in that, The method includes: upon receiving a string parameter to be decoded, traversing each byte in the string parameter to be decoded; when traversing to any byte, reading the code value of the byte, determining the size between the code value of the byte and a preset threshold, and obtaining a determination result; if the determination result is that the code value of the character is greater than the preset threshold, determining that the byte is a high-order Chinese byte; if the determination result is that the code value of the character is less than or equal to the preset threshold, determining that the byte is not a high-order Chinese byte; if the byte is determined to be a high-order Chinese byte, shifting the traversal pointer by a first preset offset value, where the preset threshold is 0x80; if the byte is not... For non-high-order Chinese bytes, determine whether the byte is a byte storing a delimiter. If so, determine the position of the byte in the string parameter to be decoded and offset the traversal pointer by a second preset offset value. If the byte is not a byte storing a preset delimiter, offset the traversal pointer by the second preset offset value. When the traversal reaches a byte storing a preset end character, the traversal of the string parameter to be decoded ends. The string parameter to be decoded is truncated into character units to be decoded according to the determined position of the preset delimiter. Each character unit to be decoded is decoded based on a preset decoding rule, which is the decoding rule corresponding to GBK encoding.

2. A string decoding device, characterized in that, The device includes: a traversal module, used to traverse each byte of the string parameter to be decoded upon receiving it; a Chinese character determination module, used to read the code value of any byte when traversing it, and determine whether the byte is a high-order Chinese byte based on the code value. If the byte is determined to be a high-order Chinese byte, the traversal pointer is offset by a first preset offset value; a delimiter determination module, used to determine whether the byte is a byte storing a delimiter if it is not a high-order Chinese byte, and if so, to determine the position of the byte in the string parameter to be decoded and offset the traversal pointer by a second preset offset value; and a byte truncation module, used to end the traversal of the string parameter to be decoded upon reaching a byte storing a preset end character, and then truncate the byte according to the determined preset delimiter. The position truncates the string parameter to be decoded into character units to be decoded; the byte decoding module is used to decode each character unit to be decoded based on a preset decoding rule, the decoding rule being the decoding rule corresponding to GBK encoding; the Chinese character judgment module includes: a threshold comparison unit, used to judge the size between the code value of the byte and a preset threshold to obtain a judgment result, the preset threshold being 0x80; a first judgment unit, used to determine that the byte is a high-order Chinese byte if the judgment result is that the code value of the character is greater than the preset threshold; a second judgment unit, used to determine that the byte is not a high-order Chinese byte if the judgment result is that the code value of the character is less than or equal to the preset threshold; and a pointer offset module, used to offset the traversal pointer by a second preset offset value if the byte is not a byte storing a preset delimiter.

3. An electronic device, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the string decoding method as described in claim 1.

4. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the string decoding method as described in claim 1.

Citation Information

Patent Citations

  • Chinese character automatic checking and error-correcting system aiming at GBK (Chinese Internal Code Specification) encoding and method thereof

    CN102479174A

  • Data coding type identifying and transcoding method and device

    CN104994128A