CN109683881B - Code format adjusting method and device - Google Patents

Code format adjusting method and device Download PDF

Info

Publication number
CN109683881B
CN109683881B CN201811618411.1A CN201811618411A CN109683881B CN 109683881 B CN109683881 B CN 109683881B CN 201811618411 A CN201811618411 A CN 201811618411A CN 109683881 B CN109683881 B CN 109683881B
Authority
CN
China
Prior art keywords
code
preset
character
type
adjustment
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
CN201811618411.1A
Other languages
Chinese (zh)
Other versions
CN109683881A (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.)
Weichai Power Co Ltd
Original Assignee
Weichai Power 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 Weichai Power Co Ltd filed Critical Weichai Power Co Ltd
Priority to CN201811618411.1A priority Critical patent/CN109683881B/en
Publication of CN109683881A publication Critical patent/CN109683881A/en
Application granted granted Critical
Publication of CN109683881B publication Critical patent/CN109683881B/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/30Creation or generation of source code
    • G06F8/33Intelligent editors

Abstract

The invention provides a code format adjusting method and a device, after a code to be processed which needs to be subjected to code format adjustment is obtained, format adjustment is carried out on the code to be processed based on preset code characteristics to obtain a target code with a preset format, the target code with the preset format is output, the preset formats of different codes to be processed which are obtained after the preset code characteristics are adjusted are the same, the formats of different codes to be processed are changed from diversification to tidiness, the formats of different codes to be processed are unified, the unified format can enable each programmer to accurately understand the thought and the intention of the code, the readability of the code is obviously improved, the code modification and maintenance are facilitated, in addition, the code to be processed can be subjected to automatic format adjustment based on the preset code characteristics, the links of the programmer for adjusting or setting the format are omitted, the manual adjustment time is saved, and the adjustment efficiency is improved.

Description

