Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of Google Pinyin input method to expand API development?

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "Google Pinyin input method to expand API development method is what", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "Google Pinyin input method to expand API development method is what" it!

New featur

The input method extension API supports the converter extension, and when the user opens the converter, the candidate can be operated such as decoration, special effects, transformation and so on.

Added a set of string utility functions for UNICODE transcoding.

Introduction

In order to help developers develop and define richer extended input functions based on the basic input functions of Google Pinyin input method, Google Pinyin input method provides an input method extension API based on Lua script programming language. Using the input method extension API, developers can write custom input functions and share scripts with Google Pinyin input method users to install and use.

A simple Lua script program can constitute a most basic input method expansion module. Here is "Hello,World!" Program example:

Helloworld.lua

Function HelloWorld () return "Hello,World!" End ime.register_command ("hw", "HelloWorld", "test")

This code consists of a custom Lua function and a line of ime.register_command function calls. The custom Lua function HelloWorld () simply returns a Lua string "Hello,World!", indicating that after the input method extension function is called, the candidate displayed to the end user is "Hello,World!". The ime.register_command function call registers the custom function as a command extension of the Google Pinyin input method. The first parameter "hw" indicates that the corresponding command of the command extension in the I extension mode is "hw", the second parameter indicates that the entry function corresponding to the command extension (the custom Lua function) is "HelloWorld", and the third parameter is the short description text displayed in the list of I extended mode commands.

After entering the above program using any text editor, save it to the computer with the Google Pinyin input method installed under the file name of helloworld.lua. Then, open the Google Pinyin input method options Settings window, on the "extension" page, click the "install expansion Pack" button, select the helloworld.lua saved in your computer (you can also from Windows Explorer, right-click the helloworld.lua file, select "install to Google Pinyin input method"). After installation, open the notepad program, switch to Google Pinyin input method, type "ihw", and the only candidate "Hello,World!" will appear in the candidate window of Google Pinyin input method.

In addition to explicitly activating the extension function with commands such as "ihw", the extension function can also be activated by specific content or specific candidate words entered by the user when using the pinyin input method. For example, add a line at the end of the above helloworld.lua:

Ime.register_trigger ("HelloWorld", "test", {"hello"}, {})

The purpose of this line is to register the function "HelloWorld" as an integrated extension of the Google Pinyin input method. The first parameter is the entry function "HelloWorld" corresponding to the extension, the second parameter is a short description text, the third parameter gives which user input string or strings you want to associate the extension to (in this case, the string "hello"), and the fourth parameter gives which specific candidate word or words you want to associate the extension to (here is an empty table, which means it is not associated).

Open the Google Pinyin input method options Settings window, on the "extension" page, use the "remove expansion Pack" button to delete the helloworld.lua you just installed, and then reinstall the updated helloworld.lua. Open the notepad program, switch to Google Pinyin input method, type "hello", in the candidate window of Google Pinyin input method, in addition to the usual prompts for Chinese and English candidate words, there will also appear the candidate "Hello,World!" returned by the integrated extension function.

In fact, the input method extension API provided by Google Pinyin input method can be used to develop a variety of different input experiences, for example, returning corresponding information content according to the parameters entered by the user, looking up the table to enter specific text information, completing the calculation of custom and even containing random variables and returning results in different forms, converting the text content that the user has just entered into another form, and so on. The default functions of mode I provided by Google Pinyin input method, including time and date format conversion, constellation checking, rolling dice, printing characters, etc., are some of the simplest examples.

Three different ways to expand

Google Pinyin input method extension API provides three ways to expand Pinyin input method: command extension, integration extension and converter extension.

Command extension: associate an entry function in a script with a two-letter-long custom command. When the user types I and then the command, the input method activates the extension function and then displays the candidate results returned by the extension function in the candidate list.

Command extensions apply to situations where users explicitly want to use specific input features in a particular scenario, and there are more candidates, or more complex. For example, users explicitly want to query and enter constellation information according to their birthdays.

Integration extension: associate an entry function in a script to a specific keyboard input string, or to a specific Chinese and English candidate. When the user uses the Pinyin input method, once the string entered by the user through the keyboard matches a specific string associated with the integration extension (which may include wildcards), or a candidate parsed by the Pinyin input method matches the specific string associated with the integration extension (which may contain wildcards), the input method activates the extension function and inserts the candidate result returned by the expansion function into the candidate list.

Integration extensions apply to situations where a small number of relevant candidates are inserted based on current input or candidate content without interfering with normal user input. For example, when users enter the "time" in Chinese, they may also want to enter the current time directly, so it is more convenient for the integration extension to integrate the current time returned by the extension function directly into the candidate list.

Converter extension: registers an entry function in a script as a specific converter. When the user opens the converter through the user interface of the input method (such as the function menu), each candidate generated by the input method is sent to the converter function as a parameter in turn, and after the operation, the result returned by the function will replace the content of the original candidate and be displayed in the corresponding position by the input method.

The converter extension must be opened actively by the user. Once enabled, it will be applied to all candidates. Therefore, the converter extension is suitable for situations where decorations, special effects are added to all candidates, or all candidates are transformed according to rules. For example, add asterisk modification to each word of the candidate or candidate, output the corresponding Unicode code of that word directly after each word of the candidate, change simplified Chinese characters into traditional Chinese characters, and so on.

The following table provides a simple comparison of different expansion methods:

Expansion mode command extension integration extension converter extension registration mode ime.register_command (...) ime.register_trigger (...) ime.register_converter (...) Scope of application users clearly want to use specific input functions in a particular scenario, and there are more candidates, or in more complex cases, according to the current input or candidates without hindering the normal input of the user, insert a small number of related candidates to add decorations, special effects, or to all candidates to change according to the rules, the application instance queries the constellation according to the birthday entered. When enumerating and entering a specific character to draw the "time" in Chinese, insert the current time in the candidate list; when the user enters "" in Chinese, insert the corresponding emoji in the candidate list to add an asterisk to each word of the candidate or candidate; directly output the corresponding Unicode code after each word of the candidate Change simplified Chinese characters into traditional Chinese characters the user enters a command with a length of I plus 2 characters, activate the corresponding command to expand the pinyin string entered by the user or when a candidate generated by the input method matches a specific string associated with the integration extension (which may contain wildcards), activate the corresponding integration extension user to open a specific converter from the user interface of the input method (such as function menu) and activate the corresponding converter extension

Register command extension

In the Lua script, the basic syntax for registering a command extension with the Google Pinyin input method is:

Ime.register_command (command_name, lua_function_name, description, leading, help)

Ime is a dedicated module for Lua scripts to interact with the input method kernel. Register_command is the function used to register the new I extension mode command extension with the Google Pinyin input method. The parameters of the function have the following meanings:

◆ command_name

A 2-character string must consist of two English letters (amurz). Defines the name of the command to register. If the newly registered command name is the same as a previously registered command name (case-insensitive when judging the duplicate name), the register_command function call fails and the new command extension cannot be registered in the input method.

◆ lua_function_name

String. Give the corresponding Lua entry function when this command runs in I extension mode. This must be an existing Lua function that takes one or zero arguments.

◆ description

String. A short description of the command. This description is displayed in the command selection interface in I expansion mode, briefly explaining the function of a command to the user. Do not use a short description that is too long, usually no more than 10 characters.

◆ leading [may be omitted]

String. When you select a candidate for this command, the shortcut key you can use can be one of the following three specific strings:

"digit": default. Means to use 1, 2, 3,. Such a number is used as a candidate selection key.

"alpha": means to use a, b, c,... Such a sequence of English letters serves as a candidate selection key.

"none": indicates that candidate selection keys are not used.

Note: by default, input methods use 1, 2, 3,. The numeric key is selected as the candidate key. However, when a command in I expansion mode wants to receive the numbers 1, 2, 3,. As your own parameter, to avoid conflicts, candidate selection keys in the "digit" mode cannot be used. Similarly, when a command wants to receive parameters that contain English letters, it cannot use "alpha" as the candidate selection key.

◆ help [may be omitted]

String. Help messages slightly longer than description, but generally no more than 50 words. When the user types "I" and a specific command name, this text message is displayed at the top right of the input method candidate window to prompt the user how to enter subsequent parameters.

The command entry function given by lua_function_name can take one or zero arguments, for example:

Function my_entry_function ()-- do some processing and return the result end

When the entry function receives a parameter, the input method passes to the entry function all the content that the user continues to enter after the I + two letter command name has been typed in the I extension mode as a string parameter. For example, if the user types "ihw123" successively, the name of the command activated by the user is "hw". When the input method calls the corresponding entry function of the command, it passes in the parameter "123" as a string. The entry function can operate on the parameters and return the corresponding results. For example:

Function my_entry_function (argument)

Converts the parameter argument to a number, calculates and returns its square root.

End

The prompt message description passed when registering the command extension is displayed when the user sees a list of commands in I extension mode to prompt the user of the function of the command. This string should be as short as possible (no more than 10 characters). The "dice roll", "print characters" and so on in the following figure are all description:

The prompt help passed when registering the command extension is displayed in the upper-right corner of the input method candidate window after the user has selected a particular command. This string can be slightly longer than description, but generally no more than 50 characters. For example, in the following figure, after the user selects the print character command "zf", the display "Please enter a sequence of letters or numbers, such as hello" is the content of help:

Registration Integration extension

In the Lua script, the basic syntax for registering an integration extension with Google Pinyin input method is:

Ime.register_trigger (lua_function_name, description, input_trigger_strings, candidate_trigger_strings)

Ime is a dedicated module for Lua scripts to interact with the input method kernel. Register_trigger is a function used to register new integration extensions with Google Pinyin input method. The parameters of the function have the following meanings:

◆ lua_function_name

String. The Lua entry function corresponding to the extension runtime is given. This must be an existing Lua function that takes an argument.

◆ description

String. A short description of an extended function that briefly describes the function of an extension to the user. Do not use a short description that is too long, usually no more than 10 characters.

◆ input_trigger_strings

A Lua list of strings containing zero or more specific strings consisting of English letters or wildcard characters. All the strings given here will match the user's input when the input method is running, and once the user's input is the same as a particular string given (or successfully matched using wildcards), the registered extension function will be called, and the candidate result returned by the extension function will be inserted into the list of candidates in the input method.

◆ candidate_trigger_strings

A Lua list of strings containing zero or more specific strings consisting of English, Chinese, numbers, and other displayable characters or wildcard characters *. All the strings given here will be matched with the candidates obtained by the input method when the input method is running, and once a candidate on the first page of the candidate list is the same as a given specific string (or successfully matched with a wildcard), the registered extension function will be called, and the candidate result returned by the extension function will be inserted into the candidate list of the input method.

About wildcard matching: strings in input_trigger_strings and candidate_trigger_strings can include the wildcard * at the beginning or end, indicating a prefix match or a suffix match. For example:

◆ abc*

Represents any string that matches a prefix of abc. For example, the string abc,abcd,abcde can be successfully matched.

◆ * abc

Represents any string that matches a suffix of abc. For example, the string abc,dabc,deabc can be successfully matched.

When registering for consolidation extensions with ime.register_trigger, be aware of the following:

◆ parameters input_trigger_strings and candidate_trigger_strings cannot be empty tables at the same time.

When activating the integration extension function, the ◆ input method will first match input_trigger_strings, and then match candidate_trigger_strings. When matching candidate_trigger_strings, attempts are made in the order of candidates obtained by the input method. For each input, once a match is found, only the candidate results returned by the extension function corresponding to the match are inserted, and no other matches are tried.

Although the ◆ extension function can return one or more results, for the integration extension, only the first candidate result is currently inserted into the candidate list of the input method.

◆ currently has a limit on the number of strings that can be registered through input_trigger_strings and candidate_trigger_strings in an integration extension, generally no more than 200.

◆ 's current integration extension matches only the candidates on the first page of the candidate list when it matches candidate_trigger_strings.

The entry function of the integration extension should generally receive a parameter. When the integration extension function is activated, the input method passes the string (either the user input or a specific candidate) that activates the integration extension function to the entry function as the only parameter. In this way, an integration extension function that registers multiple matching strings can know which character is activated by parameters when it is called. Of course, the entry function can simply ignore this parameter when it is not needed.

Register the converter extension

In the Lua script, the basic syntax for registering a converter extension with Google Pinyin input method is:

Ime.register_converter (lua_function_name, description)

Ime is a dedicated module for Lua scripts to interact with the input method kernel. Register_converter is a function used to register a new converter extension with Google Pinyin input method. The parameters of the function have the following meanings:

◆ lua_function_name

String. The Lua entry function corresponding to the extension runtime is given. This must be an existing Lua function that takes an argument.

◆ description

String. A short description of an extended function that briefly describes the function of an extension to the user. Do not use a short description that is too long, usually no more than 10 characters. For converter extensions, this description information is displayed to the user by the user interface of the input method in order to select a specific converter extension.

When the user opens the converter, the input method calls the Lua entry function corresponding to the converter with each candidate as a parameter in turn. That is, the Lua entry function is called once for each candidate.

The Lua entry function corresponding to the converter extension should return and return only one result, that is, the new candidate after the transformation of the original candidate. If you do not want to transform a candidate, you can return the value of the input parameter directly. If no results are returned, or if more than one result is returned, the input method considers that the extension function does not make any changes to the candidate.

After the converter extension is installed, the user can turn on or off a specific converter from the user interface of the input method. As shown in the following figure, turn on or off a specific converter from the function menu:

Return to candidate

In general, the entry function corresponding to the extension can return one or more candidate strings. The command extension displays all returned candidates, the integration extension currently inserts only the first candidate result into the list of candidates in the input method, and the converter extension accepts only entry functions that return a candidate string.

The returned parameter type can be a Lua string type, a Lua numeric type, or a Lua Boolean type. However, when these return values are returned to the input method kernel, they are converted into strings and displayed to the end user so that the user can select the input.

To return a unique candidate string, simply use the return statement to return a string, number, or Boolean value, for example:

Function TestString (argument)-do some processing return "a string" end function TestNumber (argument)-do some processing return 1234.56789 end function TestBoolean (argument)-do some processing return true end function TestAnotherBoolean (argument)-do some processing return 3 > 2 end

To return two or more results, simply return a list object of Lua, for example:

Function TestTable (argument) return {"abc", "def", "ghi", 123, true} end

Each element in a list can be an Lua string, a number, or a Boolean value, but the list cannot be nested. Each element in the list corresponds to a candidate in the candidate list that the input method displays to the user. The list returned by the above function is displayed in the input method as shown in the following figure:

In addition to single-line string results, the entry function of a command extension can return one or more multiline results that contain newline characters (it is not recommended to return multiline results in other extensions, such as integration extensions and converter extensions). The newline character is represented by "\ n" in the string constant of the Lua program. For example, the following function:

Function TestMultilines (argument) return "line 1".. "\ n".. "line 2".. "\ n".. "line 3" end

The multi-line result is displayed as "" in the candidate window of the input method, and when the user chooses to enter the candidate, the multi-line text is inserted into the user's current document, as shown below:

Return prompt information

For command extension, when the user has just entered the command name of the I extension mode and has not yet entered the command parameters, the entry function will be called, and the arguments passed to the entry function will be an empty string. At this time, the entry function can prompt the user to have several predefined candidate parameters by returning a prompt information table, and allow the user to select a predefined parameter directly in the candidate window of the input method. For example:

Function TestMetatables (argument) if # argument = = 0 then-if there is no parameter, the prompt information table is returned So that the user can directly select the predefined parameters "num" or "chs" return {{suggest = "num", help = "number 123"}, {suggest = "chs", help = "Chinese one, two, three"},} elseif argument = = "num" then-if the parameter is "num" (it may be typed by the user or directly selected by the user according to the prompt information table) Returns the numeric result return 123elseif argument = "chs" then-if the parameter is "chs" (either typed by the user or directly selected by the user based on the prompt table), the Chinese result return "one, two, three" end end is returned.

The returned prompt information table must conform to the above format, that is, each element in the table is a child table with two elements in each child table: the element of the key name suggset represents a candidate parameter to be prompted for user input, and the element of the key name help represents a short description of the parameter (no more than 10 characters). When the above entry function has no input parameters, the prompt window displayed by the input method is as follows:

At this time, users can try the up and down keys, the page flip button and the mouse to select the parameters they want to enter, or they can enter them directly with the keyboard.

Other extensions, such as integration extensions and converter extensions, do not support the prompt to select parameters, and they ignore such prompts returned by the entry function.

Use the ime module

In the Lua script written by the developer, in addition to calling the functions of each module provided by Lua itself (which is a subset of the functions provided by the standard Lua runtime environment), the code can also use the ime module to access the relevant information of the input method to achieve specific functions related to the input method.

For example, you can use the get_last_commit () function of the ime module to get the last string that the user typed, calculate it based on the contents of the string, and return a specific result. For example, the user types "Hello" and then uses a feature in the I extension mode that automatically returns "hello" when it sees "Hello". The code to implement this simple logic is as follows:

Function TestConvertHello () if ime.get_last_commit () = "Hello" then return "hello" else return "not found" end end

For more details, see the section on the ime module in the API reference section.

Error handling

The Lua entry function accepts parameters that cannot be processed, or when other internal errors occur, it can simply not return any parameters, or use the error () function built in the Lua language to report error messages to the input method, such as:

Function TestIgnoreError (argument) if # argument > 5 then return end return 123 end function TestReportError (argument) if # argument > 5 then error ("argument length > 5") end return 123 end

Error messages reported using the error () function are not displayed in the input method user interface, but you can use the console tool to test the script and view the error message. See the development and debugging section below.

Development and debugging

The input method extension script can be created using any source code / text editor. Before installing the input method expansion pack into the Google Pinyin input method, you can use the console tool to test the extension to ensure that the program functions correctly. Please download the console tool for developing and debugging the Google Pinyin input method extension script from the link below:

Download console tools (GooglePinyinApiConsole.exe) http://dl.google.com/pinyin/v2/GooglePinyinApiConsole.exe

When running the console tool GooglePinyinApiConsole.exe on the command line, the command line parameters that need to be given are one or more script file paths to be tested. The console tool will load all specified input method extension scripts and launch an interactive interface for developers to test and execute the extension mode. For example:

GooglePinyinApiConsole.exe ext1.lua ext2.lua ext3.lua

In the interactive interface of the console tool, type "help" to view help information:

I-lists all registered command extensions

I [COMMAND]-execute a command extension without parameters

I [COMMAND] [ARGUMENT]-have parameters to execute a command extension

G [TRIGGER_STRING]-attempt to activate a consolidation extension with a string parameter

C-lists all registered converter extensions

C [FUNCTION] [STRING]-Test the converter function

Quit-exit the console tool

Help-displays help information

When an error occurs during script loading or execution, the console tool prints and displays an error message. The error message includes the name of the script file where the error occurred, the error line number, the error content, and so on.

The console tool is not a real input method running environment, so some interfaces related to the specific functions of the input method, such as ime.get_last_commit (), cannot get real-time input method-related information in the scripts run on the console, and the return value of such functions is a simple fixed string, such as "test". The integration extension cannot insert the result into the candidate list of the input method as it does in the input method.

The following figure shows the use of the console tool to test each extension in the default IME expansion package:

About Lua language

