Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gtest generated text file with format like this
................text_file_1......................................

FisheyeLens.
  getCoefficients
  MaxRadius
  DistortUndistortEquidistant
  DistortUndistortEquisolid
  DistortUndistortStereographic
  DistortUndistortOrthographic
  InversePoly
  Rig
  Perlin
Lens.
  DistortUndistort
BrownLens.
  MaxRadius
  DistortUndistort
Environment.
  FloatingPoint
  ComputePrimaryAxis


i want it to be in the following format
..................text_file_2...............................

FisheyeLens.getCoefficients
FisheyeLens.MaxRadius
FisheyeLens.DistortUndistortEquidistant
FisheyeLens.DistortUndistortEquisolid
FisheyeLens.DistortUndistortStereographic
FisheyeLens.DistortUndistortOrthographic
FisheyeLens.InversePoly
FisheyeLens.Rig
FisheyeLens.Perlin
Lens.DistortUndistort
BrownLens.MaxRadius
BrownLens.DistotUndistort
Enviroment.FloatingPoint
Enviroment.ComputerPrimaryAxis


What I have tried:

I have written a code to read the text_file_2

while ( (line=file.ReadLine()) != null)
         {

             writer.WriteStartElement("Test");
             writer.WriteAttributeString("ID", "{AB02A59E-2DF9-4EF4-AD3A-7B14BB3341BC}");
             writer.WriteAttributeString("StartTime", "");
             writer.WriteAttributeString("Description", "Runing Gtest through veracity");
             writer.WriteAttributeString("InstanceName", "RunGTest "+propertyNode);
             writer.WriteAttributeString("Result", "Failed");
             writer.WriteAttributeString("Enabled", "1");
             writer.WriteAttributeString("Checksum", "");
             writer.WriteAttributeString("EndTime", "");


             writer.WriteStartElement("PropertyCollection");
             writer.WriteStartElement("Property");
             writer.WriteAttributeString("Name", "External app path");
             writer.WriteAttributeString("Description", "Specify the path relative to Bin folder or you can specify the absolute path.May use env variable");
             writer.WriteString(textBox1.Text);
             writer.WriteEndElement();//property1

             writer.WriteStartElement("Property");
             writer.WriteAttributeString("Name", "Command line parameters");
             writer.WriteAttributeString("Description", "specify the command line parameter for Gtest");
             writer.WriteString("--gtest_filter =" + line);
             writer.WriteEndElement();//property2

             writer.WriteStartElement("Property");
             writer.WriteAttributeString("Name", "Capture Std Out");
             writer.WriteAttributeString("Description", "Set this to true if the external app uses std out");
             writer.WriteString("1");
             writer.WriteEndElement();//property3

             writer.WriteStartElement("Property");
             writer.WriteAttributeString("Name", "File Name to Capture Std Out");
             writer.WriteAttributeString("Description", "Has effect only when property 'Capture Std Out'is set to true to Capture Std Out");
             writer.WriteString("Output.txt");
             writer.WriteEndElement();//property4

             writer.WriteStartElement("Property");
             writer.WriteAttributeString("Name", "Pass Phrase");
             writer.WriteAttributeString("Description", "Pass phrase to look for in the std out or the output file to determine if the test passed or failed");
             writer.WriteString("FAILED");
             writer.WriteEndElement();//property5

             writer.WriteEndElement();//propertyCollection*/

             writer.WriteEndElement();//Test
             propertyNode += 1;
         }


But i m unsure of how do i do it for text_file_1
Posted
Updated 30-Aug-17 3:09am
v2

You just need to read each line, and if the first character is not a space, and ends with a dot assume it is a new key. Then for each following line just concatenate the two together and write them to the output file.
 
Share this answer
 
The procedure is quite simple:

  • Define a String variable for the prefix
  • Read the input file line by line
  • If a line does not begin with spaces and/or ends with a dot, assign the content to the prefix variable
  • Otherwise, remove leading spaces and write the prefix followed by the trimmed line content to the output file
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900