Code format adjusting method and device
Technical Field
The invention belongs to the field of software codes, and particularly relates to a code format adjusting method and device.
Background
With the progress of science and technology, the computer industry is also developing rapidly, wherein the related software projects are continuously expanded, and some large-scale software projects often need to be developed by multiple teams, for example: software codes require multiple persons to collaboratively develop, and full-text codes are not attractive due to different writing formats of the codes by everyone.
Currently, the way to adjust the codes with different formats into the codes with a uniform format is: the specification of the pre-established code format and the use of the code editor are assisted, but different programmers have different understandings of the pre-established code format, so that the format of the code obtained based on the pre-established code format is different, and the same different programmers set up format-related menus in the code editor when using the code editor is different, which also results in different formats of the code given by the code editor.
Disclosure of Invention
In view of the above, an object of the present invention is to provide a method and an apparatus for automatically adjusting a format of a code to be processed based on a preset code characteristic. The technical scheme is as follows:
the invention provides a code format adjusting method, which comprises the following steps:
acquiring a code to be processed which needs to be subjected to code format adjustment;
carrying out format adjustment on the code to be processed based on preset code characteristics to obtain a target code with a preset format;
and outputting the target codes with the preset format, wherein the preset formats of the target codes obtained after different codes to be processed are adjusted by the preset code characteristics are the same.
Preferably, the format adjustment of the code to be processed based on the preset code characteristics to obtain the target code with the preset format includes:
extracting features matched with the codes to be processed from the preset code features;
and adjusting the format of the code to be processed based on the characteristics matched with the code to be processed to obtain a target code with a preset format.
Preferably, the extracting the feature matched with the code to be processed from the preset code feature includes:
determining the type corresponding to each independent component in the code to be processed, wherein any independent component in each independent component is a character string or a character;
extracting type adjustment features corresponding to the types from the preset code features based on the types corresponding to the independent components respectively;
and selecting a common adjusting feature from the preset code features, wherein the common adjusting feature is used for carrying out format limitation on the parts except the independent components in the code to be processed.
Preferably, the determining the type corresponding to each independent component in the code to be processed includes:
obtaining a character group included by each line of characters in the code to be processed, wherein the character group included by any line of characters comprises: a character group between the first character and the 1 st space in the line of characters, a character group between the last character and the nth space in the line of characters, and a character group between the ith space and the (i + 1) th space, wherein the value of i is 2 to n-1, and n is the total number of spaces included in the code to be processed;
the following steps are performed for any character group:
if all contents carried by the character group are one of numbers, operators, punctuation marks and preset reserved words, the type of the character group is the type corresponding to all the contents, if the number of characters in the character group is more than 1, the character group is determined to be a character string, and if the number of characters in the character group is equal to 1, the character group is determined to be a character;
if all contents carried by the character group do not comprise numbers, operators, punctuation marks and preset reserved words, the type of the character group is an independent variable type, if the number of characters in the character group is more than 1, the character group is determined to be a character string, and if the number of characters in the character group is equal to 1, the character group is determined to be a character;
if the number of the characters in the character group is more than 1 and the character group comprises at least one preset character, splitting the character group through the preset character, determining the preset character as one character, wherein the type of the character is the same as that of the preset character, and the preset character comprises at least one of an operator, a punctuation mark and a number;
any part of the parts obtained by splitting the preset character is divided into: if the number of characters in the part is equal to 1, determining that the part is a character and the type of the character is an argument type, if the number of characters in the part is greater than 1, determining that the part is a character string, if the character string is the same as one of preset reserved words, determining that the type of the character string is a reserved word type, otherwise, determining that the type of the character string is an argument type.
Preferably, the obtaining of the preset code feature includes:
obtaining a template code for obtaining the preset code characteristics;
determining all types of adjustment features corresponding to each independent component in the template code;
adjusting characteristics for all types corresponding to any one of the individual components: if the relationship between one type of adjustment feature corresponding to the independent component and all types of adjustment features corresponding to the independent component meets a first preset relationship, determining the type of adjustment feature meeting the first preset relationship as a preset code feature;
determining various common adjustment characteristics suitable for each line of codes in the template codes;
sharing an adjustment feature for any one of the various types of shared adjustment features: and if the relation between one common adjusting feature in the class and all the common adjusting features in the class meets a second preset relation, determining the common adjusting feature meeting the second preset relation as a preset code feature.
The present invention also provides a code format adjusting apparatus, comprising:
the acquisition module is used for acquiring a code to be processed which needs to be subjected to code format adjustment;
the adjusting module is used for carrying out format adjustment on the code to be processed based on preset code characteristics to obtain a target code with a preset format;
and the output module is used for outputting the target codes with the preset format, wherein the preset formats of the target codes obtained after different codes to be processed are adjusted by the preset code characteristics are the same.
Preferably, the adjusting module includes:
the extraction unit is used for extracting features matched with the codes to be processed from the preset code features;
and the adjusting unit is used for carrying out format adjustment on the code to be processed based on the characteristics matched with the code to be processed to obtain a target code with a preset format.
Preferably, the extraction unit includes:
the determining subunit is used for determining the type corresponding to each independent component in the code to be processed, wherein any independent component in each independent component is a character string or a character;
a type adjustment feature extraction subunit, configured to extract, based on a type corresponding to each of the independent components, a type adjustment feature corresponding to the type from the preset code feature;
and the common adjustment feature selection subunit is used for selecting a common adjustment feature from the preset code features, wherein the common adjustment feature is used for carrying out format limitation on the parts except the independent components in the code to be processed.
Preferably, the determining subunit is specifically configured to obtain a character group included in each line of characters in the code to be processed, where a character group included in any line of characters includes: a character group between the first character and the 1 st space in the line of characters, a character group between the last character and the nth space in the line of characters, and a character group between the ith space and the (i + 1) th space, wherein the value of i is 2 to n-1, and n is the total number of spaces included in the code to be processed;
the following steps are performed for any character group:
if all contents carried by the character group are one of numbers, operators, punctuation marks and preset reserved words, the type of the character group is the type corresponding to all the contents, if the number of characters in the character group is more than 1, the character group is determined to be a character string, and if the number of characters in the character group is equal to 1, the character group is determined to be a character;
if all contents carried by the character group do not comprise numbers, operators, punctuation marks and preset reserved words, the type of the character group is an independent variable type, if the number of characters in the character group is more than 1, the character group is determined to be a character string, and if the number of characters in the character group is equal to 1, the character group is determined to be a character;
if the number of the characters in the character group is more than 1 and the character group comprises at least one preset character, splitting the character group through the preset character, determining the preset character as one character, wherein the type of the character is the same as that of the preset character, and the preset character comprises at least one of an operator, a punctuation mark and a number;
any part of the parts obtained by splitting the preset character is divided into: if the number of characters in the part is equal to 1, determining that the part is a character and the type of the character is an argument type, if the number of characters in the part is greater than 1, determining that the part is a character string, if the character string is the same as one of preset reserved words, determining that the type of the character string is a reserved word type, otherwise, determining that the type of the character string is an argument type.
Preferably, the apparatus further comprises:
the template code obtaining module is used for obtaining a template code used for obtaining the preset code characteristics;
a type adjustment feature determining module, configured to determine all type adjustment features corresponding to each independent component in the template code, and for all type adjustment features corresponding to any one independent component in each independent component: if the relationship between one type of adjustment feature corresponding to the independent component and all types of adjustment features corresponding to the independent component meets a first preset relationship, determining the type of adjustment feature meeting the first preset relationship as a preset code feature;
a common adjustment feature determining module, configured to determine various common adjustment features applicable to each line of codes in the template codes, and for any one of the various common adjustment features, share an adjustment feature: and if the relation between one common adjusting feature in the class and all the common adjusting features in the class meets a second preset relation, determining the common adjusting feature meeting the second preset relation as a preset code feature.
Compared with the prior art, the technical scheme provided by the invention has the following advantages:
after the codes to be processed, which need to be subjected to code format adjustment, are obtained, format adjustment is carried out on the codes to be processed based on the preset code characteristics, the target codes with the preset format are obtained, the target codes with the preset format are output, the preset formats of the target codes obtained after different codes to be processed are adjusted by the preset code characteristics are the same, the formats of the different codes to be processed are transited from diversification to tidiness, the formats of the different codes to be processed are unified, the unified format can enable each programmer to accurately understand the thought and the intention of the codes, the readability of the codes is obviously improved, the codes can be accurately changed on the basis of accurately understanding the thought and the intention, the modification and the maintenance of the codes are facilitated, and in addition, the codes to be processed can automatically carry out format adjustment based on the preset code characteristics, the link of adjusting or setting the format by a programmer is saved, the manual adjusting time is saved, and the adjusting efficiency is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a flowchart of a code format adjusting method according to an embodiment of the present invention;
fig. 2 is a flowchart of extracting features matching with a code to be processed from preset code features according to an embodiment of the present invention;
FIG. 3 is a diagram of a section of code to be processed according to an embodiment of the present invention;
fig. 4 is a flowchart of acquiring a preset code feature according to an embodiment of the present invention;
FIG. 5 is a diagram of template code provided by an embodiment of the present invention;
FIG. 6 is a schematic diagram of an object code obtained after the to-be-processed code shown in FIG. 3 is adjusted by preset code features in the template code shown in FIG. 5;
fig. 7 is a schematic structural diagram of a code format adjusting apparatus according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of another code format adjusting apparatus according to an embodiment of the present invention.
Detailed Description
The invention provides a code format adjusting method and device, a code to be processed can automatically adjust a format based on preset code characteristics, so that a link of adjusting or setting the format by a programmer is omitted, manual adjusting time is saved, and adjusting efficiency is improved.
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. 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.
As shown in fig. 1, a flowchart of a method for adjusting a code format according to an embodiment of the present invention is provided, where the method includes the following steps:
s101: and acquiring the code to be processed which needs to be subjected to code format adjustment. The code to be processed is a program code to be subjected to code format adjustment, a programmer writes a section of program code by means of a terminal, such as a computer, a mobile phone and the like, when the terminal detects that the program code is completely written, the terminal obtains the code to be processed, and when the terminal detects that the program code is completely written, the terminal can detect that the programmer triggers a writing completion control, and if the programmer clicks a storage control, one-time or partial writing is completed.
S102: and adjusting the format of the code to be processed based on the preset code characteristics to obtain the target code with the preset format.
In this embodiment, the preset code feature is an adjustment standard based on which the format of the code to be processed is adjusted, so that the target code has a preset format indicated by the preset code feature, that is, the preset code feature can represent which aspects of the code to be processed are defined, for example, the relationship between each line, each character/character group, the header file, and the character is defined, and thus the format of the target code to be finally output can be specified by defining the preset code feature, and therefore, the preset format can be indicated by the preset code feature in this embodiment.
The preset code features may be human-defined features, and the writing specifications to be followed when the code is written are characterized through the human-defined features, for example: the programmer writes a code frame which needs to be followed by other programmers and specifies the requirements of the relationship among each line, each character/character group, the header file and the characters, and then the requirements can be regarded as preset code characteristics, so that the target code has the uniform format which is desired by the programmer, and based on the mode, the content of the code to be processed only needs to be replaced by the content in the code frame when the code to be processed is written, so that the target code with the preset format indicated by the code frame is obtained.
Another possible way is: one template code is selected from a plurality of codes to be processed so as to obtain preset code characteristics from the template code, and then the adjustment is carried out based on the preset code characteristics. For example: in the template code, each line has only one program statement, and each statement is empty of two spaces, and these are taken as preset code characteristics. After the code to be processed is obtained, the characteristics are combined to be adjusted into the target code with the preset format indicated by the characteristics, so that each line of the target code only has one program statement, and each statement is empty by two blank spaces.
However, for a certain code to be processed, all the features in the preset code features cannot be all applied to the code to be processed, and at this time, features matched with the code to be processed need to be extracted from the preset code features, and based on the features matched with the code to be processed, format adjustment is performed on the code to be processed.
The method for extracting the features matched with the codes to be processed from the preset code features comprises the following steps: selecting characteristics suitable for the code to be processed from preset code characteristics, such as: the preset code features may include: the following examples illustrate the requirements for each line of code, each type of character/character string, the requirements for header files, the number of spaces indented into the hierarchy of each line of code, punctuation marks used at the end of each line, and the like, when the format of the code to be processed needs to be adjusted, the applicable features are extracted from the preset code features for format adjustment, if there are multiple lines of code in the code to be processed, the features required for each line need to be extracted, and the indented features are also extracted for each line of indentation of the code to be processed: for example, one of the preset code features is that a hierarchy is indented with 4 spaces, and a hierarchy of the code to be processed is indented with 2 spaces, at this time, a feature with 4 spaces indented in the hierarchy can be extracted as a feature matched with the code to be processed, and then, based on the feature with 4 spaces indented in the hierarchy of the preset code features, the 2 spaces indented in the hierarchy of the code to be processed is adjusted to be 4 spaces indented in the hierarchy.
S103: and outputting the target codes with the preset format, wherein the preset formats of the target codes obtained after different codes to be processed are adjusted by the preset code characteristics are the same. The formats of the different codes to be processed are different, but after format adjustment is carried out through the preset code characteristics, the formats of the output target codes are all preset formats, so that the formats of the target codes are the same, the requirement for converting the formats of the different codes to be processed into the uniform format can be met only by setting the preset code characteristics, and compared with manual format adjustment, the format adjustment is accurate and efficient.
The preset format can be for one project or one company, so that the object codes given by one project or one company all have a uniform preset format, and different projects or different companies can adopt different preset formats, so that the formats can be guaranteed to be diversified in addition to guaranteeing that the codes of one unit (such as one project or one company) have the uniform preset format, and for example, the code formats of different projects can be different.
The points to be explained here are: although the code format of the code to be processed is adjusted, the code to be processed can still be reserved as the source code, so that a programmer can compare the source code with the target code and understand which aspect is adjusted, and thus the programmer can correct the self writing style based on the adjusted aspect, so that the subsequently developed program code meets the requirement of the preset format indicated by the preset code characteristic.
According to the technical scheme, after the codes to be processed, which need to be subjected to code format adjustment, are obtained, format adjustment is performed on the codes to be processed based on the preset code characteristics, the target codes with the preset format are obtained, the target codes with the preset format are output, the preset formats of the target codes obtained after different codes to be processed are adjusted through the preset code characteristics are the same, the formats of the different codes to be processed are changed from diversification to tidiness, the formats of the different codes to be processed are unified, the unified format can enable each programmer to accurately understand the thought and the intention of the codes, the readability of the codes is obviously improved, the codes can be accurately changed on the basis of accurately understanding the thought and the intention, the codes can be modified and maintained, in addition, the codes to be processed can be automatically subjected to format adjustment based on the preset code characteristics, the link of adjusting or setting the format by a programmer is saved, the manual adjusting time is saved, and the adjusting efficiency is improved.
As shown in fig. 2, a flowchart for extracting features matching with a to-be-processed code from preset code features is provided in an embodiment of the present invention, where the method includes the following steps:
s201: determining the type corresponding to each independent component in the code to be processed, wherein any independent component in each independent component is a character string or a character. That is to say, for the code to be processed, the code to be processed is composed of two types of independent components, namely a character string and a character, it is to be noted that the character is a single character, and the character string is a set of a plurality of characters, as shown in fig. 3, in the code to be processed, "void", "main", and "int" are character strings, and the types of the three character strings are reserved word types, in the code to be processed, (","), "{", "x", "5", "b", "4", "; "," c "," + "," } "are characters, and" (",") "," { "and"; the types of "and" } "are punctuation mark type, the types of" ═ and "+" are operator type, the types of "a", "x", "b", and "c" are argument type, and the types of "3", "5", and "4" are number type.
S202: and extracting type adjustment features corresponding to the types from preset code features based on the types corresponding to the independent components respectively.
The types of the independent components in the code to be processed are at least: the five types of characters, arguments, operators, punctuation marks and numbers are reserved, and for the five types, the preset code characteristics have type adjustment characteristics corresponding to the five types respectively, so after a code to be processed is obtained, the code to be processed needs to be determined to contain independent component parts of several types, and then the type adjustment characteristics of the types contained in the code to be processed are extracted from the preset code characteristics.
The type adjustment feature is used to define the writing specification to which the type of independent component follows in writing, such as whether the type of independent component needs to adopt upper case characters or lower case characters, whether there is a gap between the type of independent component and an adjacent independent component, and the like, for example, in the code to be processed shown in fig. 3, the type adjustment feature extracted from the preset code feature is: the rule used when adjusting for a character or a character string of a certain type is that the left curly brace occupies one row alone, the right curly brace occupies one row alone, a pair of curly braces is aligned, and a space is arranged between a numeric character and an arithmetic character and between two adjacent character strings. The type adjustment features to be extracted in conjunction with fig. 5 are: a hierarchy is indented with 4 spaces, left curly braces occupy a line alone, right curly braces occupy a line alone, a pair of curly braces align, and a line has only one sentence.
S203: and selecting a common adjusting feature from the preset code features, wherein the common adjusting feature is used for carrying out format limitation on parts except the independent components in the code to be processed.
That is to say, the preset code feature is composed of a type adjustment feature and a common adjustment feature, and the common adjustment feature is a feature applicable to all the codes to be processed, for example, each code to be processed has multiple lines of codes, and even further includes a header file, which are common parts of the multiple codes to be processed, then the common adjustment feature may be a definition of the format of the contents, for example, the common adjustment feature is: the requirement of each line of code, the requirement of a header file, the specific number of spaces indented in the hierarchy of each line of code, punctuation marks adopted at the end of each line and the like. For example, there are 3 lines between the head file and the next sentence, each line of code is indented with 4 spaces, one segment of code is ended with period except the last line, the rest are ended with semicolon, each line has only one program sentence, etc.
According to the technical scheme, when the format of the code to be processed is adjusted, the type adjustment characteristic of the independent component part suitable for the code to be processed is selected based on the independent component part of the code to be processed, so that the code to be processed is adjusted based on the type adjustment characteristic and the shared adjustment characteristic of the independent component part suitable for the code to be processed, and the code is adjusted only based on the shared adjustment characteristic and the type adjustment characteristic required by the code to be processed.
In this embodiment, the process of obtaining the type corresponding to each independent component by dividing the code to be processed is as follows:
in the code compiling process of the code to be processed, inputting each line of characters of the code to be processed one by one to obtain a character group included by each line of characters, wherein the character group included by any line of characters comprises: the character set between the first character and the 1 st space in the line of characters, the character set between the last character and the nth space in the line of characters, and the character set between the ith space and the (i + 1) th space, wherein the value of i is 2-n-1, n is the total number of spaces included in the code to be processed, and for any character set: and determining whether the character included in the character group is a character string or a character based on a first preset matching rule, and obtaining the type based on a second preset matching rule.
The first preset matching rule may be, but is not limited to, the number of characters included in a character group, if the number of characters included in the character group is equal to 1, the character group is determined as a character, if the number of characters included in the character group is greater than 1, the character group is determined as a character string, and the second preset matching rule may be based on preset reserved words, operators, punctuation marks and numbers for matching, wherein for any programming language, the preset reserved words (i.e., the preset reserved words), the operators and the punctuation marks are specified, so that types can be determined based on the preset reserved words, the operators and the punctuation marks, and the numbers are generally used for assignment in the programming language, so that the types can also be determined based on the numbers. The process is as follows: the following steps are performed for any character group:
if all the contents carried by the character group are one of numbers, operators, punctuation marks and preset reserved words, the type of the character group is the type corresponding to all the contents, if the number of the characters in the character group is more than 1, the character group is determined to be a character string, and if the number of the characters in the character group is equal to 1, the character group is determined to be a character.
If all contents carried by the character group do not comprise numbers, operators, punctuation marks and preset reserved words, the type of the character group is an independent variable type, if the number of characters in the character group is more than 1, the character group is determined to be a character string, and if the number of characters in the character group is equal to 1, the character group is determined to be a character.
If the number of the characters in the character group is larger than 1 and the character group comprises at least one preset character, splitting the character group through the preset character, determining the preset character as a character, wherein the type of the character is the same as that of the preset character, and the preset character comprises: at least one of operators, punctuation marks and numbers.
Any part of all parts obtained by splitting the preset characters: if the number of characters in the part is equal to 1, determining that the part is a character and the type of the character is an argument, if the number of characters in the part is greater than 1, determining that the part is a character string, if the character string is the same as one of preset reserved words, determining that the type of the character string is a reserved word type, otherwise, determining that the type of the character string is an argument type.
It should be noted that, the underline "_" in the punctuation mark in daily life is not included in the scope of the punctuation mark in the present application, and the underline "_" is included in the special mark in the present application, and the underline and the letter are of the same type, that is, when a character string includes the letter and the underline, the character string does not need to be split.
If the number of characters in a character group is greater than 1 and the character group comprises a preset character, if the character group comprises an operator ═ then the character group is split by the operator ═ and the operator ═ is determined as a character and the type of the character is the same as that of the preset character.
If the number of characters in a character group is greater than 1 and the character group comprises at least two preset characters, if the character group comprises an operator (i.e., an operator) and a punctuation mark (i.e., a punctuation mark), the character group is split by the operator (i.e., the operator) and the punctuation mark (i.e., the punctuation mark) and the operator (i.e., the punctuation mark) are determined to be one character respectively, the type of the character is the same as that of the preset character, i.e., the operator (i.e., the punctuation mark) is determined to be an operator type, and the punctuation mark (i.e., the punctuation mark) is determined to be a punctuation mark type.
And if the number of the characters in one character group is more than 1 and comprises at least one preset character, and the at least one preset character comprises at least one number, carrying out type judgment on the character before the number, and splitting based on the type of the character before the number.
One possible way to split based on the type of the previous character of the number is: if the type of the character before the number is the letter, the character group cannot be split through the number, otherwise, the character group is split through the number. That is, a number follows a letter, treating the letter and number as a whole, and a number follows an operator or punctuation mark, splitting the number and operator or punctuation mark.
For ease of understanding, the above-mentioned division is exemplified by the C language:
firstly, reserved words are character groups defined in C language, and the words can not be used as variable names any more, if "int" is a character group defined in C language, then "int" can only be used as reserved words, but can not be used as arguments, if a programmer can not use int when defining a certain name; the independent variable is an undefined character set in the C language, and particularly defines a character string or a character by a programmer. Such as "pwd _ type," the defined string or property of a string in subsequent use is defined by the programmer himself; the operator is used for executing program code operation, and the operator is set in C language, wherein the operator comprises: monocular, binocular, and trinocular operations, the monocular operation being the operation of the operator on only one variable, e.g. "! "(logical not); the binocular operation operates on two variables for the operator, such as ═ (assignment operator); the triage operation operates on three variables for the operator, e.g., "? : "(conditional operators), the same punctuation marks are set in the C language, and this embodiment will not be described one by one. The following is described by taking the pending code shown in fig. 3 as an example:
firstly, dividing the code to be processed shown in fig. 3 according to a first character and a 1 st space of each line, a last character and an nth space of each line, and two adjacent spaces of each line, wherein the obtained character groups are ' food ', ' main () { ', ' int ', ' a ', ' 35 ', '; "," int "," b ═ 4; "" int "," c ", and" ═ a + b; ", where any character between any two spaces is empty, the character set is discarded.
If the character group "35" is a character in which all characters are numbers, the character group is determined to be a number type, and the number of characters in the character group is greater than 1, the character group is determined to be a character string.
And if the character groups 'food', 'int' and 'int' are the same as the reserved character, determining the type of the reserved character, and if the number of the characters of the character group is more than 1, determining that the character group is a character string.
The character groups "a", "c", "═ and"; "the number of characters is equal to 1," a "," c "is determined as a letter," ═ is determined as an operator, "; "is determined as a punctuation mark symbol, and" a "and" c "are determined as letter types, and" ═ is an operator type, "; "is determined as a punctuation mark type and the number of characters of the character group is equal to 1, the character group is determined as one character.
The character group "b ═ 4; "," main () { "and" ═ a + b; the number of the characters is greater than 1 and includes preset characters, the character groups are split, taking the character group "main () {" as an example, the character groups are split to obtain "main", "()", "{", and then the obtained character groups are subjected to type determination, and the determined type is the same as the execution process and principle of the code for determining the type, and is not described again.
The flow of acquiring the preset code feature in this embodiment is shown in fig. 4, and may include the following steps:
s401: and obtaining a template code for obtaining preset code characteristics. The template code is one of a plurality of codes to be processed, and can be designated by a programmer or randomly selected from the plurality of codes to be processed to serve as the template code.
S402: and determining all types of adjustment characteristics corresponding to each independent component in the template code.
S403: adjusting characteristics for all types corresponding to any one of the individual components: and if the relationship between one type of adjustment feature corresponding to the independent component and all the type of adjustment features corresponding to the independent component meets a first preset relationship, determining the type of adjustment feature meeting the first preset relationship as a preset code feature.
It can be understood that: the template code contains independent components of different formats, but the independent components of different formats have independent components corresponding to one type, so that the formats of the independent components of the same type need to be unified, and in order to obtain the unified type adjustment features of the independent components of the type, all the type adjustment features (one type adjustment feature is regarded as one format) of the independent components of the type need to be obtained first, and then one type adjustment feature is selected from all the type adjustment features of the type, and the selected type adjustment feature is the type adjustment feature of the type in the preset code features. In this embodiment, the manner of selecting the type adjustment feature is as follows:
for all types of adjustment features of a type, calculating the application proportion of each type of adjustment feature of the type to all types of adjustment features of the type, and if the application proportion exceeds a preset threshold (such as 60% but not limited to 60%), determining the type of adjustment feature with the application proportion exceeding the preset threshold as a preset code feature; if there are a plurality of type adjustment features with application ratios exceeding a preset threshold in one type, one of the type adjustments with application ratios exceeding the preset threshold needs to be selected as a preset code feature, and the selection mode may be, but is not limited to: and selecting randomly or according to the application proportion.
In addition, besides the preset threshold value based on the first preset relationship, the embodiment may also adopt other manners, for example, for all types of adjustment features of one type, one is randomly selected as a preset code feature, but compared with the manner based on the first preset relationship, in this manner, the type adjustment feature selected by the embodiment may not conform to the writing habit of most people, and therefore, the target code output after adjustment is not easy to understand, and therefore, the embodiment preferably adopts the manner based on the first preset relationship to select the preset code feature.
S404: various types of common adjustment features applicable to each line of code in the template code are determined.
S405: sharing an adjustment feature for any one of the various types of shared adjustment features: and if the relation between one common adjusting feature in the class and all the common adjusting features in the class meets a second preset relation, determining the common adjusting feature meeting the second preset relation as a preset code feature.
The second preset relationship may be the same as the first preset relationship, or may be different from the first preset relationship, for example, the values of the preset threshold value as the first preset relationship and the preset threshold value as the second preset relationship are different, and step S405 is similar to step S403, and will not be described here.
According to the technical scheme, the preset code characteristics suitable for each code to be processed are extracted from the template codes, so that an adjustment standard is provided for the format adjustment of the code to be processed, and thus target codes adjusted according to the preset code characteristics can have a uniform format.
Taking the template code shown in fig. 5 as an example, the process of extracting the preset code features from the template code shown in fig. 5 is described with reference to fig. 4, and the process is as follows:
reading the template code one by one, wherein the first character is "#", which is identified as a macro definition, but the content of the whole code is uncertain, continuously reading back "i", "n", "c", "1", "u", "d" and "e", the next character is a space which is not a letter, a number or an underline, so that the divided first character string is "# include", and meanwhile, the head file of the line is identified as a line, and for the following lines which may be the line where the feature is located, the next character is read back as a "blank line", and the next character is read back as a "non-blank line", so that the feature after the macro definition can be judged as a "blank line", and the features are sequentially extracted back according to the mode, and the extracted features comprise:
the header file comprises a sentence followed by an empty line, and the application proportion of the characteristic is 100%;
one level has 5 positions indented into 4 spaces, 2 positions indented into 2 spaces, and the application proportion of the characteristics indented into four 4 spaces is 71 percent;
the template codes have 8 binocular operators in total, and 7 spaces are arranged before and after the binocular operators, so that the application proportion of the characteristics is 87%;
the left curly braces independently occupy one line, and the application proportion of the characteristics is 100 percent;
the right curly brace occupies one row independently, and the application proportion of the characteristics is 100 percent;
a pair of braces is aligned, and the application ratio of the characteristics is 100%;
one line has only one statement, and the application proportion of the features is 100%;
then, based on the application ratio exceeding a preset threshold (such as 60% but not limited to 60%), the preset code features extracted from the template code shown in fig. 5 are: the header file contains the sentence followed by an empty line, a hierarchical indentation of 4 spaces, spaces before and after the binocular operator, left curly braces alone in a line, right curly braces alone in a line, a pair of curly braces aligned, and only one sentence in a line.
After the preset code features extracted in fig. 5 are applied to the to-be-processed code shown in fig. 3, the code adjustment process of the to-be-processed code shown in fig. 3 is as follows:
reading the code to be processed character by character, wherein the first character is "v", the symbol beginning with the letter or underline according to the C language rule is an identifier, but the whole content cannot be determined, continuing to read "o", "i" and "d" backwards, the next character string is read as a "space", which is no longer a letter, a number and an underline, so that the first character string which is divided is "void", and the code is divided according to the mode into "void", "main", "(", ")", "{", "int", "a", "("), "3", "; "," int "," x "," ═ 5 "," int "," b "," ═ 4 ",": "," int "," c "," ═ a "," + "," b ","; "," } ", the type adjustment features which can be extracted from the preset code features according to the segmented characters and character strings are as follows: blank, the left and right curly braces that have before and after the binocular operator respectively account for one line and a pair of curly braces are aligned, and the sharing adjustment characteristic has: the header file contains sentences followed by an empty line, a hierarchy indented with 4 spaces and a line with only one sentence. The target code obtained by adjusting the code to be processed shown in fig. 3 is shown in fig. 6, so that the preset format of the target code is the same as the format of the feature requirement used in the adjustment.
While, for purposes of simplicity of explanation, the foregoing method embodiments have been described as a series of acts or combination of acts, it will be appreciated by those skilled in the art that the present invention is not limited by the illustrated ordering of acts, as some steps may occur in other orders or concurrently with other steps in accordance with the invention. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required by the invention.
Corresponding to the above method embodiment, an embodiment of the present invention further provides a code format adjusting apparatus, whose structure is shown in fig. 7, and may include: an acquisition unit 11, an adjustment unit 12, and an output unit 13.
The obtaining module 11 is configured to obtain a to-be-processed code that needs to be subjected to code format adjustment, and for an obtaining manner, for example: the obtaining module 11 obtains a section of program code written by a programmer with the help of a terminal, such as a computer, a mobile phone, and the like, when the terminal detects that the program code is written, the terminal obtains a code to be processed, and when the terminal detects that the program code is written, the terminal can detect that the programmer triggers a writing completion control, and if the programmer clicks a saving control, the programmer completes one or part of writing.
The adjusting module 12 is configured to perform format adjustment on the code to be processed based on the preset code feature to obtain the target code with the preset format, where the preset code feature is an adjustment standard based on which the format of the code to be processed is adjusted, so that the target code has the preset format indicated by the preset code feature, and thus the format of the target code to be finally output can be specified by limiting the preset code feature, so that the preset format can be indicated by the preset code feature in this embodiment.
One way of adjustment is: by artificially specifying preset code characteristics, for example: the programmer writes a code frame which needs to be followed by other programmers and specifies the requirements of the relationship among each line, each character/character group, the header file and the characters, and then the requirements can be regarded as preset code characteristics, so that the target code has the uniform format which is desired by the programmer, and based on the mode, the content of the code to be processed only needs to be replaced by the content in the code frame when the code to be processed is written, so that the target code with the preset format indicated by the code frame is obtained.
Another possible way is: one template code is selected from a plurality of codes to be processed so as to obtain preset code characteristics from the template code, and then the adjustment is carried out based on the preset code characteristics.
However, for a certain code to be processed, all features in the preset code features cannot be all applied to the code to be processed, at this time, features matched with the code to be processed need to be extracted from the preset code features, and format adjustment is performed on the code to be processed based on the features matched with the code to be processed.
And the output module 13 is configured to output the object codes with the preset format, where the preset formats of the object codes obtained after different codes to be processed are adjusted by preset code characteristics are the same.
After format adjustment is carried out through the preset code characteristics, the formats of the output target codes are all preset formats, so that the formats of the target codes are the same, the requirement of converting different formats of codes to be processed into a uniform format can be met only by setting the preset code characteristics, and compared with manual format adjustment, the method is accurate and efficient.
According to the technical scheme, after the codes to be processed, which need to be subjected to code format adjustment, are obtained, format adjustment is performed on the codes to be processed based on the preset code characteristics, the target codes with the preset format are obtained, the target codes with the preset format are output, the preset formats of the target codes obtained after different codes to be processed are adjusted through the preset code characteristics are the same, the formats of the different codes to be processed are changed from diversification to tidiness, the formats of the different codes to be processed are unified, the unified format can enable each programmer to accurately understand the thought and the intention of the codes, the readability of the codes is obviously improved, the codes can be accurately changed on the basis of accurately understanding the thought and the intention, the codes can be modified and maintained, in addition, the codes to be processed can be automatically subjected to format adjustment based on the preset code characteristics, the link of adjusting or setting the format by a programmer is saved, the manual adjusting time is saved, and the adjusting efficiency is improved.
An optional structure of the adjusting module 12 in this embodiment is: the adjusting module 12 includes an extracting unit and an adjusting unit.
And the extraction unit is used for extracting the characteristics matched with the codes to be processed from the preset code characteristics.
And the adjusting unit is used for carrying out format adjustment on the code to be processed based on the characteristics matched with the code to be processed to obtain the target code with the preset format.
The specific extraction unit may include a determination subunit, a type adjustment feature extraction subunit, and a common adjustment feature selection subunit.
And the determining subunit is used for determining the type corresponding to each independent component in the code to be processed, wherein any independent component in each independent component is a character string or a character. That is to say, for the code to be processed, the code to be processed is composed of two types of independent components, namely a character string and a character, it is to be noted that the character is a single character, and the character string is a set of a plurality of characters, and the specific description of the character and the character string refers to the related method embodiment, and will not be further described here.
The type adjustment feature extraction subunit is configured to extract, based on a type corresponding to each independent component, a type adjustment feature corresponding to the type from a preset code feature, where the specific type adjustment feature is used to define a writing specification to be followed by the type of independent component when writing, for example, whether an upper case character or a lower case character needs to be used for the type of independent component, whether an interval exists between the type of independent component and an adjacent independent component, and the like, and for a description of the type adjustment feature, refer to a related description in the method embodiment.
A common adjustment feature selecting subunit, configured to select a common adjustment feature from the preset code features, where the common adjustment feature is used to perform format limitation on a portion of the to-be-processed code other than the independent component, that is, the preset code feature is composed of a type adjustment feature and a common adjustment feature, and the common adjustment feature is a feature applicable to all the to-be-processed codes, for example, each to-be-processed code has multiple lines of codes, and even further includes a header file, which is a common portion of multiple to-be-processed codes, so that the common adjustment feature may be used to define formats of the lines of codes, and for an example of the common adjustment feature, reference is not described in detail in the related method embodiment.
According to the technical scheme, when the format of the code to be processed is adjusted, the type adjustment characteristic of the independent component part suitable for the code to be processed is selected based on the independent component part of the code to be processed, so that the code to be processed is adjusted based on the type adjustment characteristic and the shared adjustment characteristic of the independent component part suitable for the code to be processed, and the code is adjusted only based on the shared adjustment characteristic and the type adjustment characteristic required by the code to be processed.
As shown in fig. 8, which illustrates another code format adjusting apparatus provided in the embodiment of the present invention, on the basis of fig. 7, the apparatus may further include: a template code obtaining module 14, a type adjustment feature determination module 15 and a common adjustment feature determination module 16.
And a template code obtaining module 14, configured to obtain a template code for obtaining the preset code characteristics. The template code is one of a plurality of codes to be processed, and can be designated by a programmer or randomly selected from the plurality of codes to be processed to serve as the template code.
A type adjustment feature determining module 15, configured to determine all type adjustment features corresponding to each independent component in the template code, and please refer to related method embodiments for how to determine all type adjustment features in the template code, which is not described herein.
A common adjustment feature determining module 16, configured to determine various common adjustment features applicable to each line of code in the template code, and please refer to related method embodiments for how to determine all common adjustment features in the template code, which will not be described herein.
According to the technical scheme, the preset code characteristics suitable for each code to be processed are extracted from the template codes, so that an adjustment standard is provided for the format adjustment of the code to be processed, and thus target codes adjusted according to the preset code characteristics can have a uniform format.
It should be noted that, in the present specification, the embodiments are all described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. For the device-like embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. The term "comprising", without further limitation, means that the element so defined is not excluded from the group consisting of additional identical elements in the process, method, article, or apparatus that comprises the element.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

Claims (8)

1. A method for adjusting a code format, the method comprising:
acquiring a code to be processed which needs to be subjected to code format adjustment;
carrying out format adjustment on the code to be processed based on preset code characteristics to obtain a target code with a preset format;
outputting the target codes with the preset format, wherein the preset formats of the target codes obtained after different codes to be processed are adjusted by the preset code characteristics are the same;
the preset code feature obtaining process comprises the following steps:
obtaining a template code for obtaining the preset code characteristics;
determining all types of adjustment features corresponding to each independent component in the template code;
adjusting characteristics for all types corresponding to any one of the individual components: if the relationship between one type of adjustment feature corresponding to the independent component and all types of adjustment features corresponding to the independent component meets a first preset relationship, determining the type of adjustment feature meeting the first preset relationship as a preset code feature;
determining various common adjustment characteristics suitable for each line of codes in the template codes;
sharing an adjustment feature for any one of the various types of shared adjustment features: if the relationship between one common adjustment feature in the class and all the common adjustment features in the class meets a second preset relationship, determining the common adjustment feature meeting the second preset relationship as a preset code feature;
if the relationship between one type of adjustment feature corresponding to the independent component and all types of adjustment features corresponding to the independent component satisfies a first preset relationship, determining the type of adjustment feature satisfying the first preset relationship as a preset code feature, including:
calculating the application proportion of one type of adjustment feature corresponding to the independent component to all types of adjustment features corresponding to the independent component;
if the application proportion exceeds a first preset threshold, determining the type adjustment characteristic of which the application proportion exceeds the first preset threshold as a preset code characteristic;
if the application proportion exceeds a plurality of type adjustment characteristics of a first preset threshold value, selecting one of the type adjustment characteristics of which the application proportion exceeds the first preset threshold value as a preset code characteristic;
if the relationship between one common adjustment feature in the class and all the common adjustment features in the class satisfies a second preset relationship, determining the common adjustment feature satisfying the second preset relationship as a preset code feature, including:
calculating the application proportion of one common adjusting characteristic in the class to all common adjusting characteristics in the class;
if the application proportion exceeds a second preset threshold, determining the common adjustment characteristic of which the application proportion exceeds the second preset threshold as a preset code characteristic;
and if the application proportion exceeds a plurality of common adjusting characteristics of a second preset threshold value, selecting one common adjusting characteristic of which the application proportion exceeds the second preset threshold value as a preset code characteristic.
2. The method of claim 1, wherein the format adjustment of the to-be-processed code based on the preset code characteristics to obtain the target code with a preset format comprises:
extracting features matched with the codes to be processed from the preset code features;
and adjusting the format of the code to be processed based on the characteristics matched with the code to be processed to obtain a target code with a preset format.
3. The method according to claim 2, wherein the extracting the feature matching the to-be-processed code from the preset code features comprises:
determining the type corresponding to each independent component in the code to be processed, wherein any independent component in each independent component is a character string or a character;
extracting type adjustment features corresponding to the types from the preset code features based on the types corresponding to the independent components respectively;
and selecting a common adjusting feature from the preset code features, wherein the common adjusting feature is used for carrying out format limitation on the parts except the independent components in the code to be processed.
4. The method according to claim 3, wherein the determining the type corresponding to each independent component in the code to be processed comprises:
obtaining a character group included by each line of characters in the code to be processed, wherein the character group included by any line of characters comprises: a character group between the first character and the 1 st space in the line of characters, a character group between the last character and the nth space in the line of characters, and a character group between the ith space and the (i + 1) th space, wherein the value of i is 2 to n-1, and n is the total number of spaces included in the code to be processed;
the following steps are performed for any character group:
if all contents carried by the character group are one of numbers, operators, punctuation marks and preset reserved words, the type of the character group is the type corresponding to all the contents, if the number of characters in the character group is more than 1, the character group is determined to be a character string, and if the number of characters in the character group is equal to 1, the character group is determined to be a character;
if all contents carried by the character group do not comprise numbers, operators, punctuation marks and preset reserved words, the type of the character group is an independent variable type, if the number of characters in the character group is more than 1, the character group is determined to be a character string, and if the number of characters in the character group is equal to 1, the character group is determined to be a character;
if the number of the characters in the character group is more than 1 and the character group comprises at least one preset character, splitting the character group through the preset character, determining the preset character as one character, wherein the type of the character is the same as that of the preset character, and the preset character comprises at least one of an operator, a punctuation mark and a number;
any part of the parts obtained by splitting the preset character is divided into: if the number of characters in the part is equal to 1, determining that the part is a character and the type of the character is an argument type, if the number of characters in the part is greater than 1, determining that the part is a character string, if the character string is the same as one of preset reserved words, determining that the type of the character string is a reserved word type, otherwise, determining that the type of the character string is an argument type.
5. An apparatus for adjusting a code format, the apparatus comprising:
the acquisition module is used for acquiring a code to be processed which needs to be subjected to code format adjustment;
the adjusting module is used for carrying out format adjustment on the code to be processed based on preset code characteristics to obtain a target code with a preset format;
the output module is used for outputting the target codes with the preset format, wherein the preset formats of the target codes obtained after different codes to be processed are adjusted by the preset code characteristics are the same;
the device further comprises:
the template code obtaining module is used for obtaining a template code used for obtaining the preset code characteristics;
a type adjustment feature determining module, configured to determine all type adjustment features corresponding to each independent component in the template code, and for all type adjustment features corresponding to any one independent component in each independent component: if the relationship between one type of adjustment feature corresponding to the independent component and all types of adjustment features corresponding to the independent component meets a first preset relationship, determining the type of adjustment feature meeting the first preset relationship as a preset code feature;
a common adjustment feature determining module, configured to determine various common adjustment features applicable to each line of codes in the template codes, and for any one of the various common adjustment features, share an adjustment feature: if the relationship between one common adjustment feature in the class and all the common adjustment features in the class meets a second preset relationship, determining the common adjustment feature meeting the second preset relationship as a preset code feature;
if the relationship between one type of adjustment feature corresponding to the independent component and all types of adjustment features corresponding to the independent component satisfies a first preset relationship, determining the type of adjustment feature satisfying the first preset relationship as a preset code feature, including:
calculating the application proportion of one type of adjustment feature corresponding to the independent component to all types of adjustment features corresponding to the independent component;
if the application proportion exceeds a first preset threshold, determining the type adjustment characteristic of which the application proportion exceeds the first preset threshold as a preset code characteristic;
if the application proportion exceeds a plurality of type adjustment characteristics of a first preset threshold value, selecting one of the type adjustment characteristics of which the application proportion exceeds the first preset threshold value as a preset code characteristic;
if the relationship between one common adjustment feature in the class and all the common adjustment features in the class satisfies a second preset relationship, determining the common adjustment feature satisfying the second preset relationship as a preset code feature, including:
calculating the application proportion of one common adjusting characteristic in the class to all common adjusting characteristics in the class;
if the application proportion exceeds a second preset threshold, determining the common adjustment characteristic of which the application proportion exceeds the second preset threshold as a preset code characteristic;
and if the application proportion exceeds a plurality of common adjusting characteristics of a second preset threshold value, selecting one common adjusting characteristic of which the application proportion exceeds the second preset threshold value as a preset code characteristic.
6. The apparatus of claim 5, wherein the adjustment module comprises:
the extraction unit is used for extracting features matched with the codes to be processed from the preset code features;
and the adjusting unit is used for carrying out format adjustment on the code to be processed based on the characteristics matched with the code to be processed to obtain a target code with a preset format.
7. The apparatus of claim 6, wherein the extraction unit comprises:
the determining subunit is used for determining the type corresponding to each independent component in the code to be processed, wherein any independent component in each independent component is a character string or a character;
a type adjustment feature extraction subunit, configured to extract, based on a type corresponding to each of the independent components, a type adjustment feature corresponding to the type from the preset code feature;
and the common adjustment feature selection subunit is used for selecting a common adjustment feature from the preset code features, wherein the common adjustment feature is used for carrying out format limitation on the parts except the independent components in the code to be processed.
8. The apparatus according to claim 7, wherein the determining subunit is specifically configured to obtain a character group included in each line of characters in the code to be processed, where a character group included in any line of characters includes: a character group between the first character and the 1 st space in the line of characters, a character group between the last character and the nth space in the line of characters, and a character group between the ith space and the (i + 1) th space, wherein the value of i is 2 to n-1, and n is the total number of spaces included in the code to be processed;
the following steps are performed for any character group:
if all contents carried by the character group are one of numbers, operators, punctuation marks and preset reserved words, the type of the character group is the type corresponding to all the contents, if the number of characters in the character group is more than 1, the character group is determined to be a character string, and if the number of characters in the character group is equal to 1, the character group is determined to be a character;
if all contents carried by the character group do not comprise numbers, operators, punctuation marks and preset reserved words, the type of the character group is an independent variable type, if the number of characters in the character group is more than 1, the character group is determined to be a character string, and if the number of characters in the character group is equal to 1, the character group is determined to be a character;
if the number of the characters in the character group is more than 1 and the character group comprises at least one preset character, splitting the character group through the preset character, determining the preset character as one character, wherein the type of the character is the same as that of the preset character, and the preset character comprises at least one of an operator, a punctuation mark and a number;
any part of the parts obtained by splitting the preset character is divided into: if the number of characters in the part is equal to 1, determining that the part is a character and the type of the character is an argument type, if the number of characters in the part is greater than 1, determining that the part is a character string, if the character string is the same as one of preset reserved words, determining that the type of the character string is a reserved word type, otherwise, determining that the type of the character string is an argument type.
CN201811618411.1A 2018-12-27 2018-12-27 Code format adjusting method and device Active CN109683881B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811618411.1A CN109683881B (en) 2018-12-27 2018-12-27 Code format adjusting method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811618411.1A CN109683881B (en) 2018-12-27 2018-12-27 Code format adjusting method and device

Publications (2)

Publication Number Publication Date
CN109683881A CN109683881A (en) 2019-04-26
CN109683881B true CN109683881B (en) 2022-04-05

Family

ID=66190111

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811618411.1A Active CN109683881B (en) 2018-12-27 2018-12-27 Code format adjusting method and device

Country Status (1)

Country Link
CN (1) CN109683881B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112486566A (en) * 2020-10-23 2021-03-12 百果园技术(新加坡)有限公司 Code file processing method, device, equipment and storage medium
CN112631606A (en) * 2020-12-31 2021-04-09 中国农业银行股份有限公司 Script formatting method and device
CN113703736A (en) * 2021-08-31 2021-11-26 四川启睿克科技有限公司 Web project code optimization method
CN113791768B (en) * 2021-09-22 2023-04-14 海通证券股份有限公司 Code generation method and device, storage medium and terminal

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6226658B1 (en) * 1998-06-19 2001-05-01 Hewlett-Packard Company Layout code tuning in universally readable document files
CN104050085A (en) * 2014-06-25 2014-09-17 北京思特奇信息技术股份有限公司 Forced code standard inspection method and system
CN107357733A (en) * 2017-07-17 2017-11-17 万帮充电设备有限公司 Improve the method and device of code quality
CN107885715A (en) * 2017-11-23 2018-04-06 掌阅科技股份有限公司 Composition method, electronic equipment and the computer-readable storage medium of code information
CN109032949A (en) * 2018-08-02 2018-12-18 郑州悉知信息科技股份有限公司 A kind of front-end code quality determining method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6226658B1 (en) * 1998-06-19 2001-05-01 Hewlett-Packard Company Layout code tuning in universally readable document files
CN104050085A (en) * 2014-06-25 2014-09-17 北京思特奇信息技术股份有限公司 Forced code standard inspection method and system
CN107357733A (en) * 2017-07-17 2017-11-17 万帮充电设备有限公司 Improve the method and device of code quality
CN107885715A (en) * 2017-11-23 2018-04-06 掌阅科技股份有限公司 Composition method, electronic equipment and the computer-readable storage medium of code information
CN109032949A (en) * 2018-08-02 2018-12-18 郑州悉知信息科技股份有限公司 A kind of front-end code quality determining method and device

Also Published As

Publication number Publication date
CN109683881A (en) 2019-04-26

Similar Documents

Publication Publication Date Title
CN109683881B (en) Code format adjusting method and device
CN106649783B (en) Synonym mining method and device
CN109344230B (en) Code library file generation, code search, coupling, optimization and migration method
CN111259873B (en) Table data extraction method and device
CN108829884B (en) Data mapping method and device
CN104199871A (en) High-speed test question inputting method for intelligent teaching
CN109508448A (en) Short information method, medium, device are generated based on long article and calculate equipment
CN110543303A (en) Visual business platform
CN115358200A (en) Template document automatic generation method based on SysML meta model
CN112395425A (en) Data processing method and device, computer equipment and readable storage medium
CN110275938B (en) Knowledge extraction method and system based on unstructured document
Yu et al. Design and implementation of curriculum system based on knowledge graph
CN109710304B (en) Format adjustment method and device
CN104090865B (en) Text similarity computing method and device
US11610051B2 (en) Dynamically generating documents using natural language processing and dynamic user interface
CN103365640A (en) Cascading style sheet style transformation method and device
CN110362691B (en) Syntax tree bank construction system
WO2019080419A1 (en) Method for building standard knowledge base, electronic device, and storage medium
CN112506488A (en) Method for generating programming language class based on sql creating statement
CN106951540B (en) Generation method, device, server and the computer-readable storage medium of file directory
CN104657340A (en) Expandable script-based Word report generating system and method
Krishna et al. SHR++: An interface for morpho-syntactic annotation of Sanskrit corpora
CN113536182A (en) Method and device for generating long text webpage, electronic equipment and storage medium
Grønvik et al. What should the electronic dictionary do for you–and how?
Andrews Digital Techniques for Critical Edition

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