diff options
Diffstat (limited to 'src/CommonAPI/Utils.cpp')
-rw-r--r-- | src/CommonAPI/Utils.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/CommonAPI/Utils.cpp b/src/CommonAPI/Utils.cpp new file mode 100644 index 0000000..2540a86 --- /dev/null +++ b/src/CommonAPI/Utils.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <algorithm> +#include <sstream> +#include <functional> + +#include <CommonAPI/Utils.hpp> + +namespace CommonAPI { + +std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems) { + std::istringstream ss(s); + std::string item; + while (std::getline(ss, item, delim)) { + elems.push_back(item); + } + return elems; +} + +std::vector<std::string> split(const std::string& s, char delim) { + std::vector<std::string> elems; + return split(s, delim, elems); +} + +void trim(std::string& toTrim) { + toTrim.erase( + toTrim.begin(), + std::find_if( + toTrim.begin(), + toTrim.end(), + std::not1(std::ptr_fun(isspace)) + ) + ); + + toTrim.erase( + std::find_if( + toTrim.rbegin(), + toTrim.rend(), + std::not1(std::ptr_fun(isspace))).base(), + toTrim.end() + ); +} + +}//namespace CommonAPI |