Source code modification-writesourcefile

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. IO;
Using system. text;

Namespace source code modification
{
Public class writesourcefile: ioperatesource
{
Private readdocument;
Private list <string> sourcefilecontent;
Private int amountofchanges;
Public int amountofchanges
{
Get
{
Return amountofchanges;
}
}

Public writesourcefile (readdocument)
{
This. readdocument = readdocument;
Sourcefilecontent = new list <string> ();
Amountofchanges = 0;
}

// Streamline the code.
Private void simplifyaline (ref string Aline)
{
Bool doublequotationhasopend = false;

For (INT I = 0; I! = Aline. length; ++ I)
{
If (Aline [I] = '"')
Doublequotationhasopend =! Doublequotationhasopend;
Else if (Aline [I] = ';')
{
If (doublequotationhasopend)
{
// It appears in the String constant in the Code;
Continue;
}
Else
{
// This is the end code;
If (I + 1! = Aline. length)
{
Aline = Aline. Remove (I + 1 );
Return;
}
// Otherwise, the Code does not need to be streamlined
}
}
}
}

// Remove the code before adding comments.
Private void addexegesis (ref string aprocessedline, string originalstring)
{
Simplifyaline (ref aprocessedline );
Aprocessedline + = ("//" + originalstring );
}

Private void processaline (ref string Aline)
{
For (INT I = 0; I <Aline. length; ++ I)
{
If (Aline [I] = keychar & I + 1 <Aline. length & Aline [I + 1] = '"' & I + 2 <Aline. length)
{
String originalstring = NULL;
For (Int J = I + 2; j <Aline. Length & Aline [J]! = '"'; ++ J)
Originalstring + = Aline [J];
If (readdocument. containsoriginalstring (originalstring ))
{
++ Amountofchanges;
Aline = Aline. Replace (originalstring, readdocument. gettargetstring (originalstring ));
Addexegesis (ref Aline, originalstring );
}
// Used to deal with the situation where multiple strings to be translated appear in one row
I + = (originalstring. Length + 2 );
}
}
}

Override public void go (fileinfo sourcefineinfo)
{
// Replace the information you want to replace with the corresponding content in the document.
Streamreader reader = sourcefineinfo. opentext ();
String Aline = reader. Readline ();
While (Aline! = NULL)
{
Processaline (ref Aline );
Sourcefilecontent. Add (Aline );
Aline = reader. Readline ();
}
Reader. Close ();
Streamwriter writer = new streamwriter (sourcefineinfo. fullname, false, encoding. utf8 );
Foreach (string aprocessedline in sourcefilecontent)
{
Writer. writeline (aprocessedline );
}
Writer. Close ();
Sourcefilecontent. Clear ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.