Code locking method and device, equipment, program product and storage medium

By judging and updating the code lines within the locked range, the problem of chaotic locking state caused by changes in the position of the code line is solved, ensuring the consistency and security of the locking state of the code line.

CN120848948APending Publication Date: 2025-10-28BEIJING SIMING QICHUANG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510983782.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-16
Publication Date
2025-10-28

AI Technical Summary

Technical Problem

In the prior art, a problem arises where a change in the line of code causes the actual line of code corresponding to a specified line number to no longer be the originally locked line of code, resulting in the original locked line of code no longer being locked, while a line of code that should not be locked is incorrectly configured to be locked.

Method used

By determining whether the target line of code is a locked line of code, the locking interval is determined using a locking identifier. If the target line of code is a locked line of code, no editing operation is performed. After an editing operation, the locking interval is redefined and the preset set of locked line numbers is updated to ensure that the lines of code within the locking interval are always uneditable.

Benefits of technology

It effectively maintains the uneditable state of code lines within the locked area, avoids confusion in the locked state caused by changes in the position of code lines, and ensures the accuracy and security of locked code lines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120848948A_ABST
    Figure CN120848948A_ABST
Patent Text Reader

Abstract

The invention provides a code locking method and device, equipment, a program product and a storage medium, and the method comprises the steps: responding to an editing instruction for a target code line, and judging whether the target code line is a locking code line or not; under the condition that the target code line is not the locking code line, editing operation corresponding to the editing instruction is executed for the target code line; under the condition that the target code line is the locked code line, not executing editing operation corresponding to the editing instruction; the locking code line is a code line which exists in a target code file and is located in a locking interval; a start code line and an end code line of the locking interval each comprise a locking identifier existing in an annotation mode, and the locking interval is determined according to the locking identifiers. In this way, under the condition that the position of the code line in the target code file is changed, the state that the original locked code line cannot be edited can be kept.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and more specifically, to a code locking method, apparatus, device, program product, and storage medium. Background Technology

[0002] In code editors, it is often necessary to restrict users' editing permissions on preset code to ensure the integrity and security of core code.

[0003] Existing technology typically uses a specified line number to lock the corresponding line of code, making it uneditable. However, when a user inserts or deletes a line of code, the line number of the line following the insertion or deletion point changes. If the specified line number corresponds to a line after the insertion or deletion point, the actual line number corresponding to that line number changes due to the insertion or deletion operation. This results in the specified line number no longer being the originally locked line, making it impossible to maintain the original locked state. Consequently, lines that shouldn't be locked are incorrectly configured as locked. Summary of the Invention

[0004] The purpose of this application is to provide a code locking method, apparatus, device, program product, and storage medium to solve the problem in the related art where, due to changes in the code line position, the actual code line corresponding to the specified code line number is no longer the originally set locked code line, resulting in the originally set locked code line no longer being in a locked state, while code lines that should not be in a locked state are incorrectly configured to be in a locked state.

[0005] In a first aspect, embodiments of this application provide a code locking method, including: In response to an editing instruction targeting a line of code, determine whether the target line of code is a locked line of code; If the target code line is not the locked code line, perform the editing operation corresponding to the editing instruction on the target code line; If the target code line is the locked line, then the editing operation corresponding to the editing instruction will not be executed; The locked code line is a code line that exists in the target code file and is located within the locked interval; the starting and ending code lines of the locked interval both include a locked identifier that exists as a comment, and the locked interval is determined based on the locked identifier.

[0006] In the above implementation, the locked interval is determined based on the locking identifier. Since the locking identifier exists as a comment in the starting and ending lines of the locked interval, its position changes whenever the line containing the locking identifier changes within the target file. Therefore, regardless of the position of the line containing the locking identifier, the locked interval determined by the identifier remains the same. Thus, when determining whether a target line is locked, the same locked interval can always be used. Furthermore, if the target line is locked, no editing operation corresponding to the editing command is performed, thereby maintaining the uneditable state of the lines within the locked interval—that is, maintaining the original uneditable state of the locked lines. This solves the problem where a change in line position causes the actual line corresponding to a specified line number to no longer be the originally defined locked line, resulting in the inability to maintain the original locked state of the locked lines, while lines that should not be locked are incorrectly configured as locked.

[0007] Further, determining whether the target code line is a locked code line includes: Determine whether the line number of the target code line is within a preset locked line number set; the preset locked line number set includes the line numbers of all code lines within the locked interval; the line numbers in the preset locked line number set change as the line numbers of the code lines within the locked interval change; If the line number of the target code line is within the preset set of locked line numbers, then the target code line is determined to be the locked code line. If the line number of the target code line is not within the preset set of locked line numbers, the target code line is not the locked code line.

[0008] In the above implementation, since the preset locked line number set includes the line numbers of all code lines within the locked interval, and each line number in the target code file is unique, it is possible to reliably determine whether the target code line is within the locked interval by checking if its line number is within the preset locked line number set. Furthermore, since the line numbers in the preset locked line number set can change as the line numbers of code lines within the locked interval change, even if the line numbers of code lines within the locked interval change, it is still possible to determine whether the target code line is within the locked interval using the updated preset locked line number set. Moreover, when the target code line is a locked line (i.e., within the locked interval), the editing operation corresponding to the editing command is not executed, thus maintaining the uneditable state of the code lines within the locked interval. This solves the problem that when the code line position changes, the actual code line corresponding to the specified line number is no longer the originally set locked line, resulting in the inability to maintain the original locked state of the locked line, while code lines that should not be locked are incorrectly configured as locked.

[0009] Furthermore, if the target code line is not the locked code line, after performing the editing operation corresponding to the editing instruction on the target code line, the method further includes: The locking interval is redefined based on the locking identifier; The line numbers in the preset locked line number set are updated based on the line numbers of the code lines within the locked interval.

[0010] In the above implementation process, performing the editing operation corresponding to the editing instruction on the target code line may cause the position of the locked interval in the target code file to change, thereby changing the line number of the code line within the locked interval. Therefore, after performing the editing operation corresponding to the editing instruction on the target code line, the locked interval can be redefined based on the locking identifier to update the locked interval in a timely manner if its position changes. Simultaneously, since the line numbers in the preset locked line number set can be updated based on the line numbers of the code lines within the locked interval, the line numbers in the preset locked line number set can also be updated in a timely manner if the position of the locked interval changes. Thus, when the position of the locked interval changes, it can be determined whether the target code line is within the locked interval whose position has changed by checking if its line number is within the updated preset locked line number set. If the target code line is within the locked interval whose position has changed, the editing operation corresponding to the editing instruction is not performed, thereby maintaining the uneditable state of the code lines within the locked interval. This solves the problem that when the line of code changes, the actual line of code corresponding to the specified line number is no longer the originally set locked line of code, which leads to the inability to maintain the original locked line of code being in a locked state, while the line of code that should not be locked is incorrectly configured to be locked.

