Moved Trim functions into Global file
parent
cd21f739ae
commit
0b43b14b18
|
@ -1,2 +1,36 @@
|
||||||
#include "Globals.h"
|
#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_
|
#define GLOBALS_H_
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
const double kAE = 1.0;
|
const double kAE = 1.0;
|
||||||
const double kQ0 = 120.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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -128,8 +128,8 @@ void RunTest(const char* infile) {
|
||||||
/*
|
/*
|
||||||
* trim spaces
|
* trim spaces
|
||||||
*/
|
*/
|
||||||
Tle::TrimLeft(line);
|
TrimLeft(line);
|
||||||
Tle::TrimRight(line);
|
TrimRight(line);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* skip blank lines or lines starting with #
|
* 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);
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
2
Tle.h
2
Tle.h
|
@ -100,8 +100,6 @@ public:
|
||||||
*/
|
*/
|
||||||
static bool IsValidPair(const std::string& line1, const std::string& line2);
|
static bool IsValidPair(const std::string& line1, const std::string& line2);
|
||||||
static bool IsValidLine(const std::string& str, unsigned char line_number);
|
static bool IsValidLine(const std::string& str, unsigned char line_number);
|
||||||
static void TrimLeft(std::string& str);
|
|
||||||
static void TrimRight(std::string& str);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue