Intelligent clipboard content processing method and system
By employing an intelligent clipboard content processing method, the issues of format compatibility, platform isolation, and error handling in clipboard tools have been resolved. This method enables automatic detection and conversion of multiple formats, supports cross-platform path conversion and various output modes, and enhances the practicality and security of clipboard tools.
Patent Information
- Application Number
- CN202511135401.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-14
- Publication Date
- 2025-11-28
AI Technical Summary
Existing clipboard tools suffer from poor format compatibility, platform isolation, limited output, and weak error handling. They cannot simultaneously handle text, HTML, images, and file lists, and path conversion between Windows and WSL environments requires manual operation.
This invention provides an intelligent clipboard content processing method, including content type detection, Base64 decoding, path conversion, and output control. It supports automatic detection and conversion of multiple formats, achieves seamless cross-platform integration, and provides standardized error codes and message feedback.
It achieves seamless processing of multiple formats, supports text, HTML, RTF, images and file lists, automatically completes Windows-WSL path conversion, provides multiple output modes, and provides standardized error feedback.
Smart Images

Figure CN121029447A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of cross-system data processing technology, specifically providing a smart clipboard content processing method and system. Background Technology
[0002] Existing clipboard tools have the following limitations:
[0003] (1) Poor format compatibility: It cannot process text, HTML, images and file lists at the same time;
[0004] (2) Platform isolation: Path conversion between Windows and WSL environments requires manual operation;
[0005] (3) Unique output: Lacks machine-readable structured output format;
[0006] (4) Weak error handling: lack of standardized error feedback mechanism. Summary of the Invention
[0007] This invention addresses the shortcomings of the prior art by providing a highly practical intelligent clipboard content processing method.
[0008] A further technical objective of this invention is to provide a reasonably designed, safe, and applicable intelligent clipboard content processing system.
[0009] The technical solution adopted by this invention to solve its technical problem is:
[0010] A method for processing intelligent clipboard content includes the following steps:
[0011] S1. Content type detection;
[0012] S2 and Base64 decoding;
[0013] S3, Path Conversion;
[0014] S4, Output Control.
[0015] Furthermore, in step S1, an array `formats` is defined to list all supported formats, in descending order of priority; the array is traversed, and each format is checked in turn to see if the current format exists in the context `ctx`, i.e., whether it is available.
[0016] If the format is available, process_format is called to process that format and the result is returned immediately. If none of the previous formats (Html / Rtf / Image / Files) are available, the Text format will be tried last.
[0017] Furthermore, in step S2, a function is defined that receives the data_url and returns a Result. <rustimagedata>Compile the regular expression to match data:image / <type>;base64, <data>A formatted Data URL;
[0018] The code matches the image type and captures the Base64 data. If the regular expression compilation fails, it returns an error directly.
[0019] The input data_url is matched using regular expressions, and the first capture group, i.e. the Base64 data part, is extracted using and_then+c.get(1). If the match fails, an error is returned.
[0020] Use a Base64 standard decoder to decode the string into binary bytes; if decoding fails, return an error.
[0021] Call the image library's load_from_memory function to load an image from binary data, and convert errors in the image library into the function's error type.
[0022] Furthermore, in step S3, a function convert_path is defined that accepts two parameters: path:String and format:PathFmt;
[0023] path: String: The path string to be converted;
[0024] format:PathFmt: Target path format;
[0025] Returns the converted path string on success and an error on failure. Different processing logic is matched according to the value of format. If the target format is Windows, the original path is returned directly. If the operation is successful, it is wrapped as a Result type.
[0026] If the target format is WSL, call the windows_to_wsl(&path) function to convert the Windows path to a WSL path;
[0027] If windows_to_wsl returns an error, the error message is wrapped into a more user-friendly string using map_err, which converts the string to the error type defined in the function.
[0028] Furthermore, in step S4, different output logic is selected according to the value of output_format. If the format is JSON, serialize the output object into a JSON string by calling seriale_json::to_string(&output) and print the JSON string. If serialization fails, an error is returned directly. If the format is PLAIN plain text, print the clip_type field of output and further process it according to the different payloads.
[0029] If the payload is of type Single(s), print the value s directly. If the payload is of type Multiple(v), iterate through the collection v and print each element line by line.
[0030] If the payload is None, print a warning message to standard error using eprintln!.
[0031] An intelligent clipboard content processing system first performs content type detection, then uses Base64 decoding to perform path conversion, and finally outputs control.
[0032] Furthermore, when performing content type detection, an array `formats` is defined to list all supported formats, in descending order of priority; the array is traversed, and each format is checked in turn to see if the current format exists in the context `ctx`, i.e., whether it is available;
[0033] If the format is available, process_format is called to process that format and the result is returned immediately. If none of the previous formats (Html / Rtf / Image / Files) are available, the Text format will be tried last.
[0034] Furthermore, when performing Base64 decoding, define a function that receives the data_url and returns a Result. <rustimagedata>Compile the regular expression to match data:image / <type>;base64, <data>A formatted Data URL;
[0035] The code matches the image type and captures the Base64 data. If the regular expression compilation fails, it returns an error directly.
[0036] The input data_url is matched using regular expressions, and the first capture group, i.e. the Base64 data part, is extracted using and_then+c.get(1). If the match fails, an error is returned.
[0037] Use a Base64 standard decoder to decode the string into binary bytes; if decoding fails, return an error.
[0038] Call the image library's load_from_memory function to load an image from binary data, and convert errors in the image library into the function's error type.
[0039] Furthermore, when performing path conversion, a function `convert_path` is defined that accepts two parameters: `path:String` and `format:PathFmt`.
[0040] path: String: The path string to be converted;
[0041] format:PathFmt: Target path format;
[0042] Returns the converted path string on success and an error on failure. Different processing logic is matched according to the value of format. If the target format is Windows, the original path is returned directly. If the operation is successful, it is wrapped as a Result type.
[0043] If the target format is WSL, call the windows_to_wsl(&path) function to convert the Windows path to a WSL path;
[0044] If windows_to_wsl returns an error, the error message is wrapped into a more user-friendly string using map_err, which converts the string to the error type defined in the function.
[0045] Furthermore, when controlling the output, different output logic is selected according to the value of output_format. If the format is JSON, serialize the output object into a JSON string by calling serialize_json::to_string(&output) and print the JSON string. If serialization fails, an error is returned directly.
[0046] If the format is PLAIN plain text, print the output clip_type field and process it further according to the different payloads;
[0047] If the payload is of type Single(s), print the value s directly. If the payload is of type Multiple(v), iterate through the collection v and print each element line by line.
[0048] If the payload is None, print a warning message to standard error using eprintln!.
[0049] Compared with the prior art, the intelligent clipboard content processing method and system of the present invention have the following outstanding advantages:
[0050] This invention supports five major data types: text, HTML, RTF, image, and file list. It enables seamless cross-platform integration, automatic Windows-WSL path conversion, and combines three configuration dimensions to create eight output modes, providing standardized error codes and message feedback. Attached Figure Description
[0051] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0052] Figure 1 This is a flowchart illustrating a smart clipboard content processing method;
[0053] Figure 2 This is a schematic diagram of the initialization process of an intelligent clipboard content processing method. Detailed Implementation
[0054] To enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to specific embodiments. Obviously, the described embodiments are merely 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.
[0055] The following is a preferred embodiment:
[0056] like Figure 1-2 As shown, a smart clipboard content processing method in this embodiment includes the following steps:
[0057] S1. Content type detection;
[0058] Define an array `formats` that lists all supported formats, ranked from highest to lowest priority (Html highest, Text lowest). Iterate through the array, checking each format in turn. Check if the current format exists in the context `ctx` (i.e., whether it is available). If the format is available, call `process_format` to process it and return the result immediately (terminating the loop). If none of the previous formats (Html / Rtf / Image / Files) are available, finally attempt to process the Text format (assuming `ctx.has(ContentFormat::Text)` returns true by default or as a fallback option).
[0059] The code is as follows:
[0060] let formats = [
[0061] ContentFormat::Html,
[0062] ContentFormat::Rtf,
[0063] ContentFormat::Image
[0064] ContentFormat::Files,
[0065] ContentFormat::Text / / fallback handling ];
[0067] for format in formats{
[0068] if ctx.has(format){
[0069] return process_format(format).
[0070] S2 and Base64 decoding;
[0071] Define a function that takes a data_url (string reference) and returns a Result. <rustimagedata>(Possible successful image data or errors); Compile regular expressions to match data:image / <type>;base64, <data>Data URL in the specified format.
[0072] Match image types (such as png, jpeg), capture the Base64 data portion, and return an error directly if the regular expression compilation fails (such as a syntax error).
[0073] The input data_url is matched using regular expressions, and the first capture group (i.e., the Base64 data part) is extracted using and_then+c.get(1); if the match fails (e.g., the URL is in the wrong format), an error is returned.
[0074] Use a Base64 standard decoder to decode the string into binary bytes (Vec). <u8>If decoding fails (e.g., non-Base64 data), an error is returned. The image library's `load_from_memory` method is called to load the image from binary data, and `map_err(|e|e.into())` converts the image library's error to the function's error type (e.g., a custom error type).
[0075] The code is as follows:
[0076] fn data_url_to_image(data_url:&str)->Result <rustimagedata>{
[0077] let re=Regex::new(r"^data:image / [^;]+;base64,(.*)$")? ;
[0078] let base64_data=re.captures(data_url)
[0079] .and_then(|c|c.get(1))
[0080] .ok_or("Invalid data URL")? ;
[0081] let bytes =
[0082] general_purpose::STANDARD.decode(base64_data.as_str())? ;
[0083] image::load_from_memory(&bytes).map_err(|e|e.into()).
[0084] S3, Path Conversion;
[0085] Define a function convert_path that takes two arguments: path: String and format: PathFmt;
[0086] path: String: The path string to be converted.
[0087] format:PathFmt: Target path format (enumeration type, may be Windows or WSL).
[0088] Returns the converted path string on success, and returns an error on failure.
[0089] Different processing logic is matched according to the value of format. If the target format is Windows, the original path path is returned directly (no conversion required). Ok(path) indicates that the operation was successful and is wrapped as a Result type.
[0090] If the target format is WSL, the `windows_to_wsl(&path)` function is called to convert the Windows path to a WSL path, with `&path` passing a reference to the path (to avoid ownership transfer); if `windows_to_wsl` returns an error (Err(e)), the error message is wrapped into a more user-friendly string using `map_err`, and `format! ("Path conversion failed:{:?}",e)` generates a message similar to "Path conversion failed:<original error>".
[0091] .into() converts the string to the error type defined by the function (which might be Box).<dyn Error> Or a custom error type).
[0092] S4, Output Control;
[0093] Different output logic is selected based on the value of output_format (which may be JSON or PLAIN). If the format is JSON, serialize the output object into a JSON string by calling serial_json::to_string(&output).
[0094] `println!("{}",...)` prints a JSON string. If serialization fails (e.g., the output contains unserializable data), it returns an error directly. If the format is PLAIN (plain text), it prints the `clip_type` field of the output (which may be descriptive text).
[0095] Further processing is performed based on the different cases of the payload. If the payload is of type Single(s) (a single value), the value s is printed directly. If the payload is of type Multiple(v) (a collection of multiple values), the collection v is traversed and each element is printed line by line.
[0096] If the payload is None, print the warning message "No payload" to standard error (stderr) using eprintln!.
[0097] Among them, a three-level configuration system;
[0098] Output format control:
[0099] enum OutPutFmt{JSON,PLAIN} / / Output format enumeration;
[0100] Content processing mode:
[0101] enum ClipContentFmt{File,String} / / File path or original content;
[0102] Path format selection:
[0103] enum PathFmt{Windows,WSL} / / Native path or WSL path;
[0104] Intelligent content processing in progress;
[0105] Deep HTML analysis;
[0106] let regex = Regex::new(r#" <img\s+src="([^"]+)""#);
[0107] if let Some(caps)=regex.captures(html){
[0108] process_image(caps[1].as_str()); / / Resource separation
[0109] Base64 instant decoding;
[0110] fn data_url_to_image(data_url:&str)->Result <rustimagedata>{
[0111] let base64_data = extract_base64(data_url);
[0112] image::load_from_memory(&base64::decode(base64_data)?)
[0113] Cross-platform path conversion;
[0114] match path_format {
[0115] PathFmt::Windows => output.payload = Some(full_path),
[0116] PathFmt::WSL => output.payload = Some(windows_to_wsl(full_path)?),
[0117] In a polymorphic output protocol;
[0118] Structured JSON output;
[0119] "error": false,
[0120] "clip_type": "image",
[0121] "payload": "C:\\Temp\\clip-tool\\20240520120000.png"
[0122] Automation-friendly text;
[0123] image
[0124] C:\Temp\clip-tool\20240520120000.png
[0125] Batch file support;
[0126] files
[0127] C:\Path\to\file1.txt
[0128] files
[0129] C:\Path\to\file2.jpg.
[0130] In application scenarios:
[0131] (1) Document automation;
[0132] Copy Word graphic content, clip-tool--content file--path wsl-oplain, output html,
[0133] / mnt / c / Temp / clip-tool / 20250620120001_attach.html;
[0134] Output WSL path for Pandoc processing,
[0135] pandoc / mnt / c / Temp / clip-tool / 20250620120001_attach.html html;
[0136] (2) CI / CD pipeline integration;
[0137] Specify the script to use the Bash interpreter to execute, call the Windows tool clip-tool.exe, pass the parameter -c file -o json (may be to get the file path from the clipboard and output in JSON format), save the output result to the variable JSON. Use jq to parse the error field value in the JSON variable, if error is false (indicates that the operation is successful), then execute the subsequent logic.
[0138] Extract the payload field from JSON (may be a Windows path), -r indicates output raw string (remove quotes), convert the Windows path to WSL (Linux subsystem) path, save the converted WSL path to the variable WSL_PATH.
[0139] Use the docker cp command to copy the file corresponding to WSL_PATH to the / data directory of the Docker container named container, end the if condition block.
[0140] The code is as follows:
[0141] #! / bin / bash
[0142] JSON=$(clip-tool.exe -c file -o json)
[0143] if [$(echo $JSON | jq '.error') == 'false']; then
[0144] WSL_PATH=$(wslpath-u $(echo $JSON|jq-r'.payload'))
[0145] docker cp $WSL_PATH container: / data
[0146] fi
[0147] (3) Cross-platform document processing;
[0148] User copy Word document image text, execute: clip-tool-c file-p wsl-oplain, output: files
[0149] / mnt / c / Temp / clip-tool / 20250620120002_attach.png, directly in WSL with vim or edit the image path.
[0150] Base64 image storage, copy base64 image <img src="data:image png;base64,iVBORw0..."> , execute: clip-tool-c file-p windows-o plain;
[0151] Output: files
[0152] c:\Temp\clip-tool\20250620120002_attach.png;
[0153] Open or use the image.
[0154] Based on the above method, the intelligent clipboard content processing system in this embodiment first detects the content type, then uses Base64 decoding, performs path conversion, and finally outputs control.
[0155] Wherein, when detecting the content type, define an array formats, list all supported formats, priority from high to low; traverse the array, check each format in turn, check if the current format format exists in the context ctx, that is, whether it is available;
[0156] If the format is available, call process_format to process the format and return the result immediately, if the previous formats (Html / Rtf / Image / Files) are not available, the Text format will be processed at last.
[0157] When Base64 decoding, define a function that receives data_url and returns Result <rustimagedata>, compile regular expression, match against data:image / <type>; base64, <data>Data URL in the format;
[0158] Match the picture type and capture the Base64 data part, and return an error directly if the regular compilation fails;
[0159] Match the input data_url with regular expressions, and extract the first capture group, which is the Base64 data part, using and_then + c.get(1). If the match fails, return an error;
[0160] Decode the string into binary bytes using the Base64 standard decoder, and return an error if the decoding fails;
[0161] Call the load_from_memory function of the image library to load the image from binary data, and convert the image library error into the error type of the function.
[0162] When converting paths, define a function convert_path that receives two parameters path:String and format:PathFmt;
[0163] path:String: The path string to be converted;
[0164] format:PathFmt: The target path format;
[0165] Return the converted path string on success, or return an error. According to the value of format, match different processing logic. If the target format is Windows, directly return the original path path, and the operation is successful. Wrap it in the Result type;
[0166] If the target format is WSL, call the windows_to_wsl(&path) function to convert the Windows path to WSL path;
[0167] If windows_to_wsl returns an error, wrap the error information into a more friendly string using map_err, and convert the string into the error type defined by the function.
[0168] When output control, according to the value of output_format, select different output logic, if the format is JSON, call serde_json::to_string(&output) to serialize the output object into a JSON string, and print the JSON string. If the serialization fails, return an error directly;
[0169] If the format is PLAIN text, print the clip_type field of the output, and further process according to the different cases of the payload;
[0170] If the payload is of type Single (s), directly print the value s, and if the payload is of type Multiple (v), iterate over the set v and print each element on a separate line;
[0171] If the payload is None, print a warning message to the standard error via eprintln!
[0172] The above specific embodiments are only specific cases of the present application, and the patent protection scope of the present application includes but is not limited to the above specific embodiments. Any technical solution meeting the above specific embodiments of the present application and any appropriate changes or replacements made by those skilled in the art to the technical solution shall fall within the patent protection scope of the present application.
[0173] Although the embodiments of the present application have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and variations can be made to the embodiments without departing from the principles and spirit of the present application, and the scope of the present application is defined by the appended claims and their equivalents.< / data> < / type> < / rustimagedata> < / rustimagedata> < / rustimagedata> < / data> < / type> < / rustimagedata> < / data> < / type> < / rustimagedata> < / data> < / type> < / rustimagedata>
Claims
1. A method for intelligent clipboard content processing, characterized in that, It has the following steps: S1. Content type detection; S2 and Base64 decoding; S3, Path Conversion; S4, Output Control.
2. The intelligent clipboard content processing method according to claim 1, characterized in that, In step S1, an array `formats` is defined to list all supported formats, in descending order of priority. The array is then traversed, and each format is checked in turn to see if the current format exists in the context `ctx`, i.e., whether it is available. If the format is available, process_format is called to process that format and the result is returned immediately. If none of the previous formats (Html / Rtf / Image / Files) are available, the Text format will be tried last.
3. The intelligent clipboard content processing method according to claim 2, characterized in that, In step S2, a function is defined that receives the data_url and returns a Result. <rustimagedata>Compile the regular expression to match data:image / <type>;base64, <data> A formatted Data URL;< / data> < / type> < / rustimagedata> The code matches the image type and captures the Base64 data. If the regular expression compilation fails, it returns an error directly. The input data_url is matched using regular expressions, and the first capture group, i.e. the Base64 data part, is extracted using and_then+c.get(1). If the match fails, an error is returned. Use a Base64 standard decoder to decode the string into binary bytes; if decoding fails, return an error. Call the image library's load_from_memory function to load an image from binary data, and convert errors in the image library into the function's error type.
4. The intelligent clipboard content processing method according to claim 3, characterized in that, In step S3, a function convert_path is defined, which accepts two parameters: path:String and format:PathFmt; path: String: The path string to be converted; format:PathFmt: Target path format; Returns the converted path string on success and an error on failure. Different processing logic is matched according to the value of format. If the target format is Windows, the original path is returned directly. If the operation is successful, it is wrapped as a Result type. If the target format is WSL, call the windows_to_wsl(&path) function to convert the Windows path to a WSL path; If windows_to_wsl returns an error, the error message is wrapped into a more user-friendly string using map_err, which converts the string to the error type defined in the function.
5. The intelligent clipboard content processing method according to claim 4, characterized in that, In step S4, different output logic is selected according to the value of output_format. If the format is JSON, serialize the output object into a JSON string by calling seriale_json::to_string(&output) and print the JSON string. If serialization fails, an error is returned directly. If the format is PLAIN plain text, print the clip_type field of output and further process it according to the different payloads. If the payload is of type Single(s), print the value s directly. If the payload is of type Multiple(v), iterate through the collection v and print each element line by line. If the payload is None, print a warning message to standard error using eprintln!.
6. A smart clipboard content processing system, characterized in that, First, perform content type detection, then use Base64 decoding, perform path conversion, and finally output control.
7. The intelligent clipboard content processing system according to claim 6, characterized in that, When performing content type detection, define an array `formats` to list all supported formats, in descending order of priority; iterate through the array, check each format in turn, and check whether the current format exists in the context `ctx`, i.e., whether it is available; If the format is available, process_format is called to process that format and the result is returned immediately. If none of the previous formats (Html / Rtf / Image / Files) are available, the Text format will be tried last.
8. The intelligent clipboard content processing system according to claim 7, characterized in that, When performing Base64 decoding, define a function that receives the data_url and returns a Result. <rustimagedata>Compile the regular expression to match data:image / <type>;base64, <data> A formatted Data URL;< / data> < / type> < / rustimagedata> The code matches the image type and captures the Base64 data. If the regular expression compilation fails, it returns an error directly. The input data_url is matched using regular expressions, and the first capture group, i.e. the Base64 data part, is extracted using and_then+c.get(1). If the match fails, an error is returned. Use a Base64 standard decoder to decode the string into binary bytes; if decoding fails, return an error. Call the image library's load_from_memory function to load an image from binary data, and convert errors in the image library into the function's error type.
9. The intelligent clipboard content processing system according to claim 8, characterized in that, When performing path conversion, define a function convert_path that accepts two parameters: path:String and format:PathFmt; path: String: The path string to be converted; format:PathFmt: Target path format; Returns the converted path string on success and an error on failure. Different processing logic is matched according to the value of format. If the target format is Windows, the original path is returned directly. If the operation is successful, it is wrapped as a Result type. If the target format is WSL, call the windows_to_wsl(&path) function to convert the Windows path to a WSL path; If windows_to_wsl returns an error, the error message is wrapped into a more user-friendly string using map_err, which converts the string to the error type defined in the function.
10. The intelligent clipboard content processing system according to claim 9, characterized in that, When performing output control, different output logic is selected according to the value of output_format. If the format is JSON, serialize the output object into a JSON string by calling serialize_json::to_string(&output) and print the JSON string. If serialization fails, an error is returned directly. If the format is PLAIN plain text, print the output clip_type field and process it further according to the different payloads; If the payload is of type Single(s), print the value s directly. If the payload is of type Multiple(v), iterate through the collection v and print each element line by line. If the payload is None, print a warning message to standard error using eprintln!.