public void TextToDelphiStringTest() { string lInput = "\r\nIt's hard to do\r\nThis kind of testing\xFF\xFF"; string lExpected = "#13#10'It''s hard to do'#13#10'This kind of testing'#255#255"; string lActual = TDelphiSource.TextToDelphiString(lInput); Assert.AreEqual(lExpected, lActual, "DelphiStringToText has result is incorrect."); }
/// <summary> /// After a rename of the unit the a the Delphi main file /// must rename the file name if it exists. /// </summary> /// <param name="aOldUnitName"></param> /// <param name="aNewUnitName"></param> /// <param name="aScanner"></param> protected override void AfterRenameUnitName(string aOldUnitName, string aNewUnitName, TUnitScanner aScanner) { aScanner.EndToken = DelphiToken.Delimiter; if (aScanner.GotoNextToken(DelphiToken.inKeyword)) { if (aScanner.GotoNextToken(DelphiToken.String)) { string lFilePath = TDelphiSource.DelphiStringToText(aScanner.TokenValue); if (IsDelphiPasFile(lFilePath)) { lFilePath = Path.Combine(Path.GetDirectoryName(lFilePath), aNewUnitName) + ".pas"; lFilePath = TDelphiSource.TextToDelphiString(lFilePath); ReplaceText(aScanner, lFilePath); } } } }
/// <summary> /// After a successful rename of a project file this method is called to rename it in the DPR file. /// </summary> /// <param name="aOldFileName">full path of the old file</param> /// <param name="aNewFileName">full path of the new file</param> public virtual void RenameContainedFile(string aOldFileName, string aNewFileName) { const string FILE_Key = "{%File"; try { TUnitScanner lScanner = new TUnitScanner(GetTextLines()); lScanner.GotoNextToken(DelphiToken.EndStatement); // look for semicolen lScanner.EndToken = DelphiToken.EndStatement; // now before an semicolen look for comments while (lScanner.GotoNextToken(DelphiToken.ItemComment)) { if (lScanner.TokenValue.IndexOf(FILE_Key, StringComparison.OrdinalIgnoreCase) == 0) { // save scanner values int lSaveStartIndex = lScanner.StartIndex; int lSaveStartLine = lScanner.StartLine; // move scanner to point inside comment lScanner.StartIndex -= (lScanner.TokenValue.Length - FILE_Key.Length); // scan for delphi string if (lScanner.GotoNextToken(DelphiToken.String)) { string lFileName = TDelphiSource.DelphiStringToText(lScanner.TokenValue); // test to see if the filename is the same ones if (String.Compare(Path.GetFileName(lFileName), Path.GetFileName(aOldFileName), true) == 0) { string lNewFile = PackageUtilities.MakeRelativeIfRooted(aNewFileName, this.ProjectMgr.BaseURI); // move the index based on size of new file name lSaveStartIndex += lNewFile.Length - lFileName.Length; // replace just the string not the whole comment ReplaceText(lScanner, TDelphiSource.TextToDelphiString(lNewFile)); } } // move scanner back to where it should be lScanner.StartIndex = lSaveStartIndex; lScanner.StartLine = lSaveStartLine; } } } catch (Exception ex) { ShowErrorMessageBox(ex.Message, "RenameContainedFile() error"); } }