[0011] Furthermore, if the target code line is not the locked code line, after performing the editing operation corresponding to the editing instruction on the target code line, the method further includes: The locking interval is redefined based on the locking identifier; If the line number of a line of code within the locked interval changes, the line numbers in the preset locked line number set are updated according to the line numbers of the line of code within the locked interval.

[0012] In the above implementation process, the position of the locked interval in the target code file may change when the editing operation corresponding to the editing instruction is performed on the target code line. Therefore, after performing the editing operation corresponding to the editing instruction on the target code line, the locked interval can be redefined based on the locking identifier to update the locked interval in a timely manner if its position changes. Simultaneously, since the preset locked line number set includes the line numbers of all code lines within the locked interval, the line numbers in the preset locked line number set are updated when the line numbers within the locked interval change, ensuring that the line numbers in the preset locked line number set are also updated in a timely manner if the position of the locked interval in the target code file changes. Thus, when the position of the locked interval changes, it can be determined whether the target code line is within the locked interval whose position has changed by checking if its line number is within the updated preset locked line number set. If the target code line is within the locked interval whose position has changed, the editing operation corresponding to the editing instruction is not performed, thereby maintaining the uneditable state of the code lines within the locked interval. This solves the problem that when the line of code changes, the actual line of code corresponding to the specified line number is no longer the originally set locked line of code, which leads to the inability to maintain the original locked line of code being in a locked state, while the line of code that should not be locked is incorrectly configured to be locked.

[0013] Further, re-determining the locking interval based on the locking identifier includes: In the case that the editing operation is a line addition or line deletion operation, the locking interval is re-determined based on the locking identifier.

[0014] In the above implementation process, performing an editing operation corresponding to an editing instruction on a target code line may or may not change the number of code lines in the target code file. Only when the number of code lines changes will the position of the locked interval change. If the number of code lines does not change, it can be directly determined that the position of the locked interval has not changed. Therefore, the locked interval is only re-determined based on the locking identifier when the editing operation is a code line addition or deletion operation. This reduces the need to re-determine the locked interval when its position has not changed, thereby reducing the consumption of processor resources.

[0015] Furthermore, the locking identifier includes a start locking identifier and an end locking identifier. Re-determining the locking interval based on the locking identifier includes: taking the code line containing the start locking identifier as the starting code line of the locking interval and taking the code line containing the end locking identifier as the ending code line of the locking interval to obtain the locking interval.

[0016] In the above implementation process, by taking the code line where the start lock character is located as the starting code line of the locked interval and the code line where the end lock character is located as the ending code line of the locked interval, the boundary value of the locked interval can be accurately determined, thereby accurately determining the locked interval.

[0017] Further, the locking interval is obtained by taking the line containing the start lock character as the starting line of the locking interval and the line containing the end lock character as the ending line of the locking interval, including: Iterate through each line of code in the target code file; When the first candidate starting line of code is encountered during traversal, the first candidate starting line of code is determined as the starting line of the locked interval; the candidate starting line of code is the line of code that includes a starting lock symbol; the first candidate starting line of code is either the line of code that has no other candidate starting line of code preceding it, or the line of code that is the closest candidate ending line of code preceding it and includes a lock identifier; the candidate ending line of code includes a ending lock symbol. When traversing to the last candidate termination code line, the last candidate termination code line is determined as the termination code line of the locked interval; wherein, the candidate termination code line is a code line that includes a termination lock symbol; the last candidate termination code line is either a code line that has no other candidate termination code lines after it, or a code line that is the closest candidate starting code line after it that includes a lock identifier.

[0018] In the above implementation, by traversing the lines of code in the target code file, when the first candidate starting line is encountered, it is determined as the starting line of the locked interval. This is because the first candidate starting line is either a line of code preceding which there are no other candidate starting lines, or the line preceding which is the nearest line containing the lock identifier is a candidate ending line. Therefore, when there are multiple candidate starting lines in the target code file, and no candidate ending lines exist between them, the first candidate starting line can be used as the starting line of the locked interval.

[0019] Simultaneously, upon reaching the last candidate terminating line of code, this line is determined as the terminating line of the locked interval. This is because the last candidate terminating line is either a line of code following which there are no other candidate terminating lines, or the line of code following which is the nearest candidate starting line and includes the lock identifier. Therefore, when multiple candidate terminating lines exist in the object code file, and there are no candidate starting lines among them, the last candidate terminating line can be used as the terminating line of the locked interval.

[0020] In this way, if a user accidentally sets multiple start lock characters and / or end lock characters, it can be guaranteed that the lock range determined by the start lock character and end lock character will necessarily include the area that the user wants to lock, thereby reducing the risk that the area that actually needs to be locked will not be successfully locked.

[0021] Furthermore, the locking identifier further includes a single-line locking character; re-determining the locking interval based on the locking identifier includes: The single-line locked line with the single-line locking symbol is determined as the locked interval.

[0022] In the above implementation process, the position of the single-line lock character is determined, that is, the single-line lock line containing the single-line lock character is identified, and the single-line lock line containing the single-line lock character is defined as the lock interval. This allows for accurate determination of the lock interval based on the position of the single-line lock character in the object code file.

[0023] Furthermore, code locking methods also include: If a line of code has both a single-line lock character and a start lock character, or both a single-line lock character and a stop lock character, then the line of code is determined to be a single-line lock line; no line of code in the target code file can be both a single-line lock line and an alternative start line, nor can it be both a single-line lock line and an alternative stop line.

[0024] In the above implementation, since single-line lock identifiers, start lock identifiers, and stop lock identifiers can all be used to determine the lock interval, and a single-line lock identifier can determine the lock interval on its own, while start and stop lock identifiers must be used together to determine the lock interval, when a line of code has both a single-line lock identifier and a start lock identifier, or both a single-line lock identifier and a stop lock identifier, the line of code is directly identified as a single-line lock line. This simplifies the processing logic for determining the lock interval based on the lock identifiers when there are multiple lock identifiers on the same line of code, thus allowing for faster determination of the lock interval.

