diff --git a/src/FGJSBBase.cpp b/src/FGJSBBase.cpp index f1c6213912..30b39688be 100644 --- a/src/FGJSBBase.cpp +++ b/src/FGJSBBase.cpp @@ -35,8 +35,6 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#define BASE - #include "FGJSBBase.h" #include "models/FGAtmosphere.h" diff --git a/src/input_output/FGXMLElement.cpp b/src/input_output/FGXMLElement.cpp index c7154287b0..5ac3697e93 100644 --- a/src/input_output/FGXMLElement.cpp +++ b/src/input_output/FGXMLElement.cpp @@ -28,6 +28,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include #include // for assembling the error messages / what of exceptions. #include // using domain_error, invalid_argument, and length_error. #include "FGXMLElement.h" diff --git a/src/input_output/FGfdmSocket.cpp b/src/input_output/FGfdmSocket.cpp index ced3a16c0b..5034068912 100644 --- a/src/input_output/FGfdmSocket.cpp +++ b/src/input_output/FGfdmSocket.cpp @@ -51,6 +51,8 @@ INCLUDES #include #endif #include +#include +#include #include #include "FGfdmSocket.h" diff --git a/src/input_output/string_utilities.cpp b/src/input_output/string_utilities.cpp index 1d4fbd0eca..2031e9dcbe 100644 --- a/src/input_output/string_utilities.cpp +++ b/src/input_output/string_utilities.cpp @@ -35,12 +35,14 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include +#include +#include +#include #ifdef __APPLE__ #include #else #include #endif -#include #include "FGJSBBase.h" #include "string_utilities.h" @@ -51,6 +53,7 @@ typedef _locale_t locale_t; #define strtod_l _strtod_l #endif +namespace JSBSim { struct CNumericLocale { CNumericLocale() @@ -100,3 +103,92 @@ double atof_locale_c(const std::string& input) std::cerr << s.str() << std::endl; throw JSBSim::BaseException(s.str()); } + + +std::string& trim_left(std::string& str) +{ + while (!str.empty() && isspace((unsigned char)str[0])) { + str = str.erase(0,1); + } + return str; +} + +std::string& trim_right(std::string& str) +{ + while (!str.empty() && isspace((unsigned char)str[str.size()-1])) { + str = str.erase(str.size()-1,1); + } + return str; +} + +std::string& trim(std::string& str) +{ + if (str.empty()) return str; + std::string temp_str = trim_right(str); + return str = trim_left(temp_str); +} + +std::string& trim_all_space(std::string& str) +{ + for (size_t i=0; i split(std::string str, char d) +{ + std::vector str_array; + size_t index=0; + std::string temp = ""; + + trim(str); + index = str.find(d); + while (index != std::string::npos) { + temp = str.substr(0,index); + trim(temp); + if (!temp.empty()) str_array.push_back(temp); + str = str.erase(0,index+1); + index = str.find(d); + } + if (!str.empty()) { + temp = trim(str); + if (!temp.empty()) str_array.push_back(temp); + } + + return str_array; +} + +std::string replace(std::string str, const std::string& oldstr, const std::string& newstr) +{ + std::string temp = str; + size_t old_idx = str.find(oldstr); + if (old_idx != std::string::npos) { + temp = str.replace(old_idx, 1, newstr); + } + return temp; +} +}; diff --git a/src/input_output/string_utilities.h b/src/input_output/string_utilities.h index 005dd2b496..8583ef6355 100644 --- a/src/input_output/string_utilities.h +++ b/src/input_output/string_utilities.h @@ -39,121 +39,24 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include -#include -#include #include -#include - -#include "JSBSim_API.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -JSBSIM_API bool is_number(const std::string& str); +namespace JSBSim { JSBSIM_API double atof_locale_c(const std::string& input); - -#if !defined(BASE) - extern std::string& trim_left(std::string& str); - extern std::string& trim_right(std::string& str); - extern std::string& trim(std::string& str); - extern std::string& trim_all_space(std::string& str); - extern std::string& to_upper(std::string& str); - extern std::string& to_lower(std::string& str); - std::vector split(std::string str, char d); - - extern std::string replace(std::string str, const std::string& old, const std::string& newstr); -#else - #include - - std::string& trim_left(std::string& str) - { - while (!str.empty() && isspace((unsigned char)str[0])) { - str = str.erase(0,1); - } - return str; - } - - std::string& trim_right(std::string& str) - { - while (!str.empty() && isspace((unsigned char)str[str.size()-1])) { - str = str.erase(str.size()-1,1); - } - return str; - } - - std::string& trim(std::string& str) - { - if (str.empty()) return str; - std::string temp_str = trim_right(str); - return str = trim_left(temp_str); - } - - std::string& trim_all_space(std::string& str) - { - for (size_t i=0; i split(std::string str, char d) - { - std::vector str_array; - size_t index=0; - std::string temp = ""; - - trim(str); - index = str.find(d); - while (index != std::string::npos) { - temp = str.substr(0,index); - trim(temp); - if (!temp.empty()) str_array.push_back(temp); - str = str.erase(0,index+1); - index = str.find(d); - } - if (!str.empty()) { - temp = trim(str); - if (!temp.empty()) str_array.push_back(temp); - } - - return str_array; - } - - std::string replace(std::string str, const std::string& oldstr, const std::string& newstr) - { - std::string temp = str; - size_t old_idx = str.find(oldstr); - if (old_idx != std::string::npos) { - temp = str.replace(old_idx, 1, newstr); - } - return temp; - } - -#endif +JSBSIM_API std::string& trim_left(std::string& str); +JSBSIM_API std::string& trim_right(std::string& str); +JSBSIM_API std::string& trim(std::string& str); +JSBSIM_API std::string& trim_all_space(std::string& str); +JSBSIM_API std::string& to_upper(std::string& str); +JSBSIM_API std::string& to_lower(std::string& str); +JSBSIM_API bool is_number(const std::string& str); +JSBSIM_API std::vector split(std::string str, char d); +JSBSIM_API std::string replace(std::string str, const std::string& old, const std::string& newstr); +}; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/simgear/xml/easyxml.cxx b/src/simgear/xml/easyxml.cxx index 1b5725ffd4..3700bf24fd 100644 --- a/src/simgear/xml/easyxml.cxx +++ b/src/simgear/xml/easyxml.cxx @@ -23,6 +23,7 @@ INCLUDES #include #include +#include #include "FGJSBBase.h" diff --git a/tests/unit_tests/StringUtilitiesTest.h b/tests/unit_tests/StringUtilitiesTest.h index c82817f8ac..287cd167b4 100644 --- a/tests/unit_tests/StringUtilitiesTest.h +++ b/tests/unit_tests/StringUtilitiesTest.h @@ -1,9 +1,9 @@ #include #include -#define BASE -#include -#undef BASE #include "FGJSBBase.h" +#include + +using namespace JSBSim; class StringUtilitiesTest : public CxxTest::TestSuite { @@ -95,8 +95,8 @@ class StringUtilitiesTest : public CxxTest::TestSuite TS_ASSERT_EQUALS(atof_locale_c("1E-999"), 0.0); TS_ASSERT_EQUALS(atof_locale_c("-1E-999"), 0.0); TS_ASSERT_EQUALS(atof_locale_c("0.0"), 0.0); - TS_ASSERT_THROWS(atof_locale_c("1E+999"), JSBSim::BaseException&); - TS_ASSERT_THROWS(atof_locale_c("-1E+999"), JSBSim::BaseException&); + TS_ASSERT_THROWS(atof_locale_c("1E+999"), BaseException&); + TS_ASSERT_THROWS(atof_locale_c("-1E+999"), BaseException&); } private: