Skip to content

Commit 3fe556b

Browse files
committed
Fix: remove comment from line before interpretation
1 parent a2e43de commit 3fe556b

File tree

7 files changed

+48
-38
lines changed

7 files changed

+48
-38
lines changed

src/datafile.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void NewFile::clear()
201201
points.clear();
202202
}
203203

204-
bool NewFile::interpret_line(const std::string &line, int line_num)
204+
bool NewFile::interpret_line(std::string line, int line_num)
205205
{
206206
points_owner.push_back(std::make_unique<Point>(this,line_num));
207207
if (points_owner.back()->read_point(line, true))
@@ -240,7 +240,7 @@ void CORFile::clear()
240240
new_points.clear();
241241
}
242242

243-
bool CORFile::interpret_line(const std::string &line, int line_num)
243+
bool CORFile::interpret_line(std::string line, int line_num)
244244
{
245245
//std::cout<<"Interpret \""<<line<<"\" as a COR line"<<std::endl;
246246
Project::theone()->points.emplace_back(this,line_num);
@@ -520,7 +520,7 @@ void OBSFile::clear()
520520
sub_files.clear();
521521
}
522522

523-
bool OBSFile::interpret_line(const std::string &line, int line_num)
523+
bool OBSFile::interpret_line(std::string line, int line_num)
524524
{
525525
//std::cout<<"Interpret \""<<line<<"\" as an OBS line"<<std::endl;
526526
std::regex regex_line(R"(^\s*([^*\s]+)\*?(.*)$)");
@@ -613,7 +613,10 @@ bool OBSFile::interpret_line(const std::string &line, int line_num)
613613
std::string comment="";
614614
std::size_t comment_pos = line.find('*');
615615
if (comment_pos!=std::string::npos)
616-
comment=line.substr(line.find('*')+1);
616+
{
617+
comment=line.substr(comment_pos+1);
618+
line=line.substr(0,comment_pos); // remove comment
619+
}
617620

618621
std::string file_path=current_absolute_path+"/"+filename.c_str();
619622
fs::path next_path=file_path;
@@ -732,7 +735,7 @@ std::unique_ptr<XYZFile> XYZFile::create(const std::string &_filename, Station_B
732735

733736
void XYZFile::clear() {}
734737

735-
bool XYZFile::interpret_line(const std::string &line, int line_num)
738+
bool XYZFile::interpret_line(std::string line, int line_num)
736739
{
737740
std::regex regex_line(R"(^\s*([^*]+)\*?(.*)$)");
738741
std::smatch what;
@@ -743,9 +746,9 @@ bool XYZFile::interpret_line(const std::string &line, int line_num)
743746
// what[2] contains the comment part
744747
if ((what[1]).length()>1)//there is something on the line
745748
{
746-
std::string line_data=what[1];
749+
line=what[1];
747750
station->observations3D.emplace_back(station);
748-
if (!station->observations3D.back().read_obs(line_data,line_num,this,what[2]))
751+
if (!station->observations3D.back().read_obs(line,line_num,this,what[2]))
749752
station->observations3D.pop_back();
750753
else
751754
return true;
@@ -978,7 +981,7 @@ std::unique_ptr<AxisFile> AxisFile::create(const std::string &_filename, Station
978981

979982
void AxisFile::clear() {}
980983

981-
bool AxisFile::interpret_line(const std::string &line, int line_num)
984+
bool AxisFile::interpret_line(std::string line, int line_num)
982985
{
983986
//File format:
984987
//target_num pos_num ground_pt sigma_rayon sigma_perp
@@ -991,13 +994,13 @@ bool AxisFile::interpret_line(const std::string &line, int line_num)
991994
// what[2] contains the comment part
992995
if ((what[1]).length()>1)//there is something on the line
993996
{
994-
std::string line_data=what[1];
995-
if (line_data[0]=='L')
997+
line=what[1];
998+
if (line[0]=='L')
996999
{
997-
return station->read_constr(line_data,line_num,this,what[2]);
1000+
return station->read_constr(line,line_num,this,what[2]);
9981001
}else{
9991002
AxisObs obsAx(station);
1000-
if (obsAx.read_obs(line_data,line_num,this,what[2]))
1003+
if (obsAx.read_obs(line,line_num,this,what[2]))
10011004
{
10021005
station->updateTarget(obsAx.getTargetNum(), obsAx);
10031006
return true;
@@ -1030,7 +1033,7 @@ std::unique_ptr<EqFile> EqFile::create(const std::string &_filename, Station_Eq
10301033

10311034
void EqFile::clear() {}
10321035

1033-
bool EqFile::interpret_line(const std::string &line, int line_num)
1036+
bool EqFile::interpret_line(std::string line, int line_num)
10341037
{
10351038
//File format:
10361039
//from to sigma *comm
@@ -1041,6 +1044,7 @@ bool EqFile::interpret_line(const std::string &line, int line_num)
10411044
// what[0] contains the whole string
10421045
// what[1] contains the data part
10431046
// what[2] contains the comment part
1047+
line=what[1];
10441048

10451049
bool ok=true;
10461050
bool active=true;

src/datafile.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class DataFile
4545
virtual void clear()=0;
4646
bool read();
4747
bool read(const std::string &_filename, const std::string &_current_absolute_path);
48-
virtual bool interpret_line(const std::string &line,int line_num)=0;
48+
virtual bool interpret_line(std::string line,int line_num)=0;
4949
virtual bool read_subfile(const std::string &filename, const std::string &absolute_path,int line_num);
5050

5151
std::string get_name() const {return filename;}
@@ -79,7 +79,7 @@ class CORFile:public DataFile
7979
int _line_num_in_parent=-1, unsigned _fileDepth=0);
8080

8181
virtual void clear() override;
82-
virtual bool interpret_line(const std::string &line,int line_num) override;
82+
virtual bool interpret_line(std::string line,int line_num) override;
8383
virtual bool read_subfile(const std::string &filename, const std::string &absolute_path,int line_num) override;
8484

8585
//virtual bool write(std::string new_filename);
@@ -103,7 +103,7 @@ class NewFile:public CORFile
103103
static std::unique_ptr<NewFile> create(const std::string &_filename);
104104

105105
virtual void clear() override;
106-
virtual bool interpret_line(const std::string &line,int line_num) override;
106+
virtual bool interpret_line(std::string line,int line_num) override;
107107
virtual bool read_subfile(const std::string &filename, const std::string &absolute_path,int line_num) override;
108108
std::vector <Point*> get_points(){return points;}
109109
protected:
@@ -120,7 +120,7 @@ class OBSFile:public DataFile
120120
int _line_num_in_parent=-1, unsigned _fileDepth=0);
121121

122122
virtual void clear() override;
123-
virtual bool interpret_line(const std::string &line, int line_num) override;
123+
virtual bool interpret_line(std::string line, int line_num) override;
124124
virtual bool read_subfile(const std::string &filename, const std::string &absolute_path,int line_num) override;
125125
protected:
126126
explicit OBSFile(const std::string &_filename, const std::string &_current_absolute_path,
@@ -137,7 +137,7 @@ class XYZFile:public DataFile
137137
int _line_num_in_parent=-1, unsigned _fileDepth=0);
138138

139139
virtual void clear() override;
140-
virtual bool interpret_line(const std::string &line, int line_num) override;
140+
virtual bool interpret_line(std::string line, int line_num) override;
141141

142142
bool finalizeFile() const;//write matrix in XYZ file
143143
protected:
@@ -156,7 +156,7 @@ class AxisFile:public DataFile
156156
int _line_num_in_parent=-1, unsigned _fileDepth=0);
157157

158158
virtual void clear() override;
159-
virtual bool interpret_line(const std::string &line, int line_num) override;
159+
virtual bool interpret_line(std::string line, int line_num) override;
160160
protected:
161161
AxisFile(const std::string &_filename, Station_Axis *_station,
162162
const std::string &_current_absolute_path,
@@ -173,7 +173,7 @@ class EqFile:public DataFile
173173
int _line_num_in_parent=-1, unsigned _fileDepth=0);
174174

175175
virtual void clear() override;
176-
virtual bool interpret_line(const std::string &line, int line_num) override;
176+
virtual bool interpret_line(std::string line, int line_num) override;
177177
protected:
178178
EqFile(const std::string &_filename, Station_Eq *_station,
179179
const std::string &_current_absolute_path,

src/point.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ bool Point::read_point(std::string line, bool fromNEW)
263263
std::regex regex_line("^(.*)\\*([^\r]*)(\r)?$");//is there a * somewhere? (remove ending \r if using win file on unix)
264264
std::smatch what;
265265
if(std::regex_match(line, what, regex_line))
266+
{
266267
comment=what[2];
268+
line=what[1];
269+
}
267270

268271
Coord _coord_read;
269272
Coord _sigmas_init;

src/station_hz.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ bool Station_Hz::read_obs(std::string line, int line_number, DataFile *_file,
181181
{
182182
Project::theInfo()->warning(INFO_OBS,_file->get_fileDepth()+1,
183183
QT_TRANSLATE_NOOP("QObject","In %s:%d: Wrong format in: %s"),
184-
_file->get_name().c_str(),line_number,line.c_str());
184+
_file->get_name().c_str(),line_number,
185+
(line+(comment.empty()?"":"*"+comment)).c_str());
185186
return false;
186187
}
187188

src/station_simple.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ bool Station_Simple::read_obs(std::string line, int line_number, DataFile *_file
127127
{
128128
Project::theInfo()->warning(INFO_OBS,_file->get_fileDepth()+1,
129129
QT_TRANSLATE_NOOP("QObject","In %s:%d: Wrong format in: %s"),
130-
_file->get_name().c_str(),line_number,line.c_str());
130+
_file->get_name().c_str(),line_number,
131+
(line+(comment.empty()?"":"*"+comment)).c_str());
131132
return false;
132133
}
133134

tests/data/syntax_error2/ex_ref.comp

Lines changed: 16 additions & 15 deletions
Large diffs are not rendered by default.

tests/tests_nonreg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void Tests_NonReg::test_syntax_error2()
338338
{
339339
std::cout<<"\nPrepare test_syntax_error2"<<std::endl;
340340
std::string refFile="./data/syntax_error2/ex_ref.comp";
341-
std::string refMD5="3e2228623b1cb08d51b4e492de7dc063";
341+
std::string refMD5="fdfbe34cb2d58ad36b3e6fae98b532b9";
342342

343343
test_template(refFile, refMD5,false);
344344
}

0 commit comments

Comments
 (0)