A software source code modification method, device, equipment and storage medium
By obtaining the initial source code and generating intermediate source code, and replacing it with target content using preset replacement rules, the problem of low efficiency of manual modification of software source code in the existing technology is solved, and efficient modifications are achieved quickly adapted to different customer needs.
Patent Information
- Application Number
- CN201910557161.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-06-25
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2039-06-25
AI Technical Summary
During the software sales process, since the label of customer information needs to be modified according to different customers, the existing technology uses manual modification, which leads to low efficiency, especially when the number of customers is large.
By obtaining the intermediate source code corresponding to the initial source code, the intermediate source code contains preset substitution content, and replaces the preset substitution content with the target substitution content according to the preset substitution rules, and generates the target source code to meet the needs of different customers.
It improves the efficiency of software source code modification, can quickly adapt to the needs of different customers, and reduces the cost and time of manual modification.
Smart Images

Figure CN112130828B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software technology, and in particular to a method, device, equipment and storage medium for modifying software source code. Background Art
[0002] In the process of selling software, it is necessary to modify the labels involving customer information in the source code of the software according to different customers. Currently, the labels are manually modified manually. However, when the number of customers is large, manual modification will result in low efficiency. Summary of the invention
[0003] The purpose of the embodiments of the present invention is to provide a method, device, equipment and storage medium for modifying software source code to improve the efficiency of modifying source code. The specific technical solution is as follows:
[0004] In a first aspect, an embodiment of the present invention provides a method for modifying software source code, comprising:
[0005] Obtaining an intermediate source code corresponding to the initial source code; the intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code;
[0006] Acquire a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between the preset replacement content and replacement content corresponding to different customers;
[0007] According to the first preset conversion rule, the preset replacement content in the intermediate source code is replaced with target replacement content to obtain a target source code, wherein the target replacement content corresponds to a target client.
[0008] Optionally, before obtaining the intermediate source code corresponding to the initial source code, the method further includes:
[0009] Obtaining the initial source code;
[0010] Determine the content to be modified in the initial source code according to a preset search rule; wherein the preset search rule is determined according to business requirements;
[0011] According to a second preset conversion rule, the content to be modified in the initial source code is replaced with preset replacement content to obtain the intermediate source code; wherein the second preset conversion rule includes a correspondence between the content to be modified and the preset replacement content.
[0012] Optionally, determining the content to be modified in the initial source code according to a preset search rule includes:
[0013] According to the preset search rule, the content to be modified is searched by character matching or regular expression wildcarding.
[0014] Optionally, after obtaining the initial source code, the method further includes:
[0015] According to the file dimensions, determine the content to be added and / or deleted;
[0016] The content to be added is added to the initial source code, and / or the content to be deleted is deleted from the initial source code.
[0017] Optionally, after obtaining the initial source code, the method further includes:
[0018] Determine the content to be added and / or deleted according to the row interval dimension;
[0019] The content to be added is added to the initial source code, and / or the content to be deleted is deleted from the initial source code.
[0020] Optionally, replacing the preset replacement content in the intermediate source code with target replacement content according to the first preset conversion rule to obtain the target source code includes:
[0021] The code restoration module replaces the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code.
[0022] Optionally, the replacing the content to be modified in the initial source code with preset replacement content according to a second preset conversion rule to obtain the intermediate source code includes:
[0023] The code modification module replaces the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code.
[0024] In a second aspect, an embodiment of the present invention provides a software source code modification device, comprising:
[0025] A first acquisition module is used to acquire an intermediate source code corresponding to the initial source code; the intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code; acquire a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between the preset replacement content and replacement content corresponding to different customers;
[0026] The modification module is used to replace the preset replacement content in the intermediate source code with target replacement content according to the first preset conversion rule to obtain a target source code, wherein the target replacement content corresponds to a target client.
[0027] Optionally, the device further comprises:
[0028] A second acquisition module, used to acquire the initial source code;
[0029] A first determination module, configured to determine the content to be modified in the initial source code according to a preset search rule; wherein the preset search rule is determined according to business requirements;
[0030] A replacement module is used to replace the content to be modified in the initial source code with preset replacement content according to a second preset conversion rule to obtain the intermediate source code; wherein the second preset conversion rule includes the corresponding relationship between the content to be modified and the preset replacement content.
[0031] Optionally, the first determination module is specifically configured to search for the content to be modified by character matching or regular expression wildcarding according to the preset search rule.
[0032] Optionally, the device further comprises:
[0033] A second determination module, used to determine content to be added and / or content to be deleted according to the file dimension;
[0034] A first adding module is used to add the content to be added to the initial source code; and / or,
[0035] The first deleting module is used to delete the content to be deleted from the initial source code.
[0036] Optionally, the device further comprises:
[0037] A third determination module is used to determine the content to be added and / or the content to be deleted according to the row interval dimension;
[0038] A second adding module is used to add the content to be added to the initial source code; and / or,
[0039] The second deleting module is used to delete the content to be deleted from the initial source code.
[0040] Optionally, the modification module is specifically configured to replace the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule through a code restoration module to obtain the target source code.
[0041] Optionally, the replacement module is specifically configured to replace the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule through the code modification module to obtain the intermediate source code.
[0042] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0043] The memory is used to store computer programs;
[0044] The processor, when used to execute the program stored in the memory, implements the following method steps:
[0045] Obtaining an intermediate source code corresponding to the initial source code; the intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code;
[0046] Acquire a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between preset replacement content and replacement content corresponding to different customers;
[0047] According to the first preset conversion rule, the preset replacement content in the intermediate source code is replaced with the target replacement content to obtain the target source code, wherein the target replacement content corresponds to the target client.
[0048] Optionally, before obtaining the intermediate source code corresponding to the initial source code, the following may also be included:
[0049] Get the initial source code;
[0050] Determine the content to be modified in the initial source code according to the preset search rules; wherein the preset search rules are determined according to business requirements;
[0051] According to the second preset conversion rule, the content to be modified in the initial source code is replaced with the preset replacement content to obtain the intermediate source code; wherein the second preset conversion rule includes the correspondence between the content to be modified and the preset replacement content.
[0052] Optionally, the content to be modified in the initial source code is determined according to a preset search rule, including:
[0053] According to the preset search rules, search for the content to be modified by character matching or regular wildcarding.
[0054] Optionally, after obtaining the initial source code, you can also include:
[0055] According to the file dimensions, determine the content to be added and / or deleted;
[0056] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0057] Optionally, after obtaining the initial source code, you can also include:
[0058] Determine the content to be added and / or deleted according to the row interval dimension;
[0059] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0060] Optionally, according to a first preset conversion rule, replacing preset replacement content in the intermediate source code with target replacement content to obtain a target source code includes:
[0061] The code restoration module replaces the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code.
[0062] Optionally, according to a second preset conversion rule, the content to be modified in the initial source code is replaced with preset replacement content to obtain an intermediate source code, including:
[0063] The code modification module replaces the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code.
[0064] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following method steps are implemented:
[0065] Obtaining an intermediate source code corresponding to the initial source code; the intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code;
[0066] Acquire a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between preset replacement content and replacement content corresponding to different customers;
[0067] According to the first preset conversion rule, the preset replacement content in the intermediate source code is replaced with the target replacement content to obtain the target source code, wherein the target replacement content corresponds to the target client.
[0068] Optionally, before obtaining the intermediate source code corresponding to the initial source code, the following may also be included:
[0069] Get the initial source code;
[0070] Determine the content to be modified in the initial source code according to the preset search rules; wherein the preset search rules are determined according to business requirements;
[0071] According to the second preset conversion rule, the content to be modified in the initial source code is replaced with the preset replacement content to obtain the intermediate source code; wherein the second preset conversion rule includes the correspondence between the content to be modified and the preset replacement content.
[0072] Optionally, the content to be modified in the initial source code is determined according to a preset search rule, including:
[0073] According to the preset search rules, search for the content to be modified by character matching or regular wildcarding.
[0074] Optionally, after obtaining the initial source code, you can also include:
[0075] According to the file dimensions, determine the content to be added and / or deleted;
[0076] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0077] Optionally, after obtaining the initial source code, you can also include:
[0078] Determine the content to be added and / or deleted according to the row interval dimension;
[0079] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0080] Optionally, according to a first preset conversion rule, replacing preset replacement content in the intermediate source code with target replacement content to obtain a target source code includes:
[0081] The code restoration module replaces the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code.
[0082] Optionally, according to a second preset conversion rule, the content to be modified in the initial source code is replaced with preset replacement content to obtain an intermediate source code, including:
[0083] The code modification module replaces the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code.
[0084] In a fifth aspect, an embodiment of the present invention provides a computer program product comprising instructions, which, when executed on a computer, causes the computer to perform the following method steps:
[0085] Obtaining an intermediate source code corresponding to the initial source code; the intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code;
[0086] Acquire a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between preset replacement content and replacement content corresponding to different customers;
[0087] According to the first preset conversion rule, the preset replacement content in the intermediate source code is replaced with the target replacement content to obtain the target source code, wherein the target replacement content corresponds to the target client.
[0088] Optionally, before obtaining the intermediate source code corresponding to the initial source code, the following may also be included:
[0089] Get the initial source code;
[0090] Determine the content to be modified in the initial source code according to the preset search rules; wherein the preset search rules are determined according to business requirements;
[0091] According to the second preset conversion rule, the content to be modified in the initial source code is replaced with the preset replacement content to obtain the intermediate source code; wherein the second preset conversion rule includes the correspondence between the content to be modified and the preset replacement content.
[0092] Optionally, the content to be modified in the initial source code is determined according to a preset search rule, including:
[0093] According to the preset search rules, search for the content to be modified by character matching or regular wildcarding.
[0094] Optionally, after obtaining the initial source code, you can also include:
[0095] According to the file dimensions, determine the content to be added and / or deleted;
[0096] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0097] Optionally, after obtaining the initial source code, you can also include:
[0098] Determine the content to be added and / or deleted according to the row interval dimension;
[0099] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0100] Optionally, according to a first preset conversion rule, replacing preset replacement content in the intermediate source code with target replacement content to obtain a target source code includes:
[0101] The code restoration module replaces the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code.
[0102] Optionally, according to a second preset conversion rule, the content to be modified in the initial source code is replaced with preset replacement content to obtain an intermediate source code, including:
[0103] The code modification module replaces the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code.
[0104] The software source code modification method, device, equipment and storage medium provided in the embodiments of the present invention can obtain the intermediate source code corresponding to the initial source code; the intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code; obtain a predetermined first preset conversion rule; wherein the first preset conversion rule includes the correspondence between the preset replacement content and the replacement content corresponding to different customers; according to the first preset conversion rule, the preset replacement content in the intermediate source code is replaced with the target replacement content to obtain the target source code, wherein the target replacement content corresponds to the target customer. The embodiments of the present invention can replace the preset replacement content included in the intermediate source code according to the preset conversion rule including the correspondence between the preset replacement content and the replacement content corresponding to different customers, and obtain the target source code including the target replacement content corresponding to the target customer, so as to realize the modification of the source code. Compared with the manual modification method, the efficiency of modifying the source code can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0105] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0106] Figure 1 A flow chart of a method for modifying software source code provided by an embodiment of the present invention;
[0107] Figure 2 Another flow chart of the software source code modification method provided by the embodiment of the present invention;
[0108] Figure 3 Another flow chart of the software source code modification method provided by the embodiment of the present invention;
[0109] Figure 4A schematic diagram of the structure of a software source code modification device provided by an embodiment of the present invention;
[0110] Figure 5 Another structural schematic diagram of a software source code modification device provided by an embodiment of the present invention;
[0111] Figure 6 Another structural schematic diagram of a software source code modification device provided by an embodiment of the present invention;
[0112] Figure 7 Another structural schematic diagram of a software source code modification device provided by an embodiment of the present invention;
[0113] Figure 8 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0114] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0115] The software source code modification method provided in the embodiment of the present invention can be applied to electronic devices. Specifically, the electronic device can be a processor, a tablet computer, a laptop computer, or a desktop computer.
[0116] The embodiment of the present invention provides a method for modifying software source code, such as Figure 1 As shown, it may include:
[0117] S101, obtaining an intermediate source code corresponding to an initial source code.
[0118] The intermediate source code includes preset replacement content, which is determined based on the initial source code.
[0119] The preset replacement content can be understood as a general identifier, which can indicate the meaning of the content to be modified. For example, if the content to be replaced in the initial source code is a company name, such as "*** Technology Company", the specific content to be replaced can be abstracted, and the preset replacement content corresponding to the content to be replaced can be determined to be "company name" or "company name", etc.
[0120] In one possible implementation, the content to be modified can be understood as X, the preset replacement content can be understood as Y, and the second preset conversion rule can be understood as a correspondence rule between X and Y.
[0121] In an achievable embodiment, the intermediate source code corresponding to the initial source code can be predetermined. When it is necessary to provide a modified source code to a customer, the intermediate source code corresponding to the predetermined initial source code is directly obtained, and the intermediate source code is modified to obtain a target source code that meets the customer's needs.
[0122] In this embodiment, after the intermediate source code corresponding to the initial source code is determined in advance, the corresponding relationship between the initial source code and the intermediate source code can be established. In one implementable method, the corresponding identification information can be determined, and in the process of obtaining the intermediate source code, the intermediate source code corresponding to the initial source code can be obtained according to the identification information. If the identification information corresponding to the initial source code is A0, and the identification information of the intermediate source code corresponding to the initial source code is A1, when it is necessary to obtain the source code modified based on the initial source code corresponding to the identification information A0 and provide it to the customer, the intermediate source code corresponding to the identification information A1 can be searched, and the intermediate source code found is the intermediate source code corresponding to the initial source code.
[0123] In another achievable embodiment, the intermediate source code corresponding to the initial source code can be determined in real time. For example, when a modified source code needs to be provided to a customer, the intermediate source code corresponding to the initial source code is first determined, and then the intermediate source code is modified to obtain a target source code that meets the customer's needs.
[0124] S102: Obtain a predetermined first preset conversion rule.
[0125] The first preset conversion rule includes a corresponding relationship between preset substitute content and replacement content corresponding to different customers.
[0126] Different customers have different needs, such as different customer information corresponding to different customers. When providing source code to customers, it is necessary to provide customers with source code that meets customer needs, such as source code corresponding to customer information.
[0127] In the embodiment of the present invention, different replacement contents corresponding to the preset replacement contents can be determined according to different needs of different customers, such as according to customer information of different customers. In a specific example, the preset replacement contents are the general identifier "company name" or "company name", and different replacement contents corresponding to the preset replacement contents can be determined according to different customers, such as the replacement contents corresponding to customer 1 are "company name 1", the replacement contents corresponding to customer 2 are "company name 2", the replacement contents corresponding to customer 3 are "company name 3", and so on.
[0128] In an achievable embodiment, there may be customer 1, customer 2, customer 3, customer 4, and customer 5. Replacement content 1, replacement content 2, replacement content 3, replacement content 4, and replacement content 5 corresponding to the preset replacement content may be determined, wherein replacement content 1 corresponds to customer 1, which may be understood as replacement content 1 meets the needs of customer 1, and replacement content 1 matches the customer information of customer 1; replacement content 2 corresponds to customer 2, which may be understood as replacement content 2 meets the needs of customer 2, and replacement content 2 matches the customer information of customer 2; replacement content 3 corresponds to customer 3, which may be understood as replacement content 3 meets the needs of customer 3, and replacement content 3 matches the customer information of customer 3; replacement content 4 corresponds to customer 4, which may be understood as replacement content 4 meets the needs of customer 4, and replacement content 4 matches the customer information of customer 4; replacement content 5 corresponds to customer 5, which may be understood as replacement content 5 meets the needs of customer 5, and replacement content 5 matches the customer information of customer 5.
[0129] After determining the replacement content corresponding to the preset replacement content, the correspondence between the preset replacement content and the replacement content corresponding to different customers can be saved in the form of a table, that is, the first preset conversion rule can be saved in the form of a table. As shown in Table 1 below:
[0130] Table 1
[0131]
[0132] In an implementation mode of the present invention, multiple preset replacement contents may be included, and replacement contents corresponding to different customers corresponding to each preset replacement content may be determined. The first preset conversion rule may be understood as including the correspondence between multiple preset replacement contents and replacement contents corresponding to different customers.
[0133] For example, the preset alternative content includes preset alternative content 1, preset alternative content 2, preset alternative content 3, preset alternative content 4, preset alternative content 5, etc. The alternative content corresponding to the preset alternative content 1 may include alternative content 11, alternative content 12, alternative content 13, etc.; the alternative content corresponding to the preset alternative content 2 may include alternative content 21, alternative content 22, alternative content 23, etc.; the alternative content corresponding to the preset alternative content 3 may include alternative content 31, alternative content 32, alternative content 33, etc.; the alternative content corresponding to the preset alternative content 4 may include alternative content 41, alternative content 42, alternative content 43, etc.; the alternative content corresponding to the preset alternative content 5 may include alternative content 51, alternative content 52, alternative content 53, etc. The details are shown in Table 2 below.
[0134] Table 2
[0135]
[0136] S103: According to a first preset conversion rule, replace the preset replacement content in the intermediate source code with the target replacement content to obtain the target source code.
[0137] Among them, the target replacement content corresponds to the target customer.
[0138] The correspondence between the target replacement content and the target customer can be understood as satisfying the needs of the target customer, such as the target replacement content matches the customer information of the target customer.
[0139] In one possible implementation, the preset replacement content can be understood as Y, the replacement content can be understood as Z, and the first preset conversion rule can be understood as a correspondence rule between Y and Z. The preset replacement content represents a general identifier, and modifying the preset replacement content to target replacement content corresponding to the target customer can also be understood as restoring a general identifier to specific replacement content corresponding to the target customer.
[0140] In the embodiment of the present invention, the correspondence between the preset replacement content included in the first preset rule and the replacement content corresponding to different customers can be searched to determine the target replacement content to be replaced by the preset replacement content. If the content included in the first preset conversion rule is shown in Table 2, Table 2 can be searched to determine the target replacement content corresponding to the preset replacement content.
[0141] In one possible implementation, after determining the target customer, the target replacement content corresponding to the preset replacement content and corresponding to the target customer can be determined, and the preset replacement content can be replaced with the target replacement content to obtain the target source code. When the intermediate source code includes multiple preset replacement contents, the target replacement content corresponding to the target customer and corresponding to each preset replacement content can be determined, and each preset replacement content can be replaced with the target replacement content corresponding to the preset replacement content, and then the intermediate source code including the preset replacement content can be modified to obtain the target source code.
[0142] The first preset conversion rule can be understood as a mapping relationship between an intermediate state and a target state, such as being represented by an intermediate state and a target state relationship mapping table. In one implementation of the present invention, according to the first preset conversion rule, the preset replacement content in the intermediate source code is replaced with the target replacement content, and the process of obtaining the target source code can be understood as reading the intermediate state and the target state relationship mapping table from the restoration logic, and determining the target source code according to the intermediate state and the target state relationship mapping table.
[0143] In the embodiment of the present invention, the preset replacement content included in the intermediate source code can be replaced according to the preset conversion rule including the correspondence between the preset replacement content and the replacement content corresponding to different customers, and the target source code including the target replacement content corresponding to the target customer can be obtained to modify the source code, so that the target source code corresponding to the customer can be obtained. Compared with the manual modification method, the modification efficiency of the source code can be improved.
[0144] In an optional embodiment of the present invention, step S103: replacing the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code may include:
[0145] The code restoration module replaces the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code.
[0146] That is, the electronic device can implement the replacement process through a special module, such as a code restoration module, to obtain the target source code.
[0147] Specifically, the code restoration module can obtain the intermediate source code and the first preset conversion rule, and replace the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code. In this way, functional modularization can be achieved. Further, the difficulty of maintenance can be reduced.
[0148] The embodiment of the present invention may include a process of determining an intermediate source code corresponding to an initial source code. In an optional embodiment, before step S101: obtaining the intermediate source code corresponding to the initial source code, such as Figure 2 As shown, it also includes:
[0149] S104, obtaining the initial source code.
[0150] The initial source code can be understood as the source code to be modified. Modifications are made based on the initial source code to obtain source code that meets customer requirements and provide it to the customer. If source code that meets the requirements of multiple customers is obtained, it is provided to the corresponding customers respectively.
[0151] S105, determining the content to be modified in the initial source code according to a preset search rule.
[0152] The preset search rules are determined according to business requirements. Business requirements can be determined according to actual business.
[0153] In an achievable embodiment, the content to be modified may be searched for by character matching or regular expression wildcarding according to preset search rules.
[0154] It can be understood as searching for the content to be modified from the initial source code according to the word dimension or the regular wildcard dimension.
[0155] The word dimension can be understood as searching with words as the search unit.
[0156] The regular wildcard dimension can be understood as wildcarding through regular expressions.
[0157] Regular expressions are usually used to retrieve and replace text that conforms to a certain pattern (rule). Regular expressions are a logical formula for operating on strings (including common characters (for example, letters from a to z) and special characters (called "meta-characters")). They use some pre-defined specific characters and the combination of these specific characters to form a "regular string". This "regular string" is used to express a filtering logic for strings. A regular expression is a text pattern that describes one or more strings to be matched when searching for text.
[0158] S106: According to a second preset conversion rule, the content to be modified in the initial source code is replaced with preset replacement content to obtain an intermediate source code.
[0159] The second preset conversion rule includes a correspondence between the content to be modified and the preset replacement content.
[0160] After determining the content to be modified in the initial source code, the preset replacement content corresponding to the content to be modified can be determined. In one implementation, the preset replacement content corresponding to the content to be modified can be saved in the form of a table, that is, the second preset conversion rule can be saved in the form of a table. As shown in Table 3.
[0161] Table 3
[0162] Content to be modified Preset Alternative Content Content to be modified 1 Default alternative content 1 Content to be modified 2 Default Alternative Content 2 Content to be modified 3 Default alternative content 3 … …
[0163] In an embodiment of the present invention, the initial source code is modified into an intermediate source code including preset replacement symbols. When the target source code is to be provided to the customer, the intermediate source code can be modified according to the first preset conversion rule to obtain the target source code that meets the customer's needs.
[0164] In this way, the source code can be automatically modified, the efficiency of source code modification can be improved, and the intermediate source code can be generated by maintaining fixed conversion rules to meet the needs of different target customers. It is simple to maintain and easy to update, and can save the labor cost of manual code modification. At the same time, the coupling can be released. When different customers are targeted to obtain target source code that meets the needs of different customers, they can be modified separately through the intermediate source code, that is, when modifying the source code for different customers, it will not affect the process of modifying the source code for other customers.
[0165] In an optional embodiment of the present invention, step S106: replacing the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code may include:
[0166] The code modification module replaces the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code.
[0167] That is, the electronic device can implement code modification through a dedicated module, such as a code modification module, to obtain an intermediate source code.
[0168] Specifically, the electronic device inputs the initial source code and the second preset conversion rule into the code modification module, and the code modification module obtains the initial source code and the second preset conversion rule, determines the content to be modified in the initial source code according to the preset search rule, and replaces the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code. In this way, functional modularization can be achieved. Further, the difficulty of maintenance can be reduced.
[0169] In an achievable embodiment, the initial source code may be added or deleted, that is, logic may be added to the initial source code or unnecessary logic may be deleted. Figure 3 As shown, it may include:
[0170] S301, determining content to be added and / or content to be deleted.
[0171] In one possible implementation, the content to be added and / or the content to be deleted may be determined according to the file dimension. In another possible implementation, the content to be added and / or the content to be deleted may be determined according to the row interval dimension. Alternatively, the content to be added and / or the content to be deleted may be determined according to both the file dimension and the row interval dimension.
[0172] The file dimension can be understood as taking files as search units to search for files to be added and / or files to be deleted.
[0173] The row interval dimension can be understood as taking rows as search units to search for rows to be added and / or rows to be deleted.
[0174] S302: adding content to be added to the initial source code, and / or deleting content to be deleted from the initial source code.
[0175] Specifically, the content to be added and / or the content to be deleted may be determined according to the file dimension; the content to be added may be added to the initial source code, and / or the content to be deleted may be deleted from the initial source code. Alternatively, the content to be added and / or the content to be deleted may be determined according to the row interval dimension; the content to be added may be added to the initial source code, and / or the content to be deleted may be deleted from the initial source code. Alternatively, the content to be added and / or the content to be deleted may be determined according to the file dimension and the row interval dimension, the content to be added may be added to the initial source code, and / or the content to be deleted may be deleted from the initial source code.
[0176] In one possible implementation, determining content to be added and / or content to be deleted, adding the content to be added to the initial source code, and / or deleting the content to be deleted from the initial source code can be understood as pruning the initial source code using a pruning tool.
[0177] Corresponding to the software source code modification method provided in the above embodiment, the embodiment of the present invention provides a software source code modification device, such as Figure 4 As shown, it may include:
[0178] The first acquisition module 401 is used to acquire an intermediate source code corresponding to the initial source code; the intermediate source code includes a preset replacement content, which is determined according to the content to be modified in the initial source code; acquire a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between the preset replacement content and the replacement content corresponding to different customers;
[0179] The modification module 402 is used to replace the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code, wherein the target replacement content corresponds to the target client.
[0180] In the embodiment of the present invention, the preset replacement content included in the intermediate source code can be replaced according to the preset conversion rule including the correspondence between the preset replacement content and the replacement content corresponding to different customers, so as to obtain the target source code including the target replacement content corresponding to the target customer, so as to realize the modification of the source code. Compared with the manual modification method, the modification efficiency of the source code can be improved.
[0181] Optional, such as Figure 5 As shown, the device also includes:
[0182] The second acquisition module 501 is used to acquire the initial source code;
[0183] A first determination module 502 is used to determine the content to be modified in the initial source code according to a preset search rule; wherein the preset search rule is determined according to business requirements;
[0184] The replacement module 503 is used to replace the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code; wherein the second preset conversion rule includes the correspondence between the content to be modified and the preset replacement content.
[0185] Optionally, the first determination module 404 is specifically configured to search for the content to be modified according to a preset search rule by character matching or regular expression wildcarding.
[0186] Optional, such as Figure 6 As shown, the device also includes:
[0187] The second determination module 601 is used to determine the content to be added and / or the content to be deleted according to the file dimension;
[0188] The first adding module 602 is used to add the content to be added to the initial source code; and / or,
[0189] The first deleting module 603 is used to delete the content to be deleted from the initial source code.
[0190] Optional, such as Figure 7 As shown, the device may also include:
[0191] The third determination module 701 is used to determine the content to be added and / or the content to be deleted according to the row interval dimension;
[0192] The second adding module 702 is used to add the content to be added to the initial source code; and / or,
[0193] The second deleting module 703 is used to delete the content to be deleted from the initial source code.
[0194] Optionally, the modification module 402 is specifically configured to replace preset replacement content in the intermediate source code with target replacement content according to a first preset conversion rule through the code restoration module to obtain a target source code.
[0195] Optionally, the replacement module 503 is specifically configured to replace the content to be modified in the initial source code with preset replacement content according to a second preset conversion rule through the code modification module to obtain an intermediate source code.
[0196] The software source code modification device provided in the embodiment of the present invention is a device applying the above-mentioned software source code modification method, and all embodiments of the above-mentioned software source code modification method are applicable to the device and can achieve the same or similar beneficial effects.
[0197] Corresponding to the software source code modification method provided in the above embodiment, the embodiment of the present invention further provides an electronic device, such as Figure 8As shown, it includes a processor 801 , a communication interface 802 , a memory 803 and a communication bus 804 , wherein the processor 801 , the communication interface 802 , and the memory 803 communicate with each other via the communication bus 804 .
[0198] Memory 803, used for storing computer programs;
[0199] The processor 801 is used to execute the program stored in the memory 803, and implements the following steps:
[0200] Obtaining an intermediate source code corresponding to the initial source code; the intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code;
[0201] Acquire a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between preset replacement content and replacement content corresponding to different customers;
[0202] According to the first preset conversion rule, the preset replacement content in the intermediate source code is replaced with the target replacement content to obtain the target source code, wherein the target replacement content corresponds to the target client.
[0203] In the embodiment of the present invention, the preset replacement content included in the intermediate source code can be replaced according to the preset conversion rule including the correspondence between the preset replacement content and the replacement content corresponding to different customers, so as to obtain the target source code including the target replacement content corresponding to the target customer, so as to realize the modification of the source code. Compared with the manual modification method, the modification efficiency of the source code can be improved.
[0204] Optionally, before obtaining the intermediate source code corresponding to the initial source code, the following may also be included:
[0205] Get the initial source code;
[0206] Determine the content to be modified in the initial source code according to the preset search rules; wherein the preset search rules are determined according to business requirements;
[0207] According to the second preset conversion rule, the content to be modified in the initial source code is replaced with the preset replacement content to obtain the intermediate source code; wherein the second preset conversion rule includes the correspondence between the content to be modified and the preset replacement content.
[0208] Optionally, the content to be modified in the initial source code is determined according to a preset search rule, including:
[0209] According to the preset search rules, search for the content to be modified by character matching or regular wildcarding.
[0210] Optionally, after obtaining the initial source code, you can also include:
[0211] According to the file dimensions, determine the content to be added and / or deleted;
[0212] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0213] Optionally, after obtaining the initial source code, you can also include:
[0214] Determine the content to be added and / or deleted according to the row interval dimension;
[0215] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0216] Optionally, according to a first preset conversion rule, replacing preset replacement content in the intermediate source code with target replacement content to obtain a target source code includes:
[0217] The code restoration module replaces the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code.
[0218] Optionally, according to a second preset conversion rule, the content to be modified in the initial source code is replaced with preset replacement content to obtain an intermediate source code, including:
[0219] The code modification module replaces the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code.
[0220] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0221] The communication interface is used for communication between the above electronic device and other devices.
[0222] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0223] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0224] Corresponding to the software source code modification method provided in the above embodiment, an embodiment of the present invention provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the following method steps are performed:
[0225] Obtaining an intermediate source code corresponding to the initial source code; the intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code;
[0226] Acquire a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between preset replacement content and replacement content corresponding to different customers;
[0227] According to the first preset conversion rule, the preset replacement content in the intermediate source code is replaced with the target replacement content to obtain the target source code, wherein the target replacement content corresponds to the target client.
[0228] In the embodiment of the present invention, the preset replacement content included in the intermediate source code can be replaced according to the preset conversion rule including the correspondence between the preset replacement content and the replacement content corresponding to different customers, so as to obtain the target source code including the target replacement content corresponding to the target customer, so as to realize the modification of the source code. Compared with the manual modification method, the modification efficiency of the source code can be improved.
[0229] Optionally, before obtaining the intermediate source code corresponding to the initial source code, the following may also be included:
[0230] Get the initial source code;
[0231] Determine the content to be modified in the initial source code according to the preset search rules; wherein the preset search rules are determined according to business requirements;
[0232] According to the second preset conversion rule, the content to be modified in the initial source code is replaced with the preset replacement content to obtain the intermediate source code; wherein the second preset conversion rule includes the correspondence between the content to be modified and the preset replacement content.
[0233] Optionally, the content to be modified in the initial source code is determined according to a preset search rule, including:
[0234] According to the preset search rules, search for the content to be modified by character matching or regular wildcarding.
[0235] Optionally, after obtaining the initial source code, you can also include:
[0236] According to the file dimensions, determine the content to be added and / or deleted;
[0237] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0238] Optionally, after obtaining the initial source code, you can also include:
[0239] Determine the content to be added and / or deleted according to the row interval dimension;
[0240] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0241] Optionally, according to a first preset conversion rule, replacing preset replacement content in the intermediate source code with target replacement content to obtain a target source code includes:
[0242] The code restoration module replaces the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code.
[0243] Optionally, according to a second preset conversion rule, the content to be modified in the initial source code is replaced with preset replacement content to obtain an intermediate source code, including:
[0244] The code modification module replaces the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code.
[0245] Corresponding to the software source code modification method provided in the above embodiment, an embodiment of the present invention provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the following method steps:
[0246] Obtaining an intermediate source code corresponding to the initial source code; the intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code;
[0247] Acquire a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between preset replacement content and replacement content corresponding to different customers;
[0248] According to the first preset conversion rule, the preset replacement content in the intermediate source code is replaced with the target replacement content to obtain the target source code, wherein the target replacement content corresponds to the target client.
[0249] In the embodiment of the present invention, the preset replacement content included in the intermediate source code can be replaced according to the preset conversion rule including the correspondence between the preset replacement content and the replacement content corresponding to different customers, so as to obtain the target source code including the target replacement content corresponding to the target customer, so as to realize the modification of the source code. Compared with the manual modification method, the modification efficiency of the source code can be improved.
[0250] Optionally, before obtaining the intermediate source code corresponding to the initial source code, the following may also be included:
[0251] Get the initial source code;
[0252] Determine the content to be modified in the initial source code according to the preset search rules; wherein the preset search rules are determined according to business requirements;
[0253] According to the second preset conversion rule, the content to be modified in the initial source code is replaced with the preset replacement content to obtain the intermediate source code; wherein the second preset conversion rule includes the correspondence between the content to be modified and the preset replacement content.
[0254] Optionally, the content to be modified in the initial source code is determined according to a preset search rule, including:
[0255] According to the preset search rules, search for the content to be modified by character matching or regular wildcarding.
[0256] Optionally, after obtaining the initial source code, you can also include:
[0257] According to the file dimensions, determine the content to be added and / or deleted;
[0258] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0259] Optionally, after obtaining the initial source code, you can also include:
[0260] Determine the content to be added and / or deleted according to the row interval dimension;
[0261] Add the content to be added to the initial source code, and / or delete the content to be deleted from the initial source code.
[0262] Optionally, according to a first preset conversion rule, replacing preset replacement content in the intermediate source code with target replacement content to obtain a target source code includes:
[0263] The code restoration module replaces the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code.
[0264] Optionally, according to a second preset conversion rule, the content to be modified in the initial source code is replaced with preset replacement content to obtain an intermediate source code, including:
[0265] The code modification module replaces the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code.
[0266] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0267] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, electronic device, storage medium and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0268] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A method for modifying software source code, characterized in that: include: Obtain the intermediate source code corresponding to the initial source code; The intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code; Acquire a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between the preset replacement content and replacement content corresponding to different customers; According to the first preset conversion rule, the preset replacement content in the intermediate source code is replaced with the target replacement content to obtain the target source code, wherein the target replacement content corresponds to the target customer; Before obtaining the intermediate source code corresponding to the initial source code, the method further includes: Obtaining the initial source code; Determine the content to be modified in the initial source code according to a preset search rule; wherein the preset search rule is determined according to business requirements; According to a second preset conversion rule, the content to be modified in the initial source code is replaced with preset replacement content to obtain the intermediate source code; wherein the second preset conversion rule includes a correspondence between the content to be modified and the preset replacement content.
2. The method according to claim 1, characterized in that The step of determining the content to be modified in the initial source code according to a preset search rule includes: According to the preset search rule, the content to be modified is searched by character matching or regular expression wildcarding.
3. The method according to claim 1, characterized in that: After obtaining the initial source code, the method further includes: According to the file dimensions, determine the content to be added and / or deleted; The content to be added is added to the initial source code, and / or the content to be deleted is deleted from the initial source code.
4. The method according to claim 1, characterized in that: After obtaining the initial source code, the method further includes: Determine the content to be added and / or deleted according to the row interval dimension; The content to be added is added to the initial source code, and / or the content to be deleted is deleted from the initial source code.
5. The method according to claim 1, characterized in that The step of replacing the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code includes: The code restoration module replaces the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule to obtain the target source code.
6. The method according to claim 1, characterized in that The step of replacing the content to be modified in the initial source code with preset replacement content according to the second preset conversion rule to obtain the intermediate source code includes: The code modification module replaces the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule to obtain the intermediate source code.
7. A software source code modification device, characterized in that: include: A first acquisition module is used to acquire an intermediate source code corresponding to the initial source code; The intermediate source code includes preset replacement content, and the preset replacement content is determined according to the content to be modified in the initial source code; obtaining a predetermined first preset conversion rule; wherein the first preset conversion rule includes a correspondence between the preset replacement content and replacement content corresponding to different customers; a modification module, configured to replace the preset replacement content in the intermediate source code with target replacement content according to the first preset conversion rule, to obtain a target source code, wherein the target replacement content corresponds to a target customer; The device also includes: A second acquisition module, used to acquire the initial source code; A first determination module, configured to determine the content to be modified in the initial source code according to a preset search rule; wherein the preset search rule is determined according to business requirements; A replacement module is used to replace the content to be modified in the initial source code with preset replacement content according to a second preset conversion rule to obtain the intermediate source code; wherein the second preset conversion rule includes the corresponding relationship between the content to be modified and the preset replacement content.
8. The device according to claim 7, characterized in that The first determination module is specifically used to search for the content to be modified according to the preset search rule through character matching or regular expression wildcarding.
9. The device according to claim 7, characterized in that The device also includes: A second determination module, used to determine content to be added and / or content to be deleted according to the file dimension; A first adding module is used to add the content to be added to the initial source code; and / or, The first deleting module is used to delete the content to be deleted from the initial source code.
10. The device according to claim 7, characterized in that The device also includes: A third determination module is used to determine the content to be added and / or the content to be deleted according to the row interval dimension; A second adding module is used to add the content to be added to the initial source code; and / or, The second deleting module is used to delete the content to be deleted from the initial source code.
11. The device according to claim 7, characterized in that The modification module is specifically configured to replace the preset replacement content in the intermediate source code with the target replacement content according to the first preset conversion rule through the code restoration module to obtain the target source code.
12. The device according to claim 7, characterized in that The replacement module is specifically configured to replace the content to be modified in the initial source code with the preset replacement content according to the second preset conversion rule through the code modification module to obtain the intermediate source code.
13. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is used to store computer programs; The processor is used to implement the method steps described in any one of claims 1-6 when executing the program stored in the memory.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 6 are implemented.