using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace 源代码修改
{
// 读出关键字符串到目标文档
// 过滤重复字符串
public class ReadSourceFile : IOperateSource
{
WriteDocument writeDocument;
public ReadSourceFile(WriteDocument writeDocument)
{
this.writeDocument = writeDocument;
}
private void ProcessALine(string aLine, string sourceFileName)
{
for (int i = 0; i < aLine.Length; ++i)
{
if (aLine[i] == KeyChar && i + 1 < aLine.Length && aLine[i + 1] == '"' && i + 2 < aLine.Length)
{
string constantString = null;
for (int j = i + 2; j < aLine.Length && aLine[j] != '"'; ++j)
constantString += aLine[j];
writeDocument.WriteAString(constantString,sourceFileName, aLine);
// 用以应对一行中出现多个待翻译字符串的情况
i += (constantString.Length + 2);
}
}
}
private string GeneratePathName(string parrentName, string fileName)
{
return parrentName + "/" + fileName;
}
override public void Go(FileInfo sourceFileInfo)
{
// 摘取想要的信息读进文档
StreamReader reader = sourceFileInfo.OpenText();
string aLine = reader.ReadLine();
while (aLine != null)
{
ProcessALine(aLine, sourceFileInfo.Name);
aLine = reader.ReadLine();
}
reader.Close();
}
}
}