Commit 07d7a1ad authored by Tristan Matthews's avatar Tristan Matthews

string_utils: move and rewrite split_string

Refs #61369

Change-Id: I1f060bd0cdf93d59204407f87a34b6453d0f3674
parent dfc95cce
......@@ -127,6 +127,7 @@ libsflphone_la_SOURCES = conference.cpp \
registration_states.h \
map_utils.h \
string_utils.h \
string_utils.cpp \
rw_mutex.h \
sflphone.h \
sflphone_api.cpp
......@@ -47,6 +47,7 @@
#include "client/configurationmanager.h"
#include "account_schema.h"
#include "string_utils.h"
#include "config/yamlparser.h"
#include <yaml-cpp/yaml.h>
......@@ -203,7 +204,7 @@ void Account::unserialize(const YAML::Node &node)
parseValue(node, AUDIO_CODECS_KEY, audioCodecStr_);
// Update codec list which one is used for SDP offer
setActiveAudioCodecs(split_string(audioCodecStr_));
setActiveAudioCodecs(sfl::split_string(audioCodecStr_, '/'));
parseValue(node, DISPLAY_NAME_KEY, displayName_);
parseValue(node, HOSTNAME_KEY, hostname_);
......@@ -349,23 +350,6 @@ join_string(const std::vector<std::string> &v)
return os.str();
}
std::vector<std::string>
Account::split_string(std::string s)
{
std::vector<std::string> list;
std::string temp;
while (s.find("/", 0) != std::string::npos) {
size_t pos = s.find("/", 0);
temp = s.substr(0, pos);
s.erase(0, pos + 1);
list.push_back(temp);
}
return list;
}
void Account::setActiveAudioCodecs(const vector<string> &list)
{
// first clear the previously stored codecs
......
......@@ -236,8 +236,6 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
void detachCall(const std::string& id);
static std::vector<std::string> split_string(std::string s);
static const char * const VIDEO_CODEC_ENABLED;
static const char * const VIDEO_CODEC_NAME;
static const char * const VIDEO_CODEC_PARAMETERS;
......
......@@ -46,6 +46,7 @@
#include "fileutils.h"
#include "map_utils.h"
#include "account.h"
#include "string_utils.h"
#if HAVE_DHT
#include "ringdht/ringaccount.h"
#endif
......@@ -2499,7 +2500,7 @@ ManagerImpl::getNewCallID()
std::vector<std::string>
ManagerImpl::loadAccountOrder() const
{
return Account::split_string(preferences.getAccountOrder());
return split_string(preferences.getAccountOrder(), '/');
}
void
......
/*
* Copyright (C) 2014 Savoir-Faire Linux Inc.
*
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include "string_utils.h"
#include <sstream>
namespace sfl {
std::vector<std::string>
split_string(const std::string &s, char delim)
{
std::vector<std::string> result;
std::string token;
std::istringstream ss(s);
while (std::getline(ss, token, delim))
if (not token.empty())
result.emplace_back(token);
return result;
}
}
......@@ -32,12 +32,16 @@
#ifndef STRING_UTILS_H
#define STRING_UTILS_H
namespace sfl {
#include <string>
#include <vector>
#ifdef __ANDROID__
#include <string>
#include <sstream>
#endif
namespace sfl {
#ifdef __ANDROID__
template <typename T>
std::string to_string(T &&value)
......@@ -58,6 +62,9 @@ std::string to_string(T &&value)
#endif
std::vector<std::string>
split_string(const std::string& s, char sep);
}
#endif // H_UTF8_UTILS
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment