CN108255490B - Hard code processing method and device - Google Patents

Hard code processing method and device Download PDF

Info

Publication number
CN108255490B
CN108255490B CN201611233716.1A CN201611233716A CN108255490B CN 108255490 B CN108255490 B CN 108255490B CN 201611233716 A CN201611233716 A CN 201611233716A CN 108255490 B CN108255490 B CN 108255490B
Authority
CN
China
Prior art keywords
hard
code
codes
processing
preset
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201611233716.1A
Other languages
Chinese (zh)
Other versions
CN108255490A (en
Inventor
谢永骏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN201611233716.1A priority Critical patent/CN108255490B/en
Publication of CN108255490A publication Critical patent/CN108255490A/en
Application granted granted Critical
Publication of CN108255490B publication Critical patent/CN108255490B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention relates to the field of source code processing tools and provides a hard code processing method and device. The processing method of hard coding comprises the following steps: carrying out hard coding detection on the target code according to preset hard coding characteristics; replacing the detected hard code with a logo code; acquiring a preset processing rule corresponding to the hard code; and establishing a calling relationship between the mark codes and the acquired processing rules so as to call the corresponding processing rules according to the calling relationship when the target codes are executed to the mark codes. In the embodiment of the invention, the hard codes are detected, and then the detected hard codes are replaced by the mark codes, so that the processing rules corresponding to the hard codes are called when the target codes are executed to the mark codes, the hard codes are sorted and modified, meanwhile, the situations of omission or error processing are avoided, the hard code sorting and modifying efficiency is improved, and the difficulty of later code maintenance is also reduced.

Description

Hard code processing method and device
Technical Field
The present invention relates to the field of source code processing tools, and in particular, to a method and an apparatus for processing hard codes.
Background
Hard coding refers to a method for replacing a variable with a fixed value during computer programming, and if the variable is to be modified after compiling, each hard coding needs to be modified one by one in a source program, so that the workload is huge and errors are easy to occur.
Generally, codes in a system are hard-coded more or less, so how to effectively process hard coding is an urgent problem to be solved. At present, the most common method for processing hard codes is manual processing, omission or error processing is easy to occur in the processing process, and the processing efficiency is low; in addition, the processing mode and the programming style of each programmer are different, and the maintenance difficulty of the code after hard coding processing is also very large.
Disclosure of Invention
The embodiment of the invention provides a hard code processing method, which can retrieve and replace hard codes in a target program, and the corresponding hard code processing rules can be flexibly and conveniently modified.
A first aspect of an embodiment of the present invention provides a method for processing hard codes, including:
carrying out hard coding detection on the target code according to preset hard coding characteristics;
replacing the detected hard code with a logo code;
acquiring a preset processing rule corresponding to the hard code;
and establishing a calling relationship between the mark codes and the acquired processing rules so as to call the corresponding processing rules according to the calling relationship when the target codes are executed to the mark codes.
A second aspect of the embodiments of the present invention provides a hard-coded processing apparatus, including:
the detection unit is used for carrying out hard coding detection on the target code according to the preset hard coding characteristics;
a replacement unit configured to replace the detected hard code with a flag code;
an obtaining unit, configured to obtain a preset processing rule corresponding to the hard code;
and the establishing unit is used for establishing a calling relationship between the mark codes and the acquired processing rules so as to call the corresponding processing rules according to the calling relationship when the target codes are executed to the mark codes.
In the embodiment of the invention, the target code is subjected to hard coding detection according to the preset hard coding characteristics; replacing the detected hard code with a logo code; acquiring a preset processing rule corresponding to the hard code; and establishing a calling relationship between the mark codes and the acquired processing rules so as to call the corresponding processing rules according to the calling relationship when the target codes are executed to the mark codes. In the embodiment of the invention, the hard codes are detected, and then the detected hard codes are replaced by the mark codes, so that the processing rules corresponding to the hard codes are called when the target codes are executed to the mark codes, the hard codes are sorted and modified, meanwhile, the situations of omission or error processing are avoided, the hard code sorting and modifying efficiency is improved, and the difficulty of later code maintenance is also reduced. In addition, when the processing rule of the hard code is modified, the processing rule can be modified in the preset processing rule corresponding to the hard code, and the calling relationship between the mark code and the preset processing rule can also be modified, so that the modification process is flexible and convenient.
Drawings
FIG. 1 is a flow chart of a hard-coded processing method according to a first embodiment of the present invention;
FIG. 2 is a flow chart of a hard-coded processing method according to a second embodiment of the present invention;
FIG. 3 is a flowchart of a hard-coded processing method according to a third embodiment of the present invention;
FIG. 4 is a block diagram of a first embodiment of a hard-coded processing device in accordance with an embodiment of the present invention;
FIG. 5 is a block diagram of a hard-coded processing device according to a second embodiment of the present invention;
FIG. 6 is a block diagram of a hard-coded processing device according to a third embodiment of the present invention.
Detailed Description
The embodiment of the invention provides a hard code processing method and device, which can retrieve and replace hard codes in a target program, and can flexibly and conveniently modify corresponding hard code processing rules.
In order to make the objects, features and advantages of the present invention more obvious and understandable, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is obvious that the embodiments described below are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a first embodiment of a hard coding processing method according to the present invention includes:
101. carrying out hard coding detection on the target code according to preset hard coding characteristics;
in this embodiment, first, the target code may be subjected to hard-coded detection according to a preset hard-coded feature.
The hard code is a method of replacing a variable with a fixed value when a computer is programmed, and for example, if (a) is replaced with if (a) 2. The preset hard-coded features may be specific characters in the program segment in which the hard-coded characters are located, for example, if or in (') in the SQL program. By means of the specific characters in these object codes it is possible to locate exactly which characters or codes belong to the hard code.
In addition, the object code may refer to a code to be processed including hard code, or may be a program file written by using various programming languages, such as C, C + +, assembly, or source code written by using a programming language such as SQL. The target code can be designated by an operator or automatically selected by a computer within a preset time and/or a preset storage space.
In this embodiment, the target code may be detected according to a preset hard coding feature, and if it is detected that a certain section of program in the target code includes the preset hard coding feature, it is determined that the program section includes hard coding.
102. Replacing the detected hard code with a logo code;
after the target code is subjected to hard coding detection according to the preset hard coding characteristics, the detected hard coding can be replaced by the mark coding.
The above-mentioned flag code may be a unique code for each hard code to distinguish the respective hard codes in the object program. For example, P1 and P2 are two flag codes, and P1 can be used to represent the first hard code in the object program and P2 can be used to represent the second hard code in the object program.
After detecting the hard code in the target program, replacing the hard code with a flag code. For example, the target program has hard codes "a ═ 2", "3.14 ═ r" and "c ≦ 70", and the non-hard codes "s ═ pi ×. r" are detected in step 101, then the hard codes "a ═ 2", "3.14 ═ r" and "c ≦ 70" are detected, and step 102 is executed to replace the hard codes with the flag codes P1, P2 and P3, respectively, while the non-hard codes "s ═ pi ×. r" are not detected in step 101.
Further, in order to more intuitively and conveniently represent the hard code and the position thereof in the target program, the step 102 may further include:
acquiring the position information of the hard code in the target code;
and coding the position information to obtain the mark code.
The marker code may contain position information hard-coded in the object code. If the position of the hard code 1 in the target program is a and the position of the hard code 2 in the target program is b, encoding the position information a and b to obtain the corresponding mark codes which can be marked as Pa and Pb respectively, so that the mark codes not only uniquely represent each hard code in the target program, but also clearly indicate the position of each hard code in the target program, thereby facilitating searching.
103. Acquiring a preset processing rule corresponding to the hard code;
after the hard code is detected, a preset processing rule corresponding to the hard code may be acquired. It is understood that, in this embodiment, step 103 may be performed before step 102, or may be performed after step 102.
The processing rule mentioned above is a rule according to which the hard code is processed, and the setting of the processing rule should be completed before the hard code is processed.
Further, the step 103 may include:
carrying out logic analysis on the hard code to obtain an analysis result;
and selecting a corresponding processing rule from a preset processing rule set according to the analysis result.
The analysis result obtained by logically analyzing the hard codes is the basis for selecting the corresponding processing rule by the hard codes, each hard code has own logical characteristics, and a reasonable processing rule can be selected for processing according to the logical characteristics. The preset processing rules may be grouped in a set of processing rules, which may be preset by the relevant personnel, and which more fully contain various types of hard-coded processing rules, which may be stored in various types of memory.
104. And establishing a calling relationship between the mark codes and the acquired processing rules so as to call the corresponding processing rules according to the calling relationship when the target codes are executed to the mark codes.
After the preset processing rule corresponding to the hard code is obtained, a calling relationship between the mark code and the obtained processing rule can be established, so that the target code calls the corresponding processing rule according to the calling relationship when the mark code is executed. And after the calling is finished, returning a calling operation result, and executing the next instruction by the target code in sequence.
For example, there are 3 flag codes P1, P2, and P3, and if the acquired processing rules are regular A, B and C, and a call relationship as shown in table 1 can be established between the flag codes and the processing rules, the processing is performed on behalf of the hard code call processing rule a in the target program corresponding to the flag code P1, the hard code call processing rule B in the target program corresponding to the flag code P2, and the hard code call processing rule C in the target program corresponding to the flag code P3. And after the calling is finished, returning a calling operation result, and executing the next instruction by the target code in sequence.
TABLE 1
P1 Rule A
P2 Rule B
P3 Rule C
Furthermore, since a hard code may have a plurality of processing rules in advance, one flag code may establish a call relationship with a plurality of the processing rules.
For example, for a certain flag code P1, 3 obtained processing rules A, B and C may be all called up with P1, as shown in table 2.
TABLE 2
P1 Rule A
P1 Rule B
P1 Rule C
Table 2 shows that there are 3 processing rules A, B and C that can be used for the hard code in the target program corresponding to the flag code P1, and at this time, one of the processing rules may be first selected according to a preset manner, and then the hard code in the target program corresponding to the flag code P1 is processed according to the selected processing rule. The preset mode may be to select the first one in sequence, may be to select the first one randomly, or may be to pop up a selection box, and the operator selects a certain processing rule.
Further, in order to more clearly and intuitively reflect the correspondence among the hard code, the flag code, and the hard code processing rule, and at the same time, to allow the correspondence among them to be easily modified, the correspondence among the hard code, the flag code, and the hard code processing rule may be written into a database. The corresponding relation among the three is clearly embodied in the form of a table in the database, and the searching and the modifying can be conveniently carried out. And because the position mark corresponding to each hard code is unique, even aiming at the hard codes of the same type, the processing can be carried out according to different hard code processing rules, and the processing mode is very flexible.
For example, if there are 3 hard codes "a ═ 2", "3.14 × r", and "C ≦ 70", the flag codes corresponding thereto are P1, P2, and P3, respectively, and the hard code processing rules for establishing call relationships with the flag codes P1, P2, and P3 are A, B and C, respectively, the information shown in table 3 can be written in the database.
TABLE 3
Hard coding Sign encoding Hard coding processing rules
a==2 P1 Rule A
3.14*r*r P2 Rule B
c≤70 P3 Rule C
As can be seen from table 3, the corresponding hard-coding processing rule can be easily modified for each hard-coding without being limited by the same type of hard-coding.
In the embodiment of the invention, the target code is subjected to hard coding detection according to the preset hard coding characteristics; replacing the detected hard code with a logo code; acquiring a preset processing rule corresponding to the hard code; and establishing a calling relationship between the mark codes and the acquired processing rules so as to call the corresponding processing rules according to the calling relationship when the target codes are executed to the mark codes. In the embodiment of the invention, the hard codes are detected, and then the detected hard codes are replaced by the mark codes, so that the processing rules corresponding to the hard codes are called when the target codes are executed to the mark codes, the hard codes are sorted and modified, meanwhile, the situations of omission or error processing are avoided, the hard code sorting and modifying efficiency is improved, and the difficulty of later code maintenance is also reduced. In addition, when the processing rule of the hard code is modified, the processing rule can be modified in the preset processing rule corresponding to the hard code, and the calling relationship between the mark code and the preset processing rule can also be modified, so that the modification process is flexible and convenient.
Referring to fig. 2, a second embodiment of a hard coding processing method according to the present invention includes:
201. carrying out hard coding detection on the target code according to preset hard coding characteristics;
in this embodiment, first, the target code may be subjected to hard-coded detection according to a preset hard-coded feature.
The hard code is a method of replacing a variable with a fixed value when a computer is programmed, and for example, if (a) is replaced with if (a) 2. The preset hard-coded features may be specific characters in the program segment in which the hard-coded characters are located, for example, if or in (') in the SQL program. By means of the specific characters in these object codes it is possible to locate exactly which characters or codes belong to the hard code.
In addition, the object code may refer to a code to be processed including hard code, or may be a program file written by using various programming languages, such as C, C + +, assembly, or source code written by using a programming language such as SQL. The target code can be designated by an operator or automatically selected by a computer within a preset time and/or a preset storage space.
In this embodiment, the target code may be detected according to a preset hard coding feature, and if it is detected that a certain section of program in the target code includes the preset hard coding feature, it is determined that the program section includes hard coding.
202. Replacing the detected hard code with a logo code;
after the target code is subjected to hard coding detection according to the preset hard coding characteristics, the detected hard coding can be replaced by the mark coding.
The above-mentioned flag code may be a unique code for each hard code to distinguish the respective hard codes in the object program. For example, P1 and P2 are two flag codes, and P1 can be used to represent the first hard code in the object program and P2 can be used to represent the second hard code in the object program.
After detecting the hard code in the target program, replacing the hard code with a flag code. For example, the target program has hard codes "a ═ 2", "3.14 ═ r" and "c ≦ 70", and the non-hard codes "s ═ pi ×. r" are detected in step 201, then the hard codes "a ═ 2", "3.14 ═ r" and "c ≦ 70" are detected, and then step 202 is executed to replace the hard codes with the flag codes P1, P2 and P3, respectively, while the non-hard codes "s ═ pi ×. r" are not detected in step 201.
Further, in order to more intuitively and conveniently represent the hard code and the position thereof in the target program, the step 202 may further include:
acquiring the position information of the hard code in the target code;
and coding the position information to obtain the mark code.
The marker code may contain position information hard-coded in the object code. If the position of the hard code 1 in the target program is a and the position of the hard code 2 in the target program is b, encoding the position information a and b to obtain the corresponding mark codes which can be marked as Pa and Pb respectively, so that the mark codes not only uniquely represent each hard code in the target program, but also clearly indicate the position of each hard code in the target program, thereby facilitating searching.
203. Acquiring a preset processing rule corresponding to the hard code, executing step 204 if the preset processing rule is not acquired after a preset event is triggered, and executing step 205 if the processing rule is acquired;
and replacing the detected hard code with a mark code to obtain a preset processing rule corresponding to the hard code.
The processing rule mentioned above is a rule according to which the hard code is processed, and the setting of the processing rule should be completed before the hard code is processed.
Further, the step 203 may include:
carrying out logic analysis on the hard code to obtain an analysis result;
and selecting a corresponding processing rule from a preset processing rule set according to the analysis result.
The analysis result obtained by logically analyzing the hard codes is the basis for selecting the corresponding processing rule by the hard codes, each hard code has own logical characteristics, and a reasonable processing rule can be selected for processing according to the logical characteristics. The preset processing rules may be grouped in a set of processing rules, which may be preset by the relevant personnel, and which more fully contain various types of hard-coded processing rules, which may be stored in various types of memory.
Since the preset processing rule set may not include the preset processing rules corresponding to all hard codes, the preset processing rules may not be obtained in step 203. If the preset processing rule is acquired, step 205 is executed, and if the preset processing rule is not acquired after a preset event is triggered, step 204 is executed. The preset event may be triggered after a preset time period elapses, or after the processing rule that fails for a specified number of times is acquired.
204. Restoring the corresponding mark code in the target code into the hard code;
for some hard codes, there may be no corresponding processing rule preset, and at this time, the call relationship between the flag code and the obtained processing rule cannot be established, and the hard code cannot be processed. For these hard codes, the flag codes corresponding to these hard codes in the target code may be restored to ensure the normal operation of the target code. The preset event may be triggered after a preset time period elapses, or after the processing rule that fails for a specified number of times is acquired. For example, for a hard code "3.14 × r" (the corresponding flag code is Px), assuming that the processing rule corresponding to the hard code is not preset, after a preset time (e.g. 2 seconds) or after the processing rule fails to be obtained for a specified number of times (e.g. 5 times), Px may be restored to "3.14 × r" in the target code, thereby ensuring the normal operation of the target code.
Because the preset processing rule may not cover all the hard-coded processing rules, when the hard code without the preset processing rule appears, the corresponding mark code can be restored to the hard code, so that the integrity and the accuracy of the processing method can be ensured, and the normal operation of the target code is prevented from being influenced.
205. And establishing a calling relationship between the mark codes and the acquired processing rules so as to call the corresponding processing rules according to the calling relationship when the target codes are executed to the mark codes.
If the preset processing rule corresponding to the hard code is obtained in step 203, a call relationship between the flag code and the obtained processing rule may be established, so that the target code calls the corresponding processing rule according to the call relationship when the target code is executed to the flag code.
And establishing a calling relation between the mark codes and the acquired processing rules, so that when the target code is executed to the mark codes, the corresponding processing rules can be called according to the calling relation, and the corresponding hard codes are processed.
For example, there are 3 flag codes P1, P2, and P3, and the acquired processing rules are regular A, B and C, and if a call relationship as shown in table 4 can be established between the flag codes and the processing rules, it represents that the hard code in the target program corresponding to the flag code P1 is processed according to the processing rule a, the hard code in the target program corresponding to the flag code P2 is processed according to the processing rule B, and the hard code in the target program corresponding to the flag code P3 is processed according to the processing rule C.
TABLE 4
P1 Rule A
P2 Rule B
P3 Rule C
Furthermore, since a hard code may have a plurality of processing rules in advance, one flag code may establish a call relationship with a plurality of the processing rules.
For example, for a certain flag code P1, 3 obtained processing rules A, B and C may be all called up with P1, as shown in table 5.
TABLE 5
P1 Rule A
P1 Rule B
P1 Rule C
Table 5 shows that there are 3 processing rules A, B and C that can be followed by the hard code in the target program corresponding to the flag code P1, and then one of the processing rules can be selected first according to a preset manner, and then the hard code in the target program corresponding to the flag code P1 is processed according to the selected processing rule. The preset mode may be to select the first one in sequence, may be to select the first one randomly, or may be to pop up a selection box, and the operator selects a certain processing rule.
Further, in order to more clearly and intuitively reflect the correspondence among the hard code, the flag code, and the hard code processing rule, and at the same time, to allow the correspondence among them to be easily modified, the correspondence among the hard code, the flag code, and the hard code processing rule may be written into a database. The corresponding relation among the three is clearly embodied in the form of a table in the database, and the searching and the modifying can be conveniently carried out. And because the position mark corresponding to each hard code is unique, even aiming at the hard codes of the same type, the processing can be carried out according to different hard code processing rules, and the processing mode is very flexible.
For example, if there are 3 hard codes "a ═ 2", "3.14 × r", and "C ≦ 70", the flag codes corresponding thereto are P1, P2, and P3, respectively, and the hard code processing rules for establishing call relationships with the flag codes P1, P2, and P3 are A, B and C, respectively, the information shown in table 6 can be written in the database.
TABLE 6
Hard coding Sign encoding Hard coding processing rules
a==2 P1 Rule A
3.14*r*r P2 Rule B
c≤70 P3 Rule C
As can be seen from table 6, the corresponding hard-coding processing rule can be easily modified for each hard-coding without being limited by the same type of hard-coding.
In the embodiment of the invention, the target code is subjected to hard coding detection according to the preset hard coding characteristics; replacing the detected hard code with a logo code; acquiring a preset processing rule corresponding to the hard code; if the preset processing rule corresponding to the hard code is not acquired after the preset event is triggered, restoring the mark code corresponding to the target code into the hard code; and establishing a calling relationship between the mark codes and the acquired processing rules so as to call the corresponding processing rules according to the calling relationship when the target codes are executed to the mark codes. When the hard code without the preset processing rule appears, the corresponding mark code can be restored to the hard code, so that the integrity and the accuracy of the processing method can be ensured, and the normal operation of the target code is prevented from being influenced. In the embodiment of the invention, the hard codes are detected, and then the detected hard codes are replaced by the mark codes, so that the processing rules corresponding to the hard codes are called when the target codes are executed to the mark codes, the hard codes are sorted and modified, meanwhile, the situations of omission or error processing are avoided, the hard code sorting and modifying efficiency is improved, and the difficulty of later code maintenance is also reduced. In addition, when the processing rule of the hard code is modified, the processing rule can be modified in the preset processing rule corresponding to the hard code, and the calling relationship between the mark code and the preset processing rule can also be modified, so that the modification process is flexible and convenient.
Referring to fig. 3, a third embodiment of a hard coding processing method according to the present invention includes:
301. carrying out hard coding detection on the target code according to preset hard coding characteristics;
in this embodiment, first, the target code may be subjected to hard-coded detection according to a preset hard-coded feature.
The hard code is a method of replacing a variable with a fixed value when a computer is programmed, and for example, if (a) is replaced with if (a) 2. The preset hard-coded features may be specific characters in the program segment in which the hard-coded characters are located, for example, if or in (') in the SQL program. By means of the specific characters in these object codes it is possible to locate exactly which characters or codes belong to the hard code.
In addition, the object code may refer to a code to be processed including hard code, or may be a program file written by using various programming languages, such as C, C + +, assembly, or source code written by using a programming language such as SQL. The target code can be designated by an operator or automatically selected by a computer within a preset time and/or a preset storage space.
In this embodiment, the target code may be detected according to a preset hard coding feature, and if it is detected that a certain section of program in the target code includes the preset hard coding feature, it is determined that the program section includes hard coding.
302. Replacing the detected hard code with a logo code;
after the target code is subjected to hard coding detection according to the preset hard coding characteristics, the detected hard coding can be replaced by the mark coding.
The above-mentioned flag code may be a unique code for each hard code to distinguish the respective hard codes in the object program. For example, P1 and P2 are two flag codes, and P1 can be used to represent the first hard code in the object program and P2 can be used to represent the second hard code in the object program.
After detecting the hard code in the target program, replacing the hard code with a flag code. For example, the target program has hard codes "a ═ 2", "3.14 ═ r" and "c ≦ 70", and the non-hard codes "s ═ pi ×. r" are detected in step 301, then the hard codes "a ═ 2", "3.14 ═ r" and "c ≦ 70" are detected, and then step 302 is executed to replace the hard codes with the flag codes P1, P2 and P3, respectively, while the non-hard codes "s ═ pi ×. r" are not detected in step 301.
Further, in order to more intuitively and conveniently represent the hard code and the position thereof in the target program, the step 302 may further include:
acquiring the position information of the hard code in the target code;
and coding the position information to obtain the mark code.
The marker code may contain position information hard-coded in the object code. If the position of the hard code 1 in the target program is a and the position of the hard code 2 in the target program is b, encoding the position information a and b to obtain the corresponding mark codes which can be marked as Pa and Pb respectively, so that the mark codes not only uniquely represent each hard code in the target program, but also clearly indicate the position of each hard code in the target program, thereby facilitating searching.
303. Acquiring a preset processing rule corresponding to the hard code, if the preset processing rule is acquired, executing step 306, and if the preset processing rule is not acquired after a preset event is triggered, executing step 304;
and replacing the detected hard code with a mark code to obtain a preset processing rule corresponding to the hard code.
The processing rule mentioned above is a rule according to which the hard code is processed, and the setting of the processing rule should be completed before the hard code is processed.
Further, the step 303 may include:
carrying out logic analysis on the hard code to obtain an analysis result;
and selecting a corresponding processing rule from a preset processing rule set according to the analysis result.
The analysis result obtained by logically analyzing the hard codes is the basis for selecting the corresponding processing rule by the hard codes, each hard code has own logical characteristics, and a reasonable processing rule can be selected for processing according to the logical characteristics. The preset processing rules may be grouped in a set of processing rules, which may be preset by the relevant personnel, and which more fully contain various types of hard-coded processing rules, which may be stored in various types of memory.
Since the preset processing rule set may not include the preset processing rules corresponding to all hard codes, the preset processing rules may not be obtained in step 303. If the preset processing rule is acquired, step 306 is executed, and if the preset processing rule is not acquired after a preset event is triggered, step 304 is executed. The preset event may be triggered after a preset time period elapses, or after the processing rule that fails for a specified number of times is acquired.
304. Acquiring an input new processing rule corresponding to the hard code;
if the preset processing rule corresponding to the hard code is not acquired after the preset event is triggered, a dialog box can be popped up to prompt whether a new processing rule corresponding to the hard code needs to be input, wherein the new processing rule can be a completely newly-built rule or a rule which exists but does not correspond to the current hard code, and the new processing rule is set by an operator according to the actual situation. After acquiring the input new processing rule, step 305 is executed.
305. And establishing a calling relation between the mark codes and the new processing rules, and calling the corresponding processing rules according to the calling relation when the target codes are executed to the mark codes.
Aiming at the hard codes without the preset corresponding processing rules, the input new processing rules can be obtained, the calling relation between the mark codes and the new processing rules is established, and finally the new processing rules are utilized to process the hard codes.
306. And establishing a calling relationship between the mark codes and the acquired processing rules so as to call the corresponding processing rules according to the calling relationship when the target codes are executed to the mark codes.
If the preset processing rule corresponding to the hard code is obtained in step 303, a call relationship between the flag code and the obtained processing rule may be established, so that the target code calls the corresponding processing rule according to the call relationship when the target code is executed to the flag code.
And establishing a calling relation between the mark codes and the acquired processing rules, so that when the target code is executed to the mark codes, the corresponding processing rules can be called according to the calling relation, and the corresponding hard codes are processed.
For example, there are 3 flag codes P1, P2, and P3, and the acquired processing rules are regular A, B and C, and if a call relationship as shown in table 7 can be established between the flag codes and the processing rules, it represents that the hard code in the target program corresponding to the flag code P1 is processed according to the processing rule a, the hard code in the target program corresponding to the flag code P2 is processed according to the processing rule B, and the hard code in the target program corresponding to the flag code P3 is processed according to the processing rule C.
TABLE 7
Figure BDA0001194953920000131
Figure BDA0001194953920000141
Furthermore, since a hard code may have a plurality of processing rules in advance, one flag code may establish a call relationship with a plurality of the processing rules.
For example, for a certain flag code P1, 3 obtained processing rules A, B and C may be all called up with P1, as shown in table 8.
TABLE 8
P1 Rule A
P1 Rule B
P1 Rule C
Table 8 shows that there are 3 processing rules A, B and C that can be followed by the hard code in the target program corresponding to the flag code P1, and then one of the processing rules can be selected first according to a preset manner, and then the hard code in the target program corresponding to the flag code P1 is processed according to the selected processing rule. The preset mode may be to select the first one in sequence, may be to select the first one randomly, or may be to pop up a selection box, and the operator selects a certain processing rule.
Further, in order to more clearly and intuitively reflect the correspondence among the hard code, the flag code, and the hard code processing rule, and at the same time, to allow the correspondence among them to be easily modified, the correspondence among the hard code, the flag code, and the hard code processing rule may be written into a database. The corresponding relation among the three is clearly embodied in the form of a table in the database, and the searching and the modifying can be conveniently carried out. And because the position mark corresponding to each hard code is unique, even aiming at the hard codes of the same type, the processing can be carried out according to different hard code processing rules, and the processing mode is very flexible.
For example, if there are 3 hard codes "a ═ 2", "3.14 × r", and "C ≦ 70", the flag codes corresponding thereto are P1, P2, and P3, respectively, and the hard code processing rules for establishing call relationships with the flag codes P1, P2, and P3 are A, B and C, respectively, the information shown in table 9 can be written in the database.
TABLE 9
Figure BDA0001194953920000142
Figure BDA0001194953920000151
As can be seen from table 9, the corresponding hard-coding processing rule can be easily modified for each hard-coding without being limited by the same type of hard-coding.
In the embodiment of the invention, the target code is subjected to hard coding detection according to the preset hard coding characteristics; replacing the detected hard code with a logo code; acquiring a preset processing rule corresponding to the hard code; if the preset processing rule corresponding to the hard code is not acquired after the preset event is triggered, acquiring an input new processing rule corresponding to the hard code; establishing a calling relation between the mark codes and the new processing rules, and calling the corresponding processing rules according to the calling relation when the target codes are executed to the mark codes; if a preset processing rule corresponding to the hard code is acquired, establishing a calling relationship between the mark code and the acquired processing rule, so that the target code calls the corresponding processing rule according to the calling relationship when the mark code is executed. When the hard code without the preset processing rule appears, a new processing rule corresponding to the hard code can be input again, the calling relation between the mark code and the new processing rule is established, and the target code calls the corresponding processing rule according to the calling relation when executing the mark code, so that the integrity and the accuracy of the processing method can be ensured, and the normal operation of the target code is prevented from being influenced. In the embodiment of the invention, the hard codes are detected, and then the detected hard codes are replaced by the mark codes, so that the processing rules corresponding to the hard codes are called when the target codes are executed to the mark codes, the hard codes are sorted and modified, meanwhile, the situations of omission or error processing are avoided, the hard code sorting and modifying efficiency is improved, and the difficulty of later code maintenance is also reduced. In addition, when the processing rule of the hard code is modified, the processing rule can be modified in the preset processing rule corresponding to the hard code, and the calling relationship between the mark code and the preset processing rule can also be modified, so that the modification process is flexible and convenient.
A hard-coded processing method has been mainly described above, and a hard-coded processing apparatus will be described in detail below.
Referring to fig. 4, a first embodiment of a hard-coded processing apparatus according to the present invention includes:
in this embodiment, a hard-coded processing apparatus includes:
a detection unit 401, configured to perform hard-coded detection on a target code according to a preset hard-coded feature;
a replacing unit 402 configured to replace the detected hard code with a flag code;
an obtaining unit 403, configured to obtain a preset processing rule corresponding to the hard code;
an establishing unit 404, configured to establish a call relationship between the flag coding and the obtained processing rule, so that when the target code is executed to the flag coding, the corresponding processing rule is called according to the call relationship.
Referring to fig. 5, a second embodiment of a hard-coded processing device according to the present invention includes:
in this embodiment, a hard-coded processing apparatus includes:
a detection unit 501, configured to perform hard-coded detection on a target code according to a preset hard-coded feature;
a replacing unit 502 for replacing the detected hard code with a flag code;
an obtaining unit 503, configured to obtain a preset processing rule corresponding to the hard code;
a restoring unit 504, configured to restore the corresponding flag code in the target code to the hard code if a preset processing rule corresponding to the hard code is not obtained after a preset event is triggered.
An establishing unit 505, configured to establish a call relationship between the flag coding and the obtained processing rule, so that when the target code is executed to the flag coding, the corresponding processing rule is called according to the call relationship.
Further, the acquiring unit may specifically include:
a logic analysis module 5031, configured to perform logic analysis on the hard code to obtain an analysis result;
a rule selecting module 5032, configured to select a corresponding processing rule from a preset processing rule set according to the analysis result.
Further, the hard-coded processing device may further include:
a position information acquisition unit 506 for acquiring the position information hard-coded in the object code;
and a coding unit 507, configured to code the position information to obtain the mark code.
Referring to fig. 6, a hard-coded processing device according to a third embodiment of the present invention includes:
in this embodiment, a hard-coded processing apparatus includes:
a detection unit 601, configured to perform hard-coded detection on a target code according to a preset hard-coded feature;
a replacing unit 602, configured to replace the detected hard code with a flag code;
an obtaining unit 603, configured to obtain a preset processing rule corresponding to the hard code;
a new rule obtaining unit 604, configured to obtain an input new processing rule corresponding to the hard code if a preset processing rule corresponding to the hard code is not obtained after a preset event is triggered;
a new rule calling relationship establishing unit 605, configured to establish a calling relationship between the flag coding and the new processing rule, where the target code calls the corresponding processing rule according to the calling relationship when the target code executes the flag coding.
An establishing unit 606, configured to establish a call relationship between the flag coding and the obtained processing rule, so that when the target code is executed to the flag coding, the corresponding processing rule is called according to the call relationship.
Further, the acquiring unit may specifically include:
a logic analysis module 6031, configured to perform logic analysis on the hard code to obtain an analysis result;
a rule selecting module 6032, configured to select a corresponding processing rule from a preset processing rule set according to the analysis result.
Further, the hard-coded processing device may further include:
a position information acquisition unit 607 for acquiring the position information hard-coded in the object code;
the encoding unit 608 is configured to encode the position information to obtain the mark code.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (8)

1. A method of hard coded processing, comprising:
carrying out hard coding detection on the target code according to preset hard coding characteristics; the target code refers to a code to be processed and contains hard codes;
acquiring the position information of the hard code in the target code;
coding the position information to obtain a mark code;
replacing the detected hard code with a logo code; the marker code comprises location information hard-coded in the object code;
acquiring a preset processing rule corresponding to the hard code; the processing rule refers to a rule according to which the hard code is processed;
establishing a calling relationship between the mark codes and the acquired processing rules so that the target codes call the corresponding processing rules according to the calling relationship when the mark codes are executed; the invocation relationships and processing rules can be directly modified.
2. The method according to claim 1, wherein the obtaining the preset processing rule corresponding to the hard code specifically includes:
carrying out logic analysis on the hard code to obtain an analysis result;
and selecting a corresponding processing rule from a preset processing rule set according to the analysis result.
3. The hard-coded processing method of claim 1, further comprising:
and if the preset processing rule corresponding to the hard code is not acquired after the preset event is triggered, restoring the mark code corresponding to the target code into the hard code.
4. The hard-coded processing method of claim 1, further comprising:
if the preset processing rule corresponding to the hard code is not acquired after the preset event is triggered, acquiring an input new processing rule corresponding to the hard code;
and establishing a calling relationship between the mark codes and the new processing rules so that the target code calls the corresponding processing rules according to the calling relationship when the mark codes are executed.
5. A hard coded processing device, comprising:
the detection unit is used for carrying out hard coding detection on the target code according to the preset hard coding characteristics; the target code refers to a code to be processed and contains hard codes;
a position information acquisition unit for acquiring the position information hard-coded in the object code;
the coding unit is used for coding the position information to obtain a mark code;
a replacement unit configured to replace the detected hard code with a flag code; the marker code comprises location information hard-coded in the object code;
an obtaining unit, configured to obtain a preset processing rule corresponding to the hard code; the processing rule refers to a rule according to which the hard code is processed;
the establishing unit is used for establishing a calling relationship between the mark codes and the acquired processing rules so as to call the corresponding processing rules according to the calling relationship when the target codes are executed to the mark codes; the invocation relationships and processing rules can be directly modified.
6. The hardcoded processing device of claim 5 wherein the means for obtaining includes:
the logic analysis module is used for carrying out logic analysis on the hard code to obtain an analysis result;
and the rule selection module is used for selecting a corresponding processing rule from a preset processing rule set according to the analysis result.
7. The hard-coded processing device according to claim 5, further comprising:
and the restoring unit is used for restoring the mark code corresponding to the target code into the hard code if the preset processing rule corresponding to the hard code is not acquired after the preset event is triggered.
8. The hard-coded processing device according to claim 5, further comprising:
the new rule obtaining unit is used for obtaining an input new processing rule corresponding to the hard code if the preset processing rule corresponding to the hard code is not obtained after a preset event is triggered;
and the new rule calling relation establishing unit is used for establishing the calling relation between the mark codes and the new processing rules, and calling the corresponding processing rules according to the calling relation when the target codes are executed to the mark codes.
CN201611233716.1A 2016-12-28 2016-12-28 Hard code processing method and device Active CN108255490B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611233716.1A CN108255490B (en) 2016-12-28 2016-12-28 Hard code processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611233716.1A CN108255490B (en) 2016-12-28 2016-12-28 Hard code processing method and device

Publications (2)

Publication Number Publication Date
CN108255490A CN108255490A (en) 2018-07-06
CN108255490B true CN108255490B (en) 2021-11-26

Family

ID=62719330

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611233716.1A Active CN108255490B (en) 2016-12-28 2016-12-28 Hard code processing method and device

Country Status (1)

Country Link
CN (1) CN108255490B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111399848B (en) * 2020-03-17 2023-05-23 阿波罗智联(北京)科技有限公司 Hard-coded data detection method and device, electronic equipment and medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1510569A (en) * 2002-12-23 2004-07-07 华为技术有限公司 Method for extracting and concentrating hard code string from source codes
CN101145102A (en) * 2006-09-11 2008-03-19 国际商业机器公司 Method and device for testing internationalized software
CN103577178A (en) * 2012-08-03 2014-02-12 北京奥鹏远程教育中心有限公司 Method and system for flexibly modifying computation rule

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100082808A1 (en) * 2008-09-29 2010-04-01 Red Aril, Inc. System and method for automatically delivering relevant internet content

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1510569A (en) * 2002-12-23 2004-07-07 华为技术有限公司 Method for extracting and concentrating hard code string from source codes
CN101145102A (en) * 2006-09-11 2008-03-19 国际商业机器公司 Method and device for testing internationalized software
CN103577178A (en) * 2012-08-03 2014-02-12 北京奥鹏远程教育中心有限公司 Method and system for flexibly modifying computation rule

Also Published As

Publication number Publication date
CN108255490A (en) 2018-07-06

Similar Documents

Publication Publication Date Title
US9471470B2 (en) Automatically recommending test suite from historical data based on randomized evolutionary techniques
CN107016019B (en) Database index creation method and device
US8510602B2 (en) Testing a software application used in a database system
CN106250319B (en) Static code scanning result treating method and apparatus
CN110647562B (en) Data query method and device, electronic equipment and storage medium
CN107643904B (en) Method, device and medium for detecting code submission log and electronic equipment
CN110096419A (en) Acquisition methods, interface log management server and the service server of interface log
CN109617745B (en) Alarm prediction method, device, system and storage medium
US9454561B2 (en) Method and a consistency checker for finding data inconsistencies in a data repository
CN111767265B (en) Data tilting method and system in connection operation and computer equipment
CN111324781A (en) Data analysis method, device and equipment
US20200201741A1 (en) Identification of software program fault locations
CN108255490B (en) Hard code processing method and device
CN115629949A (en) Optimization method and device for management information system, electronic equipment and storage medium
CN113093702B (en) Fault data prediction method and device, electronic equipment and storage medium
CN113656210A (en) Processing method and device for error reporting information, server and readable storage medium
CN113159479A (en) Work statistics method and system based on project management
CN111639057A (en) Log message processing method and device, computer equipment and storage medium
CN106055625B (en) Method and device for executing service
CN112115148B (en) Method, device and equipment for determining data comparison result
CN110730972A (en) Work Range System and method of Using the same
CN103761247A (en) Processing method and device for error files
CN111027307A (en) Method and device for judging content influencing judgment result in judgment document
CN113792800B (en) Feature generation method and device, electronic equipment and storage medium
CN111026307B (en) Method and device for quickly associating graphics primitives in graphics configuration tool

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant