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 ();
}
}
}