At present, the Google Pinyin input method extension API only provides Lua as a development language. Lua is a small but powerful dynamic scripting language, which is widely used in the development of plug-ins or extended functions for applications such as online games. It is not difficult for a developer with experience in developing JavaScript, VBScript, or Python languages to learn the Lua language. Please refer to the following URL for various information about the Lua language:

Lua programming language

Lua programming language

In the input method environment, the input method extension installed by each user is an independent Lua language module, and each module runs in its own namespace. In other words, the symbols of the same name between different modules will not conflict, but different modules can not call each other. The user-installed input method extension can only call the built-in functions of Lua described in the API reference section and the input method-related functions provided by the ime module.

API referenc

UTF-8-encoded text files are recommended when input method extensions written in Lua are saved on disk. Text files may or may not contain BOM headers. When there is no BOM header, IME defaults to loading in UTF-8 encoding.

Input method extensions written in Lua can use the following built-in functions. In addition to the input method related functions provided by the ime module, these functions are a subset of the standard Lua runtime environment. Therefore, before porting an existing Lua program to an input method extension, make sure that the functions used by the program are within the scope of the following table.

The following functions that belong to the Lua standard operating environment only give a brief description of the functions. For more information on usage, please see the description of the Lua language standard function library.

Basic function

◆ assert (v [, message])

Assert. If the value of v is false (nil or false), an error is reported.

◆ error (message [, level])

Error reported.

◆ ipairs (t)

Iterator function. Used to iterate over the (sequence number, value) of the elements in the list.

◆ loadstring (string [, chunkname])

Load and execute the string.

◆ next (table [, index])

Used to traverse each element of the list.

◆ pairs (t)

Iterator function. Used to iterate over the (key, value) of the elements in the list.

◆ select (index,...)

Returns all parameters in the variable length parameter list that start after index.

◆ tonumber (e [, base])

Convert to a number.

◆ tostring (e)

Convert to a string.

◆ type (v)

Returns the type name of the parameter.

◆ unpack (list [, I [, j]])

Returns each element in the list.

String processing function

◆ string.byte (s [, I [, j]])

Returns the internal encoding of the character.

◆ string.char ()

Returns the string corresponding to the internal encoding.

◆ string.find (s, pattern [, init [, plain]])

String lookup.

◆ string.format (formatstring,)

String formatting.

◆ string.gmatch (s, pattern)

Iterator function. Used to iterate over all matches in a string.

◆ string.gsub (s, pattern, repl [, n])

Global replacement of strings.

◆ string.len (s)

Returns the string length.

◆ string.lower (s)

Convert to lowercase.

◆ string.match (s, pattern [, init])

String match.

◆ string.rep (s, n)

Repeat the string n times.

◆ string.reverse (s)

String reversal.

◆ string.sub (s, I [, j])

String substitution.

◆ string.upper (s)

Convert to uppercase.

Date and time function

◆ os.date ([format [, time]])

Returns the formatted date-time string.

◆ os.difftime (T2, T1)

Returns the number of seconds between the two times.

◆ os.time ([table])

Returns the current date, or the specified date.

Mathematical function

◆ math.abs (x)

absolute value.

◆ math.acos (x)

Inverse cosine.

◆ math.asin (x)

Arcsine.

◆ math.atan (x)

Anyway, cut.

◆ math.ceil (x)

Round it up.

◆ math.cos (x)

CoSine.

◆ math.cosh (x)

Hyperbolic cosine.

◆ math.deg (x)

Radian to angle.

◆ math.exp (x)

Calculate ex

◆ math.floor (x)

Round it down.

◆ math.fmod (x, y)

Floating point numbers are modeled.

◆ math.frexp (x)

Return m and e that make x = M2e valid

◆ math.ldexp (m, e)

Calculate M2e

◆ math.log (x)

Calculate the natural logarithm.

◆ math.log10 (x)

Calculate the commonly used logarithm.

◆ math.max (x,)

Seek the maximum value.

◆ math.min (x,)

Find the minimum.

◆ math.modf (x)

Returns the integer and decimal parts of a floating-point number.