[0025] Secondly, embodiments of this application also provide a code locking method, including: Obtain the target code file; If the target code file includes a lock identifier, the lock interval in the target code file is determined and recorded based on the lock identifier; the starting and ending code lines within the lock interval both include lock identifiers that exist as comments. The lines of code within the locked area cannot be edited.

[0026] In the above implementation, the locked interval is determined based on the locking identifier. Since the locking identifier exists as a comment in the starting and ending lines of the locked interval, its position changes whenever the line containing the locking identifier changes within the target file. Therefore, regardless of the position of the line containing the locking identifier, the locked interval determined by the identifier remains the same, thus maintaining the uneditable state of the lines within the locked interval. This solves the problem where a change in line position causes the actual line corresponding to a specified line number to no longer be the originally locked line, resulting in the inability to maintain the original locked line while incorrectly locking lines that shouldn't be locked are incorrectly configured to be locked.

[0027] Further, the locking identifier includes a start locking identifier and an end locking identifier, and determining the locking range in the object code file based on the locking identifier includes: The locking interval is obtained by taking the line containing the start lock symbol as the starting line of the locking interval and the line containing the end lock symbol as the ending line of the locking interval.

[0028] Further, the locking interval is obtained by taking the line containing the start lock character as the starting line of the locking interval and the line containing the end lock character as the ending line of the locking interval, including: Iterate through each line of code in the target code file; When the first candidate starting line of code is encountered during traversal, the first candidate starting line of code is determined as the starting line of the locked interval; the candidate starting line of code is the line of code that includes a starting lock symbol; the first candidate starting line of code is either the line of code that has no other candidate starting line of code preceding it, or the line of code that is the closest preceding line of code and includes a lock symbol is the line of code that is the candidate ending line of code; the candidate ending line of code is the line of code that includes a ending lock symbol; the candidate ending line of code is the line of code that includes a ending lock symbol. When traversing to the last candidate termination line, the last candidate termination line is determined as the termination line of the locked interval; the last candidate termination line is either a line of code where there are no other candidate termination lines after it, or the line of code that is the closest candidate starting line of code after it and includes the lock identifier.

[0029] Further, the locking identifier includes a single-line locking character; determining the locking range in the target code file based on the locking identifier includes: The single-line locked line with the single-line locking symbol is determined as the locked interval.

[0030] Furthermore, if a line of code has both a single-line lock character and a start lock character, or both a single-line lock character and a stop lock character, then the line of code is determined to be a single-line lock line; no line of code in the target code file can be both a single-line lock line and an alternative start line, nor can it be both a single-line lock line and an alternative stop line.

[0031] Furthermore, the locked intervals in the target code file are recorded, including: Record the line numbers of the starting and ending code lines within the locked interval.

[0032] In the above implementation, since each line number in the target code file is unique, the locked interval can be recorded by recording the line numbers of the starting and ending lines. Furthermore, compared to recording the line numbers of all lines within the locked interval, this method reduces storage resource consumption. Additionally, when subsequent updates to the recorded locked interval are needed, the amount of data required is also less, allowing for faster updates.

[0033] Furthermore, the line numbers of the starting and ending code lines within the locked interval are recorded, including: Record the line number of the starting code line within the locked interval into the first position of a preset two-dimensional array, and record the line number of the ending code line within the locked interval into the second position of the two-dimensional array.

[0034] In the above implementation process, by recording the line number of the starting code line within the locked interval in the first position of a preset two-dimensional array and recording the line number of the ending code line within the locked interval in the second position of the two-dimensional array, the structured storage of the locked interval can be achieved, making the recording results of the locked interval more concise and clear, and facilitating programmers' understanding and maintenance of the program code.

[0035] Thirdly, embodiments of this application also provide a code locking device, including: The judgment module is configured to determine whether the target code line is a locked code line in response to an editing instruction for the target code line; The execution module is configured to perform the editing operation corresponding to the editing instruction on the target code line if the target code line is not the locked code line. The execution module is also configured to not perform the editing operation corresponding to the editing instruction if the target code line is the locked code line; The locked code line is a code line that exists in the target code file and is located within the locked interval; the starting and ending code lines of the locked interval both include a locked identifier that exists as a comment, and the locked interval is determined based on the locked identifier.

[0036] Fourthly, embodiments of this application also provide a code locking device, including: The acquisition module is configured to acquire target code files; The recording module is configured to determine and record a locked interval in the target code file based on the locked identifier when the target code file includes a locked identifier; the starting and ending lines of the locked interval both include the locked identifier, which is present as a comment. The lines of code within the locked area cannot be edited.

[0037] When the code editor is running, it executes the code locking methods described in the first and / or second aspects above.

[0038] Fifthly, embodiments of this application also provide an electronic device, including a processor and a memory; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the code locking method of the first aspect and / or the second aspect described above.

[0039] Sixthly, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the code locking method described in the first and / or second aspects.

[0040] In a seventh aspect, this application also provides a storage medium storing computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the code locking method described in the first and / or second aspects. Attached Figure Description

[0041] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0042] Figure 1 A flowchart illustrating a code locking method provided in an embodiment of this application; Figure 2 A schematic diagram of an object code file provided for an embodiment of this application; Figure 3 A schematic diagram of another object code file provided in an embodiment of this application; Figure 4 A schematic diagram of another object code file provided in an embodiment of this application; Figure 5 A schematic diagram of another object code file provided in an embodiment of this application; Figure 6(a) is a schematic diagram of a single-row locked row provided in an embodiment of this application; Figure 6(b) is a schematic diagram of another single-row locked row provided in an embodiment of this application; Figure 6(c) is a schematic diagram of another single-row locked row provided in an embodiment of this application; Figure 7 A flowchart illustrating another code locking method provided in an embodiment of this application; Figure 8 A flowchart illustrating another code locking method provided in an embodiment of this application; Figure 9 A flowchart illustrating another code locking method provided in an embodiment of this application; Figure 10 This is a schematic diagram of the structure of a code locking device provided in an embodiment of this application; Figure 11 This is a schematic diagram of another code locking device provided in an embodiment of this application; Figure 12 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0043] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.

[0044] Example 1: To address the problem in related technologies where a change in code line position causes a specified code line number to no longer correspond to the originally designated locked code line, resulting in the originally locked code line no longer being locked while code lines that should not be locked are incorrectly configured to be locked, this application provides a code locking method. See also... Figure 1 As shown, Figure 1 A flowchart illustrating a code locking method provided in this application embodiment includes: Step S101: Obtain the target code file.

[0045] In some embodiments, the target code file can be a code file edited by the programmer. The programmer can input the edited code file into a code editor, which will then compile the target code file, determine the locked sections within the target code file, and display the compiled target code file.

[0046] Step S102: If the target code file includes a lock identifier, determine and record the lock interval in the target code file based on the lock identifier.

[0047] The starting and ending lines of code within a locked region both include a lock identifier that is displayed as a comment. Lines of code within a locked region cannot be edited.

[0048] In the code locking method provided in this application embodiment, since the locking identifier exists as a comment in the corresponding code line, the position of the locking identifier in the target code file will change even if the position of the code line changes. Therefore, no matter how the position of the code line in the target code file changes, the locking interval determined by the locking identifier remains the same, thus maintaining the uneditable state of the code lines within the locking interval. This solves the problem that when the position of the code line changes, the actual code line corresponding to the specified code line number is no longer the originally set locked code line, resulting in the inability to maintain the originally set locked code line in a locked state, while code lines that should not be locked are incorrectly configured as locked.

[0049] Alternatively, the presence of a lock identifier in the object code file can be determined in the following ways: Using a preset locking identifier, a matching operation is performed on each line of code in the target code file. If a match is successful, it is determined that the target code file contains the locking identifier. Furthermore, if the target code file contains the locking identifier, the locking range in the target code file is determined based on the locking identifier.

[0050] For example, regular expressions can be used to perform matching operations on each line of code in the target code file using lock identifiers. Even when the lock identifier consists of multiple symbols, spaces between the symbols can still accurately identify the lock identifier.

[0051] Optionally, the lock identifier includes at least one of a single-line lock character, a start lock character, and a stop lock character.

[0052] A single-line lock character can be used alone to restrict the line of code it belongs to to an uneditable state. That is, the locked area defined by a single-line lock character is the line of code containing the single-line lock character. Start and end lock characters must be used together to define a locked area. The start lock character specifies the beginning line of the locked area, and the end lock character specifies the ending line of the locked area. In other words, a locked area defined by start and end lock characters has a start lock character at its beginning and an end lock character at its end.

[0053] In target code files built with different programming languages, the corresponding lock identifiers are different.

[0054] In one embodiment, the programming language of the target code file is C. The single-line lock character can be " / / The start lock delimiter can be " / / ▼". The end lock delimiter can be " / / ▲". Correspondingly, the regular expression for the lock delimiter can be represented as regex_cpp = r"^\s* / / \s*([▼▲ ])"

[0055] In one embodiment, the programming language of the target code file is Python, and the single-line lock character can be "#". The start lock delimiter can be "#▼". The end lock delimiter can be "#▲". Correspondingly, the regular expression for the lock delimiter can be represented as regex_python = r"^\s*#\s*([▼▲ ])"

[0056] In one optional implementation provided in this application, determining the locking interval in the target code file based on the locking identifier includes: the locking interval can be obtained by taking the code line where the start locking identifier is located as the starting code line of the locking interval and the code line where the end locking identifier is located as the ending code line of the locking interval.

[0057] For example, the target code file can be as follows Figure 2 As shown. In Figure 2 In the target code file shown, #include <iostream> / / ▼ indicates the first alternative starting line of code. #include<walnut_string> / / ▲ represents the last alternative termination line. Therefore, the locked range is the line starting with #include. <iostream> / / ▼ indicates the starting line of code, followed by the line #include<walnut_string> / / ▲ indicates the range where the code line ends.

[0058] Optionally, the process of obtaining the locked interval by taking the code line containing the start lock character as the starting code line and the code line containing the end lock character as the ending code line can include: Iterate through each line of code in the target code file; When traversing to the first candidate starting line of code, the first candidate starting line of code is determined as the starting line of the locked interval; the candidate starting line of code is the line of code that includes the starting lock identifier; the first candidate starting line of code is either the line of code that has no other candidate starting line of code before it, or the line of code that is the closest candidate ending line of code that includes the lock identifier before it.

[0059] When traversing to the last candidate termination line, the last candidate termination line is determined as the termination line of the locked interval; wherein, the candidate termination line is the line of code that includes the lock terminator; the last candidate termination line is: the line of code that has no other candidate termination lines after it, or the line of code that is the closest candidate starting line of code that includes the lock identifier after it.

[0060] For example, in combination Figure 3 The target code file shown is in, as Figure 3 In the target code file shown, lines 5 and 6 both contain a start lock character, making them both potential start lines. However, since line 5 precedes line 6, it is not the first potential start line. Since there are no other potential start lines before line 5, line 5 is the first potential start line. Simultaneously, line 9 contains a stop lock character, and there are no other lines after it. Therefore, line 9 is the last potential stop line. Thus, in... Figure 3 In the target code file shown, the locked range is defined by the line `#include "walnut_webview.h"` as the starting line and the line `#include` as the ending line.<walnut_string> This is the interval that terminates the line of code.

[0061] For example, in combination Figure 4 The target code file shown is in, as Figure 4 In the target code file shown, line 5 contains a start lock character, making it a candidate start line. The nearest line before line 5 that contains a lock character is line 3, which also contains a stop lock character; therefore, line 3 is a candidate stop line. Thus, the nearest line before line 5 that contains a lock character is a candidate stop line. Therefore, line 5 is determined to be the first candidate start line. Meanwhile, line 9 contains a stop lock character, and there are no other lines after line 9. Therefore, line 9 is the last candidate stop line. Therefore, in the... Figure 4 In the target code file shown, the locked range is defined by the line `#include "walnut_webview.h"` as the starting line and the line `#include` as the ending line.<walnut_string> This is the interval that terminates the line of code.

[0062] For example, in combination Figure 5 As shown, in Figure 5 In the target code file, line 8 contains a termination lock character. Therefore, line 8 is a candidate termination line. Similarly, line 10 contains a start lock character. Therefore, line 10 is a candidate start line. Furthermore, line 9 does not contain a lock identifier. Therefore, the nearest line after line 8 that contains a lock identifier is a candidate start line. Thus, line 8 is the last candidate termination line. Meanwhile, line 5 contains a start lock character, and there are no other lines containing start lock characters before line 5. Therefore, line 5 is the first candidate start line. Therefore, in... Figure 5 In the target code file shown, the locked interval is the interval that starts with the line #include "walnut_webview.h" and ends with the line #include "thread.h".

[0063] In one optional implementation of this application, a single-line locked line with a single-line lock symbol is defined as a locked interval.

[0064] For example, a single-line locked line can be a line of code as shown in Figure 6(a). A single-line locked line includes the single-line lock character " / / ". ".

