A gb18030 input method candidate generation and interaction input method and system
By using a GB18030 input method candidate generation and interactive input method, the problem of being unable to input GB18030 four-byte encoding in existing technologies has been solved, enabling real-time parsing and interactive input, reducing operational complexity and improving user experience.
Patent Information
- Application Number
- CN202611089858.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-22
- Publication Date
- 2026-11-06
AI Technical Summary
Existing input method systems cannot directly input GB18030 four-byte encoding, making it impossible for users to input L3 level rare characters. Furthermore, existing encoding conversion tools lack real-time performance and interactive capabilities.
This paper provides a method for generating and interactively inputting GB18030 input method candidates. Through input buffering, encoding parsing, candidate generation, and interactive input, it realizes real-time parsing and interactive input of GB18030 encoding. The method includes the system design of input buffering module, encoding parsing module, candidate generation module, and interactive module.
It achieves unified parsing and real-time candidate generation of GB18030 double-byte and four-byte encodings, significantly reducing input memory and operation costs, constructing a complete interactive closed loop from encoding input to character display, and improving the system's robustness and user experience.
Smart Images

Figure CN123047803A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer input methods, and in particular to a GB18030 input method candidate generation and interactive input method and system. Background Technology
[0002] GB18030 is my country's current national character encoding standard, supporting single-byte, double-byte, and four-byte encoding lengths. The four-byte encoding ranges from 0x81308130 to 0xFE39FE39, and is used to include extended characters from the CJK Unified Ideographs extension area and minority scripts. In existing input method systems, users typically rely on semantic encoding methods such as Pinyin and Wubi to input characters, and cannot directly input characters using character encoding (such as GB18030 encoding). Many of the four-byte characters in the GB18030 standard belong to L3 level rare characters. Ordinary input methods usually only support up to L2 level, and these characters are not included in the code table. Therefore, they cannot parse the corresponding input sequences or provide real-time interactive feedback, resulting in users being unable to input them.
[0003] Existing encoding conversion tools (such as iconv) are mainly used for offline file-level or data-level conversion, lacking real-time and interactive capabilities during the input process. In scenarios such as character testing, encoding verification, and special character input, users need an input method that can directly input GB18030 encoding and obtain character feedback in real time.
[0004] Therefore, there is an urgent need for a technical solution that deeply integrates GB18030 encoding parsing, encoding conversion and input method candidate interaction mechanism to achieve a complete interactive closed loop from encoding input to character display on screen. Summary of the Invention
[0005] To address the technical problem that existing technologies cannot perform real-time parsing and interactive input of GB18030 four-byte encoding at the input method level, this invention provides a GB18030 input method candidate generation and interactive input method and system.
[0006] In a first aspect of the present invention, a method for generating GB18030 input method candidates and interactive input is provided. The method includes: Step S1, Input Buffer: The user-typed input string is cached and maintained in the current input context as the sole data source for subsequent encoding parsing and candidate generation; the input string is a hexadecimal character sequence encoded in GB18030. Step S2, Encoding Parsing: Based on the length and character characteristics of the input string, determine the encoding path of GB18030, and determine the number of hexadecimal characters and candidates required for complete encoding according to the encoding path. The encoding path includes a two-byte encoding path and a four-byte encoding path. Assemble the currently input string into a GB18030 byte sequence. Step S3, Candidate Generation: When the length of the input string is equal to the number of bits required for the complete encoding minus one, keep all bytes in the GB18030 byte sequence except the last byte unchanged, and perform successive incrementing exhaustive enumeration only on the last byte. After each incrementing exhaustive enumeration, the byte sequence is converted into UTF-8 candidate characters through the GB18030 to UTF-8 encoding conversion channel pre-established during the system initialization phase, generating a candidate list with index labels; the lower four hexadecimal bits of the last byte after each increment are called the last bit encoding; Step S4, Interactive Input: Receive key events transmitted by the input method framework and process them according to their type; When a selection key or space key corresponding to an index label is received, the target candidate character is selected from the candidate list and submitted to the current application screen. When the input string is not empty and the Enter key is received, the current input string is submitted to the screen as is and the session state is reset. When the input string is not empty, if a backspace key is pressed, the current input string will be entered one position back and the interface will be refreshed. If a cancel key is received while the input string is not empty, the current input string is discarded and the session state is reset.
[0007] By adopting the above technical solution, the present invention realizes unified parsing and real-time candidate generation of GB18030 double-byte and four-byte encodings within the input method framework. Users only need to input the first few digits of the complete encoding to quickly locate the target character through the candidate list, which significantly reduces the memory and typing cost of GB18030 internal code input.
[0008] Optionally, the step of determining the GB18030 encoding path based on the length and character features of the input string, and determining the number of hexadecimal characters and candidate characters required for complete encoding based on the encoding path, specifically includes: When the hexadecimal character corresponding to the high four bits of the second byte in the input string is “3”, it is determined that the encoding path of GB18030 is a four-byte encoding path, and the number of hexadecimal characters required for complete encoding is 8, and the number of candidates is 10. When the hexadecimal character corresponding to the high four bits of the second byte in the input string is not "3", it is determined that the encoding path of GB18030 is a double-byte encoding path, and the number of hexadecimal characters required for complete encoding is 4, and the number of candidates is 16.
[0009] By adopting the above technical solution, lightweight path discrimination is performed by utilizing the structural feature that the second byte of the GB18030 four-byte encoding always falls between 0x30 and 0x39. The encoded path can be quickly determined without byte-by-byte complete interval verification, thus balancing discrimination efficiency and accuracy.
[0010] Optionally, assembling the currently input string into a GB18030 byte sequence specifically includes: The input string is converted into byte values in pairs. Each byte is composed of the high-order half-byte value multiplied by sixteen and the low-order half-byte value. When the length of the input string is equal to the number of bits required for complete encoding minus one, the low-order half-byte of the corresponding last byte is treated as zero.
[0011] By adopting the above technical solution, a precise mapping from hexadecimal strings to GB18030 byte sequences was achieved. When the input is incomplete, the integrity of the byte sequence is ensured by padding the last byte with zeros, providing a correct baseline sequence for subsequent candidate exhaustive search.
[0012] Optionally, the step of performing an enumeration by incrementing the last byte includes: The process is looped based on the GB18030 byte sequence. In each round, the GB18030 byte sequence is first converted into UTF-8 candidate characters, and then the last byte of the GB18030 byte sequence is incremented by one. In this way, the characters corresponding to the continuously incremented values of the last byte starting from the current value are enumerated in turn. Among them, the double-byte encoding path exhaustively explores 16 possible values of the last byte to generate 16 candidate options, which correspond to the candidate quantity of 16; the four-byte encoding path exhaustively explores 10 possible values of the last byte to generate 10 candidate options, which correspond to the candidate quantity of 10.
[0013] By adopting the above technical solution, when the input string is only missing the last bit, all legal values of the last byte are automatically enumerated, transforming "precise input of the last bit code" into "selection from the candidate list", which greatly reduces the operational complexity of internal code input.
[0014] Optionally, the index tags are assigned in the following way: For each candidate, an index label is generated according to the number of candidates. The label characters of the index label are extracted sequentially from 0 to 9 and a to f according to the number of candidates, and correspond one-to-one with the corresponding selection key, so that any candidate can be directly selected by the corresponding selection key; the label characters of the index label correspond one-to-one with the last digit code.
[0015] By adopting the above technical solution, a direct mapping relationship is formed between candidate tags and the last code. Users can deduce the value of the last code from the candidate position, which takes into account both the convenience of selection and the continuity of code cognition.
[0016] Optionally, the processing of the key events also includes event filtering: Key release events and key events with modifier keys are allowed directly, while simple key press events are handled later. When the input string is not empty but a non-hexadecimal character is received, the key press event is intercepted and not displayed on the screen. When the input string is empty and the first hexadecimal character has not yet been received, letter keys are blocked, while number keys and function keys are allowed. After the first hexadecimal character is received, subsequent letter keys are entered into the input buffer as valid hexadecimal characters.
[0017] By adopting the above technical solution and using a layered event filtering strategy, the normal key semantics are guaranteed while the interference of non-hexadecimal characters on the internal code input process is effectively avoided.
[0018] Optionally, the input buffer further includes: For numeric keys from the numeric keypad, they are first normalized to be the same characters as the numeric keys on the main keyboard, and then the normalized characters are appended to the input string to ensure the consistency of input behavior between the main keyboard and the numeric keypad. Any change to the input string content triggers a screen refresh, instantly reflecting the change in input state in the candidate window and the pre-edited text.
[0019] By adopting the above technical solution, the input difference between the main keyboard and the numeric keypad is eliminated, and the change-driven refresh mechanism ensures real-time synchronization between the input status and the interface display.
[0020] Optionally, the establishment and use of the encoding conversion channel includes: Create an encoding conversion channel during the system initialization phase; If creation fails, the system initialization will be terminated and the error will be reported to ensure that subsequent conversions are available from the source. During the candidate generation process, each GB18030 byte sequence obtained through exhaustive search is converted into UTF-8 candidate characters through an encoding conversion channel, which are then used as the display content of each candidate in the candidate list.
[0021] By adopting the above technical solution, encoding conversion tools (such as iconv) are extended from offline tools to real-time components during input method runtime. By pre-building conversion channels during the initialization phase and terminating the startup in case of failure, the reliability and consistency of encoding conversion during candidate generation are ensured.
[0022] Optional features include candidate window display and real-time refresh: The constructed candidate list is injected into the candidate window through the input method framework interface; Depending on whether the client supports pre-edited text display, select to echo the current input string in either highlighted or normal pre-edited text mode; Each time the input string changes, the candidate window display content is reset first, and then a new candidate list is attached and refreshed when the candidate generation conditions are met, so as to realize the real-time update of the candidate options and the pre-edited text.
[0023] By adopting the above technical solution, a dual-channel real-time display of the candidate list and pre-edited text was achieved, and the display mode was adaptively selected according to the client's capabilities, thus improving cross-platform compatibility.
[0024] In a second aspect of the invention, a GB18030 input method candidate generation and interactive input system is provided. The system includes: Input buffer module: used to cache and maintain the input string typed by the user in the current input context, as the sole data source for subsequent encoding parsing and candidate generation; the input string is a hexadecimal character sequence encoded in GB18030; Encoding parsing module: used to determine the encoding path of GB18030 based on the length and character features of the input string, determine the number of hexadecimal characters and candidates required for complete encoding based on the encoding path, the encoding path includes a two-byte encoding path and a four-byte encoding path, and assemble the currently input string into a GB18030 byte sequence; Candidate generation module: When the length of the input string is equal to the number of bits required for the complete encoding minus one, it keeps all bytes in the GB18030 byte sequence unchanged except for the last byte, and performs successive incrementing exhaustive enumeration only on the last byte. After each incrementing exhaustive enumeration, the byte sequence is converted into UTF-8 candidate characters through the GB18030 to UTF-8 encoding conversion channel pre-established during the system initialization phase, generating a candidate list with index labels; the lower four hexadecimal bits of the last byte after each increment are called the last bit code; Interaction module: Used to receive key events transmitted by the input method framework and process them according to the type of key event; When a selection key or space key corresponding to an index label is received, the target candidate character is selected from the candidate list and submitted to the current application screen. When the input string is not empty and the Enter key is received, the current input string is submitted to the screen as is and the session state is reset. When the input string is not empty, if a backspace key is pressed, the current input string will be entered one position back and the interface will be refreshed. If a cancel key is received while the input string is not empty, the current input string is discarded and the session state is reset.
[0025] In summary, the present invention has at least one of the following beneficial technical effects: 1. By using a lightweight encoding path discrimination mechanism based on input string length and character features, the GB18030 two-byte and four-byte encoding paths can be quickly distinguished without the need for byte-by-byte complete interval verification, which significantly improves the encoding parsing efficiency while ensuring the accuracy of discrimination; 2. By using the candidate generation mechanism of auto-incrementing the last byte, the process of "precisely inputting the complete code" is transformed into "selecting from the candidate list after inputting the first few digits". This reduces the number of times a two-byte path is typed from 4 to 3 and a four-byte path from 8 to 7, significantly reducing the memory burden and operational cost of GB18030 code input. 3. By embedding encoding conversion tools such as iconv into the input method's workflow, a complete interactive closed loop of encoding input, parsing, conversion, candidate display, and character display is constructed, realizing a mode leap from "offline tool" to "input process component" for encoding conversion; 4. By establishing a one-to-one mapping between index labels and last-digit codes, users can intuitively deduce the last-digit code value from the candidate position, thus balancing input efficiency with the continuity of code cognition. 5. Through mechanisms such as hierarchical event filtering, main keypad normalization, pre-construction of conversion channels during initialization, and termination upon failure, the robustness of the system and the consistency of user experience are ensured throughout the entire process from input acquisition, encoding parsing, candidate generation to interactive on-screen display. Attached Figure Description
[0026] Figure 1 This is a flowchart illustrating a GB18030 input method candidate generation and interactive input method according to an embodiment of this application.
[0027] Figure 2 This is a flowchart of the encoding parsing and candidate generation process in an embodiment of this application.
[0028] Figure 3 This is an architecture diagram of a GB18030 input method candidate generation and interactive input system according to an embodiment of this application. Detailed Implementation
[0029] The present invention will be further described in detail below with reference to the accompanying drawings.
[0030] This specific embodiment is merely an explanation of the present invention and is not intended to limit the invention. After reading this specification, those skilled in the art can make modifications to this embodiment without contributing any inventive step, but such modifications are protected by patent law as long as they fall within the scope of the claims of the present invention.
[0031] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0032] The following are explanations of the relevant technical terms involved in this invention: GB18030 encoding: The national character encoding standard, supporting 1 / 2 / 4 byte encoding.
[0033] Four-byte encoding: The encoding format used for extended characters in GB18030.
[0034] iconv: A general character encoding conversion library.
[0035] Fcitx5 / Input Method Framework: A system that handles input events, candidate generation, and display on screen, such as Fcitx5, ibus, etc.
[0036] Candidate Window (Candidate Panel): The interface through which the input method displays a list of candidate characters.
[0037] The embodiments of the present invention will now be described in further detail with reference to the accompanying drawings.
[0038] like Figure 1 and Figure 2 As shown, this embodiment provides a GB18030 input method candidate generation and interactive input method, applied to the GB18030 internal code input mode based on the Fcitx5 input method framework. The user enters the GB18030 internal code of the target character using hexadecimal characters (0-9, af). The system automatically determines the code length, assembles the byte sequence, completes the encoding conversion, and generates a candidate character list. The user then inputs the candidate character using the selection key, space bar, and enter key. The specific steps are as follows: Step S1: Input buffer.
[0039] An input buffer is established within the current input context, storing the hexadecimal character sequence in the order the user types. The buffer provides the current complete input string to the outside world for use in encoding parsing, candidate generation, and pre-edited text display.
[0040] When a user types a hexadecimal character, the valid hexadecimal characters are appended sequentially. For numeric keys on the numeric keypad, they are first normalized to match the characters on the main keyboard numeric keys, and then the normalized characters are appended to the input string, thus ensuring consistency between the input behavior of the main keyboard and the numeric keypad.
[0041] The buffer supports backspace deletion: when the input string is not empty, it supports deleting the last typed character.
[0042] Supports clear and reset operations: After the user cancels, submits, or selects a candidate, the input string is cleared and the session state is reset.
[0043] Once any of the above operations that change the content of the input string is completed, the interface will be refreshed, and the change in the input state will be reflected in the candidate window and the pre-edited text in real time.
[0044] Step S2: Encoding parsing.
[0045] Determine the GB18030 encoding path based on the length and character characteristics of the input string. The GB18030 four-byte encoding uses the 0x30-0x39 range, which is not used in GB / T 11383-1989, as an extended suffix. Its encoding range is from 0x81308130 to 0xFE39FE39, and the second byte always falls between 0x30 and 0x39.
[0046] Therefore, when the hexadecimal character corresponding to the high four bits of the second byte in the input string is "3", the encoding path of GB18030 is determined to be a four-byte encoding path, and the number of hexadecimal characters required for complete encoding is 8, with a candidate number of 10 (corresponding to the last value of 0 to 9); when the hexadecimal character corresponding to the high four bits of the second byte in the input string is not "3", the encoding path of GB18030 is determined to be a two-byte encoding path, and the number of hexadecimal characters required for complete encoding is 4, with a candidate number of 16 (corresponding to all enumerations of the last hexadecimal value from 0 to f).
[0047] The input string is converted into byte values in pairs. Each byte is composed of the high-order nibble multiplied by sixteen and then the low-order nibble. When the length of the input string is equal to the number of bits required for complete encoding minus one, the low-order nibble of the corresponding last byte is treated as zero. For example, when the input string is "813", it is assembled into the byte sequence [0x81, 0x30]; when the input string is "8130", it is assembled into the byte sequence [0x81, 0x30].
[0048] During system initialization, a GB18030 to UTF-8 encoding conversion channel (implemented using the iconv library) is pre-established. If the creation of this encoding conversion channel fails, the system initialization will terminate with an error, ensuring that subsequent conversions are available from the source.
[0049] Step S3: Candidate generation.
[0050] When the length of the input string is equal to the number of bits required for full encoding minus one, the candidate generation process is triggered.
[0051] The process is based on a GB18030 byte sequence and iterates through the data. In each round, the GB18030 byte sequence is first converted into UTF-8 candidate characters. Then, the last byte of the GB18030 byte sequence is incremented by one, thereby enumerating the characters corresponding to consecutive codes with the last byte value of 0, 1, 2, etc.
[0052] Taking a two-byte encoded path as an example, assuming the user has entered "813" (corresponding to the byte sequence [0x81, 0x30]), the system will start with 0x30 and enumerate 16 possible values from 0x30 to 0x3f, generating 16 candidate characters after conversion. Taking a four-byte encoded path as an example, assuming the user has entered "8130813" (corresponding to the byte sequence [0x81, 0x30, 0x81, 0x30]), the system will start with 0x30 and enumerate 10 possible values from 0x30 to 0x39, generating 10 candidate characters.
[0053] Each candidate character is encapsulated as an independent candidate, which internally stores the text content that can be displayed on the screen, and retains the ability to access the session state for use when selected.
[0054] For each candidate, an index label is generated based on the number of candidates. The label characters are sequentially extracted from 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, according to the number of candidates, and correspond one-to-one with the corresponding selection key, allowing any candidate to be directly selected by the corresponding key. The value of the candidate label also intuitively corresponds to the value of the last digit code, allowing the user to deduce the last digit code from the candidate position. For example, the label "0" corresponds to the last digit code "0", and the label "f" corresponds to the last digit code "f".
[0055] Step S4: Interactive input.
[0056] The constructed candidate list is injected into the candidate window via the input method framework interface. Depending on whether the application supports pre-edited text display, the current input string is displayed either as highlighted pre-edited text or as normal pre-edited text. Each time the input string changes, the candidate window display content is reset first, and then a new candidate list is attached and refreshed when the trigger condition is met, achieving real-time updates of the candidates and pre-edited text, including the following eight cases: 1. Event filtering (see attached document) Figure 1 In the "Whether it is a key release or a key combination with modifier keys": key release events and key events with modifier keys are allowed directly, while simple key press events are handled later to avoid accidental triggering.
[0057] 2. Candidate selection key processing: When the candidate list exists and is not empty, the selection key (0-9, af) is mapped to the corresponding candidate index. When the index is valid, the corresponding candidate is selected and displayed on the screen. Then the input string is cleared and the interface is reset.
[0058] 3. Space confirmation: When the candidate list exists and is not empty and a space key is received, the default candidate character is submitted to the screen, then the input string is cleared and the interface is reset, thus ending the current input loop.
[0059] 4. Enter key to submit original input: When the candidate list does not exist and the input string is not empty, and the Enter key is pressed, the current input string is submitted as is and the session state is reset. This is used to directly submit the typed coded text (corresponding to the appendix). Figure 1 The input loop is described as follows: "Submit the current input string as is - clear the input string and reset the interface - end the current input loop".
[0060] 5. Backspace Delete: When the candidate list does not exist and the input string is not empty, and a backspace key is pressed, backspace one position and refresh the interface (see attached diagram). Figure 1 The "Delete last character of input string - refresh interface and echo current input string" option (as shown in the attached document) will cause the number of characters in the input string to fall below the trigger condition. If this causes the number of characters in the input string to fall below the trigger condition, the candidate list will be cancelled accordingly (see attached document). Figure 1 The process involves checking if the entered number of digits equals the length of the complete internal code minus one, exhaustively searching for each digit of the internal code to generate an indexed candidate list, displaying the candidates in the candidate panel, and waiting for the next key press.
[0061] 6. Cancel Input: When the candidate list does not exist, the input string is not empty, and a cancel key is pressed, the current input is discarded and the state is cleared (see attached diagram). Figure 1 The message "Clear input serial and parallel reset interface - End of this input loop" appears in the code.
[0062] 7. Illegal Character Interception: When the candidate list does not exist and the input string is not empty and a non-hexadecimal character is received, the key press event is intercepted and not displayed on the screen to prevent irrelevant characters from interfering with the internal code input (see attached table). Figure 1 The function "Append this character to the input string - refresh the interface and echo the current input string" is included. When the input string is empty, letter keys are intercepted (see attached image). Figure 1 The options include "Is the key a letter key? - Swallow the key - Wait for the next key press" and allowing other keys to proceed (see attached instructions). Figure 1 The option "Is the key a letter key? - Do not process, return to the system" is used to take into account the key semantics when the input method is active.
[0063] 8. Selecting a candidate and resetting the status: When a candidate is selected, its text content is submitted to the current application, and the input string is immediately cleared, the session status is reset, and the interface is refreshed, completing a complete input loop.
[0064] The specific procedures for the above eight situations are as follows: Step S41: Receive user key press events and determine whether the key press event is a key release event or a combination key with modifier keys; If so, do not process and return to the system, thus ending the current input loop; If not, proceed to step S42.
[0065] Step S42: Determine whether the candidate list is currently displayed; If so, proceed to step S43; If not, proceed to step S44.
[0066] Step S43: Determine the key type of the key event; If the key type is a candidate selection key and the corresponding candidate exists, the selected candidate character is submitted to the screen, the input string is cleared and the interface is reset, and the input loop ends. If the key type is a candidate selection key and the corresponding candidate does not exist, then the key event is intercepted and the system waits for the next key event. If the key type is the space bar, the default candidate character is submitted to the screen, the input string is cleared and the interface is reset, and the input loop ends. If the button type is other buttons, then proceed to step S44.
[0067] Step S44: Directly process the input string and determine whether the current input string is empty; If so, proceed to step S45; If not, proceed to step S46.
[0068] Step S45: Determine whether the key press event is a hexadecimal character; If not, if the key event is a letter key, intercept the key event and wait for the next key event; if the key event is not a letter key, do not process it, switch systems, and end the current input loop. If so, append the character to the input string, refresh the interface and echo the current input string, and then proceed to step 47.
[0069] Step S46: Perform a second judgment on the case type of the button event; If the key type is backspace, delete the last character of the input string, refresh the interface and echo the current input string, and then proceed to step 47; If the key type is Enter, the current input string will be submitted to the screen as is, the input string will be cleared and the interface will be reset, and the current input loop will end. If the key type is a hexadecimal character, then append the character to the input string and proceed to step 47. If the key type is the cancel key, the input string will be cleared and the interface will be reset, ending the current input loop. If the key press type is another illegal character (such as m, n, etc.), the key press event is intercepted and the system waits for the next key press event.
[0070] Step S47: Determine if the number of digits already entered is equal to the length of the complete internal code minus one; If not, simply wait for the next button press; If so, exhaustively search the last digit of the internal code to generate a candidate list to be indexed, display it in the candidate window, and wait for the next key press event.
[0071] Figure 3 This is an architecture diagram of a GB18030 input method candidate generation and interactive input system. The system specifically includes four parts: an input buffer module, an encoding parsing module, a candidate generation module, and an interaction module, forming a complete closed loop from internal code input to character output. The input buffer module is responsible for caching the user input sequence. It caches and maintains the user-typed input string (a GB18030 encoded hexadecimal character sequence) in the current input context, serving as the sole data source for subsequent encoding parsing and candidate generation. It maintains the input string in the current input context and provides the complete input string externally. It supports appending, backspace deletion, clearing, and resetting functions. It normalizes the numeric keys from the numeric keypad to ensure consistency between the main keyboard and numeric keypad input behavior. It triggers a UI refresh when the input string content changes.
[0072] The encoding parsing module is used to determine the GB18030 encoding path based on the length and character characteristics of the input string. Based on the encoding path, it determines the number of hexadecimal characters and candidate characters required for complete encoding. The encoding path includes a two-byte encoding path and a four-byte encoding path. It assembles the currently input string into a GB18030 byte sequence and converts it into UTF-8 text. It uses the structural characteristics of the GB18030 four-byte encoding for lightweight discrimination. It converts the hexadecimal strings into byte values in pairs. Using a pre-established GB18030 to UTF-8 encoding conversion channel, it converts the assembled byte sequence into UTF-8 text that can be displayed on the screen.
[0073] The candidate generation module is used to keep all bytes in the GB18030 byte sequence unchanged except for the last byte when the length of the input string is equal to the number of bits required for the complete encoding minus one. Only the last byte is subjected to successive incrementing exhaustive enumeration. After each incrementing exhaustive enumeration, the byte sequence is converted into UTF-8 candidate characters through the GB18030 to UTF-8 encoding conversion channel pre-established during the system initialization phase, generating a candidate list with index labels. The lower four hexadecimal bits of the last byte after each increment are called the last bit code.
[0074] The interaction module is responsible for uniformly handling user operations such as candidate selection, confirmation, submission, deletion, and cancellation, completing the display of the target text and resetting the session state. It receives key events transmitted from the input method framework and processes them according to their type. When it receives a selection key or space key corresponding to an index label, it selects the target candidate character from the candidate list and submits it to the current application for display. When the input string is not empty and a Enter key is received, it submits the current input string as is and resets the session state. When the input string is not empty and a Backspace key is received, it backtracks the current input string by one position and refreshes the interface. When the input string is not empty and a Cancel key is received, it discards the current input string and resets the session state.
[0075] The system process is as follows: User presses a key event -- Interaction module receives the key event -- Interaction module calls input buffer module to append characters -- Input buffer module triggers change-driven refresh -- Interaction module calls encoding and parsing module to determine the path -- Encoding and parsing module returns (path type + maximum number of bytes + number of candidates + whether candidate generation was triggered) -- Interaction module calls candidate generation module (if candidate generation was triggered) -- Candidate generation module calls encoding and parsing module to assemble byte sequence -- Candidate generation module performs last-bit exhaustive search -- Candidate generation module calls iconv to transform each candidate -- Candidate generation module constructs candidate objects and assigns indices -- Candidate generation module returns candidate list to interaction module -- Interaction module injects candidate window and refreshes pre-edited text.
[0076] To facilitate understanding of this invention, the following are application scenario examples: Scenario 1: Inputting rare four-byte characters.
[0077] The user needs to input a rare character encoded in GB18030 four bytes. The user switches to GB18030 input mode and enters "8", "1", "3", "0", "8", "1", "3" in sequence. When the 7th character is entered, the system determines it to be a four-byte encoded path (because the high-order bit of the second byte is "3"). The entered digits (7) equal the full length (8 minus one), triggering candidate generation. The system uses the byte sequence [0x81, 0x30, 0x81, 0x30] as a baseline, exhaustively listing 10 possible values from the last byte (0x30-0x39). After iconv transformation, 10 candidate characters are generated and assigned index labels 0-9. The candidate window displays these 10 candidates in real time. The user presses the "5" key to select the 6th candidate, which is then displayed on the screen. The input buffer is cleared, completing one input cycle.
[0078] Scenario 2: Double-byte character input.
[0079] The user needs to input a GB18030 double-byte encoded character. The user enters "8", "1", and "3". When the third character is entered, the system determines it to be a double-byte encoded path (because the high-order bit of the second byte is "3", but the number of characters entered is less than 4, so further judgment is needed; when the third character is entered, the corresponding character in the high-order bit of the second byte is "3", but the complete length of the double-byte path is 4, so 3 characters have been entered but the trigger condition has not yet been met; after the user continues to enter the fourth character, if the complete input is "8130", it will be directly displayed; if the user only enters "813", because 3 characters are less than 4 characters minus one (i.e., 3 characters), candidate generation is triggered, exhaustively listing 16 candidates). The user selects the target character from the candidate list to display.
[0080] Scenario 3: Encoding verification and testing.
[0081] When testing GB18030 encoding support, developers need to quickly verify the characters corresponding to a specific encoding. Using the Enter key submission function of this invention, developers can directly view the encoded text; the candidate generation function allows them to quickly browse all legal characters under a given encoding prefix, improving testing efficiency.
[0082] The above description is merely a preferred embodiment of the present invention and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this invention is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the foregoing disclosed concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this invention.
[0083] The above description is merely a preferred embodiment of the present invention and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this invention is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the foregoing disclosed concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this invention.
Claims
1. A GB18030 input method candidate generation and interaction input method, characterized in that, include: Step S1, Input Buffer: The user-typed input string is cached and maintained in the current input context as the sole data source for subsequent encoding parsing and candidate generation; the input string is a hexadecimal character sequence encoded in GB18030. Step S2, Encoding Parsing: Based on the length and character characteristics of the input string, determine the encoding path of GB18030, and determine the number of hexadecimal characters and candidates required for complete encoding according to the encoding path. The encoding path includes a two-byte encoding path and a four-byte encoding path. Assemble the currently input string into a GB18030 byte sequence. Step S3, Candidate Generation: When the length of the input string is equal to the number of bits required for the complete encoding minus one, keep all bytes in the GB18030 byte sequence except the last byte unchanged, and perform successive incrementing exhaustive enumeration only on the last byte. After each incrementing exhaustive enumeration, the byte sequence is converted into UTF-8 candidate characters through the GB18030 to UTF-8 encoding conversion channel pre-established during the system initialization phase, generating a candidate list with index labels; the lower four hexadecimal bits of the last byte after each increment are called the last bit encoding; Step S4, Interactive Input: Receive key events transmitted by the input method framework and process them according to their type; When a selection key or space key corresponding to an index label is received, the target candidate character is selected from the candidate list and submitted to the current application screen. When the input string is not empty and the Enter key is received, the current input string is submitted to the screen as is and the session state is reset. When the input string is not empty, if a backspace key is pressed, the current input string will be entered one position back and the interface will be refreshed. If a cancel key is received while the input string is not empty, the current input string is discarded and the session state is reset.
2. The GB18030 input method candidate generation and interaction input method according to claim 1, wherein, The step of determining the GB18030 encoding path based on the length and character features of the input string, and determining the number of hexadecimal characters and candidate characters required for complete encoding based on the encoding path, specifically includes: When the hexadecimal character corresponding to the high four bits of the second byte in the input string is "3", it is determined that the encoding path of GB18030 is a four-byte encoding path, and the number of hexadecimal characters required for complete encoding is 8, and the number of candidates is 10. When the hexadecimal character corresponding to the high four bits of the second byte in the input string is not "3", it is determined that the encoding path of GB18030 is a double-byte encoding path, and the number of hexadecimal characters required for complete encoding is 4, and the number of candidates is 16.
3. The GB18030 input method candidate generation and interactive input method according to claim 1, characterized in that, The step of assembling the currently input string into a GB18030 byte sequence specifically includes: The input string is converted into byte values in pairs. Each byte is composed of the high-order half-byte value multiplied by sixteen and the low-order half-byte value. When the length of the input string is equal to the number of bits required for complete encoding minus one, the low-order half-byte of the corresponding last byte is treated as zero.
4. The GB18030 input method candidate generation and interactive input method according to claim 1, characterized in that, The process of performing an enumeration by incrementing the last byte includes: The process is looped based on the GB18030 byte sequence. In each round, the GB18030 byte sequence is first converted into UTF-8 candidate characters, and then the last byte of the GB18030 byte sequence is incremented by one. In this way, the characters corresponding to the continuously incremented values of the last byte starting from the current value are enumerated in turn. Among them, the double-byte encoding path exhaustively explores 16 possible values of the last byte to generate 16 candidate options, which correspond to the candidate quantity of 16; the four-byte encoding path exhaustively explores 10 possible values of the last byte to generate 10 candidate options, which correspond to the candidate quantity of 10.
5. The GB18030 input method candidate generation and interactive input method according to claim 1, characterized in that, The specific method for allocating the index tags is as follows: For each candidate, an index label is generated according to the number of candidates. The label characters of the index label are extracted sequentially from 0 to 9 and a to f according to the number of candidates, and correspond one-to-one with the corresponding selection key, so that any candidate can be directly selected by the corresponding selection key; the label characters of the index label correspond one-to-one with the last digit code.
6. The GB18030 input method candidate generation and interactive input method according to claim 1, characterized in that, The handling of key events also includes event filtering: Key release events and key events with modifier keys are allowed directly, while simple key press events are handled later. When the input string is not empty but a non-hexadecimal character is received, the key press event is intercepted and not displayed on the screen. When the input string is empty and the first hexadecimal character has not yet been received, the letter keys are blocked, while the number keys and function keys are allowed. After receiving the first hexadecimal character, subsequent letter keys are entered into the input buffer as valid hexadecimal characters.
7. The GB18030 input method candidate generation and interactive input method according to claim 1, characterized in that, The input buffer also includes: For numeric keys from the numeric keypad, they are first normalized to be the same characters as the numeric keys on the main keyboard, and then the normalized characters are appended to the input string to ensure the consistency of input behavior between the main keyboard and the numeric keypad. Any change to the input string content triggers a screen refresh, instantly reflecting the change in input state in the candidate window and the pre-edited text.
8. The GB18030 input method candidate generation and interactive input method according to claim 1, characterized in that, The establishment and use of the encoding conversion channel includes: Create an encoding conversion channel during the system initialization phase; If creation fails, the system initialization will be terminated and the error will be reported to ensure that subsequent conversions are available from the source. During the candidate generation process, each GB18030 byte sequence obtained through exhaustive search is converted into UTF-8 candidate characters through an encoding conversion channel, which are then used as the display content of each candidate in the candidate list.
9. The GB18030 input method candidate generation and interactive input method according to claim 1, characterized in that, This also includes candidate window display and real-time refresh: The constructed candidate list is injected into the candidate window through the input method framework interface; Depending on whether the client supports pre-edited text display, select to echo the current input string in either highlighted or normal pre-edited text mode; Each time the input string changes, the candidate window display content is reset first, and then a new candidate list is attached and refreshed when the candidate generation conditions are met, so as to realize the real-time update of the candidate options and the pre-edited text.
10. A GB18030 input method candidate generation and interactive input system, characterized in that, include: Input buffer module: used to cache and maintain the input string typed by the user in the current input context, as the sole data source for subsequent encoding parsing and candidate generation; the input string is a hexadecimal character sequence encoded in GB18030; Encoding parsing module: used to determine the encoding path of GB18030 based on the length and character features of the input string, determine the number of hexadecimal characters and candidates required for complete encoding based on the encoding path, the encoding path includes a two-byte encoding path and a four-byte encoding path, and assemble the currently input string into a GB18030 byte sequence; Candidate generation module: When the length of the input string is equal to the number of bits required for the complete encoding minus one, it keeps all bytes in the GB18030 byte sequence unchanged except for the last byte, and performs successive incrementing exhaustive enumeration only on the last byte. After each incrementing exhaustive enumeration, the byte sequence is converted into UTF-8 candidate characters through the GB18030 to UTF-8 encoding conversion channel pre-established during the system initialization phase, generating a candidate list with index labels; the lower four hexadecimal bits of the last byte after each increment are called the last bit code; Interaction module: Used to receive key events transmitted by the input method framework and process them according to the type of key event; When a selection key or space key corresponding to an index label is received, the target candidate character is selected from the candidate list and submitted to the current application screen. When the input string is not empty and the Enter key is received, the current input string is submitted to the screen as is and the session state is reset. When the input string is not empty, if a backspace key is pressed, the current input string will be entered one position back and the interface will be refreshed. If a cancel key is received while the input string is not empty, the current input string is discarded and the session state is reset.