◆ math.pi

Returns the value of pi.

◆ math.pow (x, y)

Calculate xy

◆ math.rad (x)

The angle turns to the Radian.

◆ math.random ([m [, n]])

Generate pseudorandom numbers.

◆ math.randomseed (x)

Sets the random number seed.

◆ math.sin (x)

Sine.

◆ math.sinh (x)

Hyperbolic sine.

◆ math.sqrt (x)

Square root.

◆ math.tan (x)

Tangent.

◆ math.tanh (x)

Hyperbolic tangent.

Table processing function

◆ table.concat (table [, sep [, I [, j])

Connect list elements.

◆ table.insert (table, [pos,] value)

Insert an element.

◆ table.maxn (table)

Returns the largest integer index number.

◆ table.remove (table [, pos])

Delete the element.

◆ table.sort (table [, comp])

Sort.

Input method related functions provided by ime module

Registration of input method module related functions

◆ ime.register_command (command_name, lua_function_name, description [, leading [, help]])

Register the command extension. For more information, see Registration Command extension.

◆ ime.register_trigger (lua_function_name, description, input_trigger_strings, candidate_trigger_strings)

Register the consolidation extension. For more information, see registering the Integration extension.

◆ ime.register_converter (lua_function_name, description)

Register the converter extension. For more information, see registering the converter extension.

Input method information correlation function

◆ ime.get_version ()

Returns the version number of the current input method as a string.

◆ ime.get_last_commit ()

Returns the last string entered by the user through the Google Pinyin input method.

Utility function

◆ ime.int_to_hex_string (value [, width])

Converts the integer value value to a string represented in hexadecimal. The optional parameter width specifies the minimum length of the resulting string, and when the minimum length is less than the minimum length, the high bit is filled with "0".

◆ ime.join_string (str_list, sep)

Concatenate all the strings in the str_list list into one large string and use sep as the concatenation character to return the result string.

◆ ime.parse_mapping (src_string, line_sep, key_value_sep, values_sep)

The string src_string is a mapping table represented as a string, with each row representing the mapping of a key to its value, the delimiter between lines is line_sep, the delimiter between each inline key and subsequent one or more values is key_value_sep, and the delimiter between multiple values is values_sep. Ime.parse_mapping parses strings in this format and converts them into lists that can be used directly by the Lua language. The format of the result list is {key1= {value1, value2,...}, key2= {value1, value2,...},...}. A typical application example of this tool function is to preset a mapping table in the form of a string in the input method expansion module that is easy to read and edit (such as the mapping of a Chinese character coding to the corresponding one or more Chinese characters), and then use this function to parse the mapping table in the expansion module so that the Lua code can query it quickly.

Sample code:

_ MAPPING_TABLE = [a, b, no, c from, wear, out]] _ MAPPING = ime.parse_mapping (_ MAPPING_TABLE, "\ n", "", ",") function Lookup (input) if _ map [input] then return _ map [input] else error ("Invalid argument") end end ime.register_command ("lp", "Lookup", "mapping lookup")

◆ ime.split_string (str, sep)

The string str is split into a set of strings based on the delimiter sep, and a list of these strings is returned.

◆ ime.trim_string (str)

Remove the white space characters on the left and right sides of the string str and return the result string.

◆ ime.trim_string_left (str)

Remove the white space character to the left of the string str and return the result string.

◆ ime.trim_string_right (str)

Remove the white space character to the right of the string str and return the result string.

◆ ime.utf8_to_utf16 (str)

Converts a UTF-8-encoded string to a UTF-16-encoded string, and the returned result string ends with "\ 0\ 0".

◆ ime.utf16_to_utf8 (str)

Converts a UTF-16-encoded string to a UTF-8-encoded string.

Thank you for your reading, the above is "Google Pinyin input method expansion API development method is what" the content, after the study of this article, I believe you on Google Pinyin input method expansion API development method is what this problem has a deeper understanding, the specific use of the need for you to practice verification. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report