[0065] Optionally, a line of code can have both a single-line lock character and a start lock character. If a line of code has both a single-line lock character and a start lock character, then that line of code is determined to be a single-line lock line. No line of code in the object code file can be both a single-line lock line and an alternative start line, nor can it be both a single-line lock line and an alternative end line. In other words, the single-line lock character has higher priority than the start lock character.

[0066] For example, a single-line locked line can also be a line of code as shown in Figure 6(b). A single-line locked line can include the single-line lock character " / / ". "and start lock character " / / ▼".

[0067] Similarly, a line of code can have both a single-line lock and a terminating lock. If a line of code has both a single-line lock and a terminating lock, it is determined to be a single-line lock line. No line of code in the object file can simultaneously be a single-line lock line and an alternative start line, nor can it simultaneously be a single-line lock line and an alternative terminating line. In other words, the single-line lock has higher priority than the terminating lock.

[0068] For example, a single-line locked line can also be a line of code as shown in Figure 6(c). A single-line locked line can include the single-line lock character " / / ". "and the terminator " / / ▲".

[0069] In one optional implementation provided in this application embodiment, recording the locked interval in the target code file includes: recording the line numbers of the starting and ending code lines within the locked interval.

[0070] Optionally, the line numbers of the starting and ending code lines within the locked interval are recorded, including: recording the line number of the starting code line within the locked interval to the first position of a preset two-dimensional array, and recording the line number of the ending code line within the locked interval to the second position of the two-dimensional array.

[0071] For example, the code lines in the target code file are traversed. When the first candidate starting line is reached, it is determined as the starting line of the locked interval. If the line number of this candidate starting line is 2, then line number 2 is recorded in the first position of a preset two-dimensional array. Then, the code lines after this candidate starting line are traversed. When the last candidate ending line is reached, it is determined as the ending line of the locked interval. If the line number of this candidate ending line is 5, then line number 5 is recorded in the second position of a preset two-dimensional array. The two-dimensional array [2, 5] is obtained. Thus, the determination and recording of the locked interval are achieved.

[0072] Optionally, multiple locking intervals can exist. For each locking interval, the line number of the starting code line within the locking interval can be recorded in the first position of a preset two-dimensional array, and the line number of the ending code line within the locking interval can be recorded in the second position of the two-dimensional array. This results in multiple two-dimensional arrays.

[0073] Optionally, if the locked interval is a single-line locked line, then both the starting and ending code lines of the locked interval are single-line locked lines. Correspondingly, the line numbers of the single-line locked lines can be recorded in the first and second positions of a two-dimensional array, thereby realizing the recording of the locked interval determined by the single-line locked lines.

[0074] For example, if the row number of the single-row locked row is 7, then the two-dimensional array determined by the single-row locked row is [7, 7].

[0075] In one optional implementation provided in this application embodiment, recording the locked interval in the target code file includes: recording the line numbers of all code lines within the locked interval.

[0076] Optionally, to inform users that the lines of code within the locked section are in an uneditable state, after step S102, locking styles can be set for each line of code within the locked section based on a preset CSS class name.

[0077] For example, the preset CSS class names can be recorded in the first position of a preset array, and the line numbers of each line of code within the locked section can be recorded in the second position of the preset array to obtain the preset array. The `setAnnotations` method is then used to apply the preset array to the code editor, so that the lines of code within the locked section have the locking style corresponding to the preset CSS class names. In some embodiments, the locking style corresponding to the preset CSS class names can be a padlock.

[0078] Example 2 Based on Example 1, the code editor can display the compiled target code file, and the code lines within the locked section in the displayed target code file can have a locked style.

[0079] When the user edits the compiled target code file, it can be combined with Figure 7 The code locking method shown determines whether to respond to user editing actions.

[0080] Combination Figure 7 As shown, the code locking method may include the following steps: Step S701: In response to an editing instruction for the target line of code, determine whether the target line of code is a locked line of code. If so, proceed to step S702; otherwise, proceed to step S703.

[0081] Alternatively, you can determine if an editing command has been received by listening to the keydown event in the code editor. You can obtain the line number of the target code line using `aceEditor.selection.getAllRanges()`.

[0082] You can use handleEditorReadOnlyCommand to determine if the target line of code is a locked line of code.

[0083] Optionally, the process of determining whether a target code line is a locked code line may include: determining whether the line number of the target code line is within a preset locked line number set. The preset locked line number set includes the line numbers of all code lines within the locked interval; the line numbers in the preset locked line number set change as the line numbers of code lines within the locked interval change. If the line number of the target code line is within the preset locked line number set, the target code line is determined to be a locked code line. If the line number of the target code line is not within the preset locked line number set, the target code line is determined not to be a locked code line. Optionally, the preset locked line number set may be a two-dimensional array as described in Embodiment 1 above.

[0084] Step S702: Do not perform the editing operation corresponding to the editing instruction.

[0085] For example, when the target code behavior locks the code line, the editing instruction for the target code line can be canceled by calling the Cancel Event Default Behavior interface, thereby preventing the editing operation corresponding to the editing instruction from being executed.

[0086] In some embodiments, editing instructions may include at least one of the following: code move instructions, code modification instructions, and code copy instructions.

[0087] Correspondingly, the code move command corresponds to the edit operation of moving code. The code modify command corresponds to the edit operation of modifying code. The code copy command corresponds to the edit operation of copying code.

[0088] Step S703: Execute the editing operation corresponding to the editing instruction for the target line of code.

[0089] The code locking method provided in this application determines the locking range based on a locking identifier. Since the locking identifier exists as a comment in the starting and ending lines of the locking range, its position changes whenever the position of the code line with the locking identifier changes within the target code file. Therefore, regardless of the position of the code line with the locking identifier, the locking range determined by the locking identifier remains the same. Thus, when determining whether a target code line is a locked code line, the same locking range can always be used to determine it. Furthermore, if the target code line is a locked code line, the editing operation corresponding to the editing instruction is not executed, thereby maintaining the uneditable state of the code lines within the locking range. This solves the problem that when the code line position changes, the actual code line corresponding to the specified code line number is no longer the originally set locked code line, resulting in the inability to maintain the originally set locked code line in a locked state, while code lines that should not be locked are incorrectly configured as locked.

[0090] Optional, combined Figure 8 As shown, in order to maintain the uneditable state of the code lines within the locked interval even when the code line position in the target code file changes, the following steps can be performed after step S703: Step S704: Re-determine the locking range based on the locking identifier.

[0091] Alternatively, step S704 can be replaced by re-determining the locking range based on the locking identifier when the editing operation is a line addition or line deletion operation.

[0092] In one optional implementation provided in this application, the locking interval can be obtained by taking the code line where the start lock character is located as the starting code line of the locking interval and the code line where the end lock character is located as the ending code line of the locking interval.

[0093] Optionally, the locked interval is obtained by taking the line containing the start lock character as the starting line of the locked interval and the line containing the end lock character as the ending line of the locked interval, including: Iterate through each line of code in the target code file; When the first candidate starting line of code is encountered, it is determined as the starting line of the locked interval. The candidate starting line of code is the line of code that includes the starting lock identifier. The first candidate starting line of code is either the line of code that has no other candidate starting line of code before it, or the line of code that is the closest candidate ending line of code that includes the lock identifier before it. When traversing to the last candidate termination line, the last candidate termination line is determined as the termination line of the locked interval; wherein, the candidate termination line is the line of code that includes the lock terminator; the last candidate termination line is: the line of code that has no other candidate termination lines after it, or the line of code that is the closest candidate starting line of code that includes the lock identifier after it.

[0094] In one optional implementation of this application, a single-line locked line with a single-line lock symbol is defined as a locked interval.

[0095] Optionally, a line of code can have both a single-line lock character and a start lock character. If a line of code has both a single-line lock character and a start lock character, then the line of code is determined to be a single-line lock line. No line of code in the target code file can be both a single-line lock line and an alternative start line of code, nor can it be both a single-line lock line and an alternative end line of code.

[0096] Similarly, a line of code can have both a single-line lock and a terminating lock. If a line of code has both a single-line lock and a terminating lock, then the line of code is determined to be a single-line lock line; no line of code in the object code file can be both a single-line lock line and an alternative start line, nor can it be both a single-line lock line and an alternative terminating line.

[0097] Step S705: Update the line numbers in the preset locked line number set according to the line numbers of the code lines within the locked interval.

[0098] Optional, combined Figure 9 As shown, step S705 can also be replaced by step S706.

[0099] Step S706: If the line number of the code line within the locked interval changes, update the line numbers in the preset locked line number set according to the line numbers of the code line within the locked interval.

[0100] Because performing an editing operation corresponding to an editing instruction on a target line of code may cause a change in the position of the locked interval in the target code file, thus changing the line number of the code line within the locked interval. Therefore, after performing the editing operation corresponding to the editing instruction on the target line of code, the locked interval can be redefined based on the locking identifier to update the locked interval promptly if its position changes. Simultaneously, since the line numbers in the preset locked line number set can be updated based on the line numbers of the code lines within the locked interval, the line numbers in the preset locked line number set can also be updated promptly if the position of the locked interval changes. Thus, if the position of the locked interval changes, it can be determined whether the target line of code is within the locked interval whose position has changed by checking if its line number is within the updated preset locked line number set. If the target line of code is within the locked interval whose position has changed, the editing operation corresponding to the editing instruction is not performed, thereby maintaining the uneditable state of the code lines within the locked interval.

[0101] Example 3: This embodiment provides further examples and explanations of the present application based on the above embodiments.

[0102] If a user wants to restrict the editability of specific code behavior in a target code file, they can add a lock identifier as a comment after that line of code.

[0103] Locking identifiers include at least one of start lock, stop lock, and single-line lock.

[0104] The start lock character can be ▼, used to declare the starting position of the lock for subsequent lines of code, and must be used in pairs with the end lock character. Each start lock character must match a end lock character; otherwise, it is considered a syntax error.

[0105] The terminating lock symbol can be ▲, used to indicate the end of the locked interval. If the starting lock symbol corresponding to the terminating lock symbol is unknown in the object code file, an error message can be displayed and the symbol can be ignored.

[0106] The single-line lock character can be It is used to independently lock the line of code it is located in. It also has higher priority than the start lock and the end lock.

[0107] If both a start lock character and a single-line lock character exist in a line of code, or if both a stop lock character and a single-line lock character exist, the single-line lock character shall prevail.

[0108] Single-line lock characters can be used at the comment position on any line of code, without needing to be used in pairs.

[0109] Regular expressions can be used to determine whether a line of code contains a lock identifier.

[0110] When the target code file is in Python, it can match lines of code that begin with '#' and contain a lock identifier. The corresponding regular expression could be `regex_python = r"^\s*#\s*([▼▲]`. ])". Spaces are allowed before the #, for example, for first-line indentation.

[0111] When the target code file is in C++ or Java, it can match lines of code that begin with / / and include a lock identifier. The corresponding regular expression could be `regex_cpp = r"^\s* / / \s*([▼▲]`. Similarly, spaces are allowed before / / .

[0112] After obtaining the target code file with lock tags added by the user, the code editor can be initialized using this locked target code file, and logic can be added to prevent editing of locked lines of code. The specific steps are as follows: The code editor can maintain a two-dimensional array to dynamically cache specified lines of code in the target code file. The two-dimensional array can be configured as `disabledRowLines = []`.

[0113] Using ` / n` as the delimiter, filter code files by checking if line comments contain lock identifiers. For code files written in Python, line comments should include `#▼`, `#▲`, and / or `#`. In this case, it can be determined that the line of code contains a lock identifier.

[0114] For target code files that exist in C++ or Java, comments in the code lines include / / ▼, / / ▲, and / or / / In this case, it can be determined that the line of code contains a lock identifier.

[0115] If the lock identifier in a line of code is / / ▼ or #▼, it indicates that locking begins from that line of code, and the line number of that line, for example, 2, is filled into the first position of the two-dimensional array disabledRowLines. This continues until a line of code containing / / ▲ or #▲ appears, at which point the line number of that line, for example, 5, is filled into the second position of the two-dimensional array disabledRowLines. Thus, the two-dimensional array disabledRowLines = [2, 5] is obtained, representing that the second, third, fourth, and fifth lines are all locked.

[0116] The lock identifier in line 7 is / / or# In this case, the line number of the code line is directly filled into the two-dimensional array. The resulting two-dimensional array is: disabledRowLines = [[2, 5], [7, 7]].

[0117] Furthermore, the two-dimensional array can be dynamically updated when the user edits the target code file. For example, when the user edits the target code file, i.e., sends an editing command to the code editor, in other words, when the user presses Enter, the two-dimensional array can be updated according to the locking logic described above.

[0118] For example, you can listen to the onkeydown event of the code editor, and update the two-dimensional array disabledRowLines according to the locking logic described above when the onkeydown event is detected.

