Moved Trim functions into Global file
parent
cd21f739ae
commit
0b43b14b18
|
@ -1,2 +1,36 @@
|
|||
#include "Globals.h"
|
||||
|
||||
void TrimLeft(std::string& str) {
|
||||
|
||||
std::string whitespaces(" \t\f\n\r");
|
||||
|
||||
if (!str.empty()) {
|
||||
std::string::size_type pos = str.find_first_not_of(whitespaces);
|
||||
|
||||
if (pos != std::string::npos)
|
||||
str.erase(0, pos);
|
||||
else
|
||||
str.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void TrimRight(std::string& str) {
|
||||
|
||||
std::string whitespaces(" \t\f\n\r");
|
||||
|
||||
if (!str.empty()) {
|
||||
std::string::size_type pos = str.find_last_not_of(whitespaces);
|
||||
|
||||
if (pos != std::string::npos)
|
||||
str.erase(pos + 1);
|
||||
else
|
||||
str.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void Trim(std::string& str) {
|
||||
|
||||
TrimLeft(str);
|
||||
TrimRight(str);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define GLOBALS_H_
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
const double kAE = 1.0;
|
||||
const double kQ0 = 120.0;
|
||||
|
@ -97,6 +98,9 @@ inline double AcTan(const double sinx, const double cosx) {
|
|||
}
|
||||
}
|
||||
|
||||
void TrimLeft(std::string& str);
|
||||
void TrimRight(std::string& str);
|
||||
void Trim(std::string& str);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -128,8 +128,8 @@ void RunTest(const char* infile) {
|
|||
/*
|
||||
* trim spaces
|
||||
*/
|
||||
Tle::TrimLeft(line);
|
||||
Tle::TrimRight(line);
|
||||
TrimLeft(line);
|
||||
TrimRight(line);
|
||||
|
||||
/*
|
||||
* skip blank lines or lines starting with #
|
||||
|
|
35
Tle.cpp
35
Tle.cpp
|
@ -294,38 +294,3 @@ int Tle::CheckSum(const std::string& str) {
|
|||
|
||||
return (xsum % 10);
|
||||
}
|
||||
|
||||
/*
|
||||
* trim left of string
|
||||
*/
|
||||
void Tle::TrimLeft(std::string& str) {
|
||||
|
||||
std::string whitespaces(" \t\f\n\r");
|
||||
|
||||
if (!str.empty()) {
|
||||
std::string::size_type pos = str.find_first_not_of(whitespaces);
|
||||
|
||||
if (pos != std::string::npos)
|
||||
str.erase(0, pos);
|
||||
else
|
||||
str.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* trim right of string
|
||||
*/
|
||||
void Tle::TrimRight(std::string& str) {
|
||||
|
||||
std::string whitespaces(" \t\f\n\r");
|
||||
|
||||
if (!str.empty()) {
|
||||
std::string::size_type pos = str.find_last_not_of(whitespaces);
|
||||
|
||||
if (pos != std::string::npos)
|
||||
str.erase(pos + 1);
|
||||
else
|
||||
str.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue