Moved Trim functions into Global file

feature/19
Daniel Warner 2011-05-27 16:51:23 +00:00
parent cd21f739ae
commit 0b43b14b18
5 changed files with 40 additions and 39 deletions

34
Globals.cpp Normal file → Executable file
View File

@ -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);
}

4
Globals.h Normal file → Executable file
View File

@ -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

4
RunTest.cpp Normal file → Executable file
View File

@ -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
View File

@ -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
View File

@ -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:
/* /*