[0119] For locked lines of code, a lock style can be displayed in the code editor. For the Ace editor, a lock style can be added to locked lines of code using a custom CSS class name.

[0120] As mentioned above, the locked lines of code have been obtained, for example, disabledRowLines=[[2, 5], [7, 7]]. Since [2, 5] represents an interval, the two-dimensional array can be extracted into the "number of rows to be locked" using an internal function, resulting in [2, 3, 4, 5, 7]. After flattening the structure, this is the number of single rows to be locked.

[0121] Then iterate through [2, 3, 4, 5, 7] and generate a new array called annotations. This array stores an object with two properties: const annotations = Object.keys(rows).map(row =>{ const annotation = { row, className: "ace-readonly__annotation" }; return annotation; }); Here, Row represents the number of single lines that need to be locked. Adding a fixed CSS class name to it will add a padlock-style icon background to the ace_icon class, indicating that the current line of code cannot be edited.

[0122] Finally, the current annotations are set using the `aceEditor.renderer.setAnnotations(annotations)` interface. This ensures that the DOM element locking the line of code in the Ace editor has the specified CSS class name. Having this CSS class name completes the application of the padlock style to the locked line of code.

[0123] The following code can be integrated into a code editor to disable mouse and keyboard operations on locked lines of code.

[0124] aceEditor.container.addEventListener( "keydown", handleEditorReadOnlyCommand, true ); In this way, the code editor can determine whether the user has performed mouse and / or keyboard operations on the target code file by listening to the keydown event of aceEditor.container.

[0125] The event logic for keyboard and / or mouse operations can be handled in handleEditorReadOnlyCommand.

[0126] In this logic, it can be determined whether the line of code being edited is a locked line of code when the keyboard or mouse is pressed.

[0127] The locked line of code can be determined using a two-dimensional array. The line number of the currently edited line of code can be obtained using the aceEditor.selection.getAllRanges() interface.

[0128] Therefore, by determining whether the line number of the currently edited line is within a two-dimensional array, it can be determined whether the currently edited line is a locked line. If the currently edited line is a locked line, the default behavior interface for canceling the event is invoked, canceling the editing operation on that line.

[0129] The interface for canceling the default behavior of an event can be either e.preventDefault() or e.stopPropagation().

[0130] Additionally, it can restrict the operation of some hidden commands, such as the four commands "copylinesup", "movelinesup", "copylinesdown", and "movelinesdown", and also prohibit operations in locked lines of code.

[0131] `copylinesup` means to copy the selected lines of code "up" without deleting the original lines.

[0132] `copylinesdown` means to copy the selected lines of code "down" without deleting the original lines.

[0133] The movelinesup instruction moves the currently selected line of code up one line while maintaining the original order.

[0134] `movelinesdown` moves the currently selected line of code down one line while maintaining the original order.

[0135] Example 4 Based on the same inventive concept, combined with Figure 10 As shown in the figure, this application embodiment also provides a code locking device, including a judgment module 801 and an execution module 802.

[0136] The judgment module 801 is configured to determine whether a target code line is a locked code line in response to an editing instruction for that target code line. The execution module 802 is configured to execute the editing operation corresponding to the editing instruction on the target code line if it is not a locked code line. The execution module 802 is also configured not to execute the editing operation corresponding to the editing instruction if the target code line is a locked code line. A locked code line is a code line existing in the target code file and located within a locked interval; both the starting and ending code lines of the locked interval include a locking identifier that exists as a comment, and the locked interval is determined based on the locking identifier.

[0137] The judgment module 801 is specifically configured to determine whether the line number of the target code line is within the preset locked line number set; the preset locked line number set includes the line numbers of all code lines within the locked interval; the line numbers in the preset locked line number set change as the line numbers of the code lines within the locked interval change; if the line number of the target code line is within the preset locked line number set, the target code line is determined to be a locked code line. If the line number of the target line is not in the preset set of locked line numbers, the target line is not a locked line.

[0138] The code locking device may further include a determining module 803 and an updating module 804. The determining module 803 is configured to re-determine the locking interval based on the locking identifier after the execution module performs the editing operation corresponding to the editing instruction on the target code line. The updating module 804 is configured to update the line numbers in a preset set of locked line numbers based on the line numbers of the code lines within the locked interval.

[0139] The determination module 803 can also be configured to re-determine the locking range based on the locking identifier when the editing operation is a line addition operation or a line deletion operation.

[0140] The module 803 can be specifically configured to take the code line where the start lock character is located as the starting code line of the locked interval and the code line where the end lock character is located as the ending code line of the locked interval to obtain the locked interval.

[0141] Specifically, module 803 can be configured to traverse each line of code in the target code file; when traversing to the first candidate starting line of code, the first candidate starting line of code is determined as the starting line of the locked interval; the candidate starting line of code is a line of code including a start lock symbol; the first candidate starting line of code is a line of code where there are no other candidate starting lines before it, or it is the line of code that is the closest preceding candidate starting line of code and includes a lock identifier as the candidate ending line of code; the candidate ending line of code is a line of code including a stop lock symbol; when traversing to the last candidate ending line of code, the last candidate ending line of code is determined as the ending line of the locked interval; the last candidate ending line of code is a line of code where there are no other candidate ending lines after it, or it is the line of code that is the closest following candidate ending line of code and includes a lock identifier as the candidate starting line of code.

[0142] Specifically, module 803 can be configured to identify single-line locked lines with single-line lock characters as locked intervals.

[0143] Specifically, module 803 can be configured to determine that a line of code is a single-line locked line when it has both a single-line lock character and a start lock character, or both a single-line lock character and a stop lock character. No line of code in the target code file can be both a single-line locked line and an alternative start line of code, nor can it be both a single-line locked line and an alternative stop line of code.

[0144] The update module 804 can also be configured to update the line numbers in the preset locked line number set based on the line numbers of the code lines within the locked interval when the line number of the code lines within the locked interval changes.

[0145] It should be understood that, for the sake of brevity, some of the content described in Embodiment 2 will not be repeated in this embodiment.

[0146] Example 5 Based on the same inventive concept, combined with Figure 11 As shown in the illustration, this application also provides a code locking device, including an acquisition module 901 and a recording module 902. The acquisition module 901 is configured to acquire a target code file. The recording module 902 is configured to determine and record a locked section in the target code file based on the locking identifier when the target code file includes a locking identifier; the starting and ending code lines within the locked section both include locking identifiers that exist as comments. The code lines within the locked section cannot be edited.

[0147] The recording module 902 is specifically configured to use the code line where the start lock character is located as the starting code line of the locked interval and the code line where the end lock character is located as the ending code line of the locked interval to obtain the locked interval.

[0148] The recording module 902 is specifically configured to traverse each line of code in the target code file. When traversing to the first candidate starting line, it is determined as the starting line of the locked interval; the candidate starting line is a line of code including a start lock character; the first candidate starting line is a line of code where no other candidate starting line precedes it, or the nearest preceding line of code including a lock identifier is the candidate ending line; the candidate ending line is a line of code including a stop lock character; the candidate ending line is a line of code including a stop lock character. When traversing to the last candidate ending line, it is determined as the ending line of the locked interval; the last candidate ending line is a line of code where no other candidate ending line follows it, or the nearest preceding line of code including a lock identifier is the candidate starting line.

[0149] The recording module 902 is specifically configured to identify single-line locked lines with single-line lock characters as locked intervals.

[0150] The recording module 902 can also be configured to determine that a line of code is a single-line locked line when it has both a single-line lock character and a start lock character, or both a single-line lock character and a stop lock character; no line of code in the target code file can be both a single-line locked line and an alternative start line of code, nor can it be both a single-line locked line and an alternative stop line of code.

[0151] The recording module 902 can also be configured to record the line numbers of the starting and ending code lines within the locked range.

[0152] The recording module 902 can also be configured to record the line number of the starting code line within the locked interval into the first position of a preset two-dimensional array, and record the line number of the ending code line within the locked interval into the second position of the two-dimensional array.

[0153] It should be understood that, for the sake of brevity, some of the content described in Embodiment 1 will not be repeated in this embodiment.

[0154] Example 6: Based on the same inventive concept, combined with Figure 12 As shown, this embodiment provides an electronic device, which includes a processor 111, a memory 112, and a code editor. Wherein: The processor 111 is used to execute one or more programs stored in the memory 112 to implement the code locking method described above in the code editor.

[0155] It is understandable that processor 111 can be a processor core or processor chip, or other circuitry capable of program configuration and execution. Memory 112 can be RAM (Random Access Memory), ROM (Read-Only Memory), flash memory, etc., but this is not a limitation.

[0156] It's understandable. Figure 12 The structure shown is for illustrative purposes only; the electronic device may also include components that are more advanced than those shown. Figure 12 The more or fewer components shown, or having the same Figure 12 Different configurations are shown. For example, it may also have an internal communication bus for communication between the processor 111 and the memory 112; or it may have an external communication interface, such as a USB (Universal Serial Bus) interface, a CAN (Controller Area Network) bus interface, etc.; or it may have an information display component such as a display screen, but this is not a limitation.

[0157] Based on the same inventive concept, this embodiment also provides a computer program product, which includes a computer program that, when executed by a processor, implements the code locking method of Embodiment 1 and / or Embodiment 2 described above.

[0158] Based on the same inventive concept, this embodiment also provides a computer-readable storage medium, such as a floppy disk, optical disk, hard disk, flash memory, USB flash drive, SD (Secure Digital Memory Card), MMC (Multimedia Card), etc., in which one or more programs implementing the above steps are stored. These one or more programs can be executed by one or more processors to implement the above code locking method. Further details will not be elaborated here.

[0159] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.

[0160] Furthermore, the units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0161] Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0162] In this document, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, without necessarily requiring or implying any such actual relationship or order between these entities or operations.

[0163] In this article, "multiple" refers to two or more.

[0164] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.< / iostream> < / iostream>

Claims

1. A code locking method, characterized in that, include: In response to an editing instruction targeting a line of code, determine whether the target line of code is a locked line of code; If the target code line is not the locked code line, perform the editing operation corresponding to the editing instruction on the target code line; If the target code line is the locked line, then the editing operation corresponding to the editing instruction will not be executed; The locked code line is a code line that exists in the target code file and is located within the locked interval; The starting and ending lines of the locked interval both include a locking identifier that is present as a comment, and the locked interval is determined based on the locking identifier.

2. The method according to claim 1, characterized in that, Determining whether the target line of code is a locked line of code includes: Determine whether the line number of the target code line is within a preset locked line number set; the preset locked line number set includes the line numbers of all code lines within the locked interval; the line numbers in the preset locked line number set change as the line numbers of the code lines within the locked interval change; If the line number of the target code line is within the preset set of locked line numbers, then the target code line is determined to be the locked code line. If the line number of the target code line is not within the preset set of locked line numbers, the target code line is not the locked code line.

3. The method according to claim 2, characterized in that, If the target code line is not the locked code line, after performing the editing operation corresponding to the editing instruction on the target code line, the method further includes: The locking interval is redefined based on the locking identifier; The line numbers in the preset locked line number set are updated based on the line numbers of the code lines within the locked interval.

4. The method according to claim 2, characterized in that, If the target code line is not the locked code line, after performing the editing operation corresponding to the editing instruction on the target code line, the method further includes: The locking interval is redefined based on the locking identifier; If the line number of a line of code within the locked interval changes, the line numbers in the preset locked line number set are updated according to the line numbers of the line of code within the locked interval.

5. A code locking method, characterized in that, include: Obtain the target code file; If the target code file includes a lock identifier, the lock interval in the target code file is determined and recorded based on the lock identifier; the starting and ending code lines within the lock interval both include lock identifiers that exist as comments. The lines of code within the locked area cannot be edited.

6. A code locking device, characterized in that, include: The judgment module is configured to determine whether the target code line is a locked code line in response to an editing instruction for the target code line; The execution module is configured to perform the editing operation corresponding to the editing instruction on the target code line if the target code line is not the locked code line. The execution module is also configured to not perform the editing operation corresponding to the editing instruction if the target code line is the locked code line; The locked code line is a code line that exists in the target code file and is located within the locked interval; The starting and ending lines of the locked interval both include a locking identifier that is present as a comment, and the locked interval is determined based on the locking identifier.

7. A code locking device, characterized in that, include: The acquisition module is configured to acquire target code files; The recording module is configured to determine and record a locked interval in the target code file based on the locked identifier when the target code file includes a locked identifier; the starting and ending lines of the locked interval both include the locked identifier, which is present as a comment. The lines of code within the locked area cannot be edited.

8. An electronic device, characterized in that, include: Processor and memory; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the code locking method according to any one of claims 1 to 5.

9. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the code locking method according to any one of claims 1 to 5.

10. A storage medium, characterized in that, The storage medium stores computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the code locking method according to any one of claims 1 to 5.