- improve string helper - add startsWith() method + fix indentation

This commit is contained in:
Dmytro Bogovych 2018-09-29 22:30:15 +03:00
parent 96c2ed3d94
commit 2564e690e8
2 changed files with 300 additions and 293 deletions

View File

@ -17,88 +17,88 @@
std::string StringHelper::extractFilename(const std::string& path) std::string StringHelper::extractFilename(const std::string& path)
{ {
// Look for separator from end of string // Look for separator from end of string
for (int i = path.size() - 1; i >= 0; i--) for (int i = path.size() - 1; i >= 0; i--)
{ {
if (path[i] == '/' || path[i] == '\\') if (path[i] == '/' || path[i] == '\\')
return path.substr(i+1); return path.substr(i+1);
} }
return ""; return "";
} }
std::string StringHelper::makeUtf8(const std::tstring &arg) std::string StringHelper::makeUtf8(const std::tstring &arg)
{ {
#if defined(TARGET_WIN) #if defined(TARGET_WIN)
size_t required = WideCharToMultiByte(CP_UTF8, 0, arg.c_str(), -1, NULL, 0, NULL, NULL); size_t required = WideCharToMultiByte(CP_UTF8, 0, arg.c_str(), -1, NULL, 0, NULL, NULL);
char *result = (char*)_alloca(required + 1); char *result = (char*)_alloca(required + 1);
WideCharToMultiByte(CP_UTF8, 0, arg.c_str(), -1, result, required+1, NULL, NULL); WideCharToMultiByte(CP_UTF8, 0, arg.c_str(), -1, result, required+1, NULL, NULL);
return result; return result;
#else #else
return arg; return arg;
#endif #endif
} }
std::tstring StringHelper::makeTstring(const std::string& arg) std::tstring StringHelper::makeTstring(const std::string& arg)
{ {
#if defined(TARGET_WIN) #if defined(TARGET_WIN)
size_t count = MultiByteToWideChar(CP_UTF8, 0, arg.c_str(), -1, NULL, 0); size_t count = MultiByteToWideChar(CP_UTF8, 0, arg.c_str(), -1, NULL, 0);
wchar_t* result = (wchar_t*)_alloca(count * 2); wchar_t* result = (wchar_t*)_alloca(count * 2);
MultiByteToWideChar(CP_UTF8, 0, arg.c_str(), -1, result, count); MultiByteToWideChar(CP_UTF8, 0, arg.c_str(), -1, result, count);
return result; return result;
#else #else
return arg; return arg;
#endif #endif
} }
int StringHelper::toInt(const char *s, int defaultValue, bool* isOk) int StringHelper::toInt(const char *s, int defaultValue, bool* isOk)
{ {
int result; int result;
if (sscanf(s, "%d", &result) != 1) if (sscanf(s, "%d", &result) != 1)
{ {
if (isOk) if (isOk)
*isOk = false; *isOk = false;
result = defaultValue; result = defaultValue;
} }
else else
if (isOk) if (isOk)
*isOk = true; *isOk = true;
return result; return result;
} }
uint64_t StringHelper::toUint64(const char* s, uint64_t def, bool *isOk) uint64_t StringHelper::toUint64(const char* s, uint64_t def, bool *isOk)
{ {
uint64_t result = def; uint64_t result = def;
#if defined(TARGET_WIN) #if defined(TARGET_WIN)
if (sscanf(s, "%I64d", &result) != 1) if (sscanf(s, "%I64d", &result) != 1)
#else #else
if (sscanf(s, "%llu", &result) != 1) if (sscanf(s, "%llu", &result) != 1)
#endif #endif
{ {
if (isOk) if (isOk)
*isOk = false; *isOk = false;
result = def; result = def;
} }
else else
if (isOk) if (isOk)
*isOk = true; *isOk = true;
return result; return result;
} }
std::string StringHelper::toHex(unsigned int value) std::string StringHelper::toHex(unsigned int value)
{ {
char buffer[32]; char buffer[32];
sprintf(buffer, "%x", value); sprintf(buffer, "%x", value);
return buffer; return buffer;
} }
std::string StringHelper::toHex(const void *ptr) std::string StringHelper::toHex(const void *ptr)
{ {
std::ostringstream oss; std::ostringstream oss;
oss << std::hex << ptr; oss << std::hex << ptr;
return oss.str(); return oss.str();
} }
//must be lowercase for MD5 //must be lowercase for MD5
@ -106,334 +106,340 @@ static const char hexmap[] = "0123456789abcdef";
std::string StringHelper::toHex(const uint8_t* input, size_t inputLength) std::string StringHelper::toHex(const uint8_t* input, size_t inputLength)
{ {
std::string result; result.resize(inputLength * 2); std::string result; result.resize(inputLength * 2);
const char* p = (const char*)input; const char* p = (const char*)input;
char* r = &result[0]; char* r = &result[0];
for (size_t i=0; i < inputLength; ++i) for (size_t i=0; i < inputLength; ++i)
{ {
unsigned char temp = *p++; unsigned char temp = *p++;
int hi = (temp & 0xf0)>>4; int hi = (temp & 0xf0)>>4;
int low = (temp & 0xf); int low = (temp & 0xf);
*r++ = hexmap[hi]; *r++ = hexmap[hi];
*r++ = hexmap[low]; *r++ = hexmap[low];
} }
*r = 0; *r = 0;
return result; return result;
} }
std::string StringHelper::prefixLines(const std::string &source, const std::string &prefix) std::string StringHelper::prefixLines(const std::string &source, const std::string &prefix)
{ {
// Read source line by line // Read source line by line
std::istringstream iss(source); std::istringstream iss(source);
std::ostringstream oss; std::ostringstream oss;
std::string line; std::string line;
while (std::getline(iss,line)) while (std::getline(iss,line))
{ {
oss << prefix << line << std::endl; oss << prefix << line << std::endl;
} }
return oss.str(); return oss.str();
} }
std::string StringHelper::doubleToString(double value, int precision) std::string StringHelper::doubleToString(double value, int precision)
{ {
std::stringstream ss; std::stringstream ss;
ss << std::fixed << std::setprecision(precision) << value; ss << std::fixed << std::setprecision(precision) << value;
return ss.str(); return ss.str();
} }
const char* StringHelper::findSubstring(const char* buffer, const char* substring, size_t bufferLength) const char* StringHelper::findSubstring(const char* buffer, const char* substring, size_t bufferLength)
{ {
#if defined(TARGET_WIN) #if defined(TARGET_WIN)
return (const char*)strstr(buffer, substring); return (const char*)strstr(buffer, substring);
#else #else
return (const char*)memmem(buffer, bufferLength, substring, strlen(substring)); return (const char*)memmem(buffer, bufferLength, substring, strlen(substring));
#endif #endif
} }
void StringHelper::split(const std::string& src, std::vector<std::string>& dst, const std::string& delims) void StringHelper::split(const std::string& src, std::vector<std::string>& dst, const std::string& delims)
{ {
dst.clear(); dst.clear();
std::string::size_type p = 0; std::string::size_type p = 0;
while (p < src.size()) while (p < src.size())
{
std::string::size_type f = src.find_first_of(delims, p);
if (f == std::string::npos)
{ {
std::string t = src.substr(p); std::string::size_type f = src.find_first_of(delims, p);
if (!t.empty()) if (f == std::string::npos)
dst.push_back(t); {
p = src.size(); std::string t = src.substr(p);
if (!t.empty())
dst.push_back(t);
p = src.size();
}
else
{
std::string t = src.substr(p, f-p);
if (!t.empty())
dst.push_back(t);
p = f + 1;
}
} }
else
{
std::string t = src.substr(p, f-p);
if (!t.empty())
dst.push_back(t);
p = f + 1;
}
}
} }
std::pair<std::string, int> StringHelper::parseHost(const std::string& host, int defaultPort) std::pair<std::string, int> StringHelper::parseHost(const std::string& host, int defaultPort)
{ {
std::pair<std::string, int> result; std::pair<std::string, int> result;
std::size_t p = host.find(':'); std::size_t p = host.find(':');
if (p != std::string::npos) if (p != std::string::npos)
{ {
result.first = host.substr(0, p); result.first = host.substr(0, p);
result.second = StringHelper::toInt(host.c_str() + p + 1, defaultPort); result.second = StringHelper::toInt(host.c_str() + p + 1, defaultPort);
} }
else else
{ {
result.first = host; result.first = host;
result.second = defaultPort; result.second = defaultPort;
} }
return result; return result;
} }
std::pair<std::string, std::string> StringHelper::parseAssignment(const std::string& s, bool trimQuotes) std::pair<std::string, std::string> StringHelper::parseAssignment(const std::string& s, bool trimQuotes)
{ {
std::pair<std::string, std::string> result; std::pair<std::string, std::string> result;
std::string::size_type p = s.find('='); std::string::size_type p = s.find('=');
if (p != std::string::npos) if (p != std::string::npos)
{
result.first = StringHelper::trim(s.substr(0, p));
result.second = StringHelper::trim(s.substr(p+1));
if (trimQuotes && result.second.size() >= 2)
{ {
if (result.second[0] == '"' && result.second[result.second.size()-1] == '"' || result.first = StringHelper::trim(s.substr(0, p));
result.second[0] == '\'' && result.second[result.second.size()-1] == '\'') result.second = StringHelper::trim(s.substr(p+1));
result.second = result.second.substr(1, result.second.size() - 2); if (trimQuotes && result.second.size() >= 2)
{
if (result.second[0] == '"' && result.second[result.second.size()-1] == '"' ||
result.second[0] == '\'' && result.second[result.second.size()-1] == '\'')
result.second = result.second.substr(1, result.second.size() - 2);
}
} }
} else
else result.first = StringHelper::trim(s);
result.first = StringHelper::trim(s);
return result; return result;
} }
std::string StringHelper::intToString(int value) std::string StringHelper::intToString(int value)
{ {
char buffer[32]; char buffer[32];
sprintf(buffer, "%d", value); sprintf(buffer, "%d", value);
return buffer; return buffer;
} }
float StringHelper::toFloat(const std::string &s, float v, bool* isOk) float StringHelper::toFloat(const std::string &s, float v, bool* isOk)
{ {
float result = 0.0; float result = 0.0;
int code = sscanf(s.c_str(), "%f", &result); int code = sscanf(s.c_str(), "%f", &result);
if (code == 1) if (code == 1)
{ {
if (isOk) if (isOk)
*isOk = true; *isOk = true;
} }
else else
{ {
result = v; result = v;
if (isOk) if (isOk)
*isOk = false; *isOk = false;
} }
return result; return result;
} }
std::string StringHelper::trim(const std::string &s) std::string StringHelper::trim(const std::string &s)
{ {
auto wsfront = std::find_if_not(s.begin(), s.end(), [](int c) { return std::isspace(c); }); auto wsfront = std::find_if_not(s.begin(), s.end(), [](int c) { return std::isspace(c); });
auto wsback = std::find_if_not(s.rbegin(), s.rend(), [](int c) { return std::isspace(c); }).base(); auto wsback = std::find_if_not(s.rbegin(), s.rend(), [](int c) { return std::isspace(c); }).base();
return (wsback <= wsfront ? std::string() : std::string(wsfront,wsback)); return (wsback <= wsfront ? std::string() : std::string(wsfront,wsback));
} }
std::string StringHelper::timeToString(time_t t) std::string StringHelper::timeToString(time_t t)
{ {
char buffer[96]; char buffer[96];
struct tm lt; struct tm lt;
#if defined(TARGET_LINUX) || defined(TARGET_OSX) || defined(TARGET_ANDROID) #if defined(TARGET_LINUX) || defined(TARGET_OSX) || defined(TARGET_ANDROID)
localtime_r(&t, &lt); localtime_r(&t, &lt);
#else #else
lt = *localtime(&t); lt = *localtime(&t);
#endif #endif
strftime(buffer, sizeof(buffer)-1, "%Y-%m-%d %H:%M:%S", &lt); strftime(buffer, sizeof(buffer)-1, "%Y-%m-%d %H:%M:%S", &lt);
return buffer; return buffer;
} }
std::string StringHelper::millisecondsToString(uint64_t t) std::string StringHelper::millisecondsToString(uint64_t t)
{ {
return timeToString(t/1000); return timeToString(t/1000);
} }
int StringHelper::fromHex2Int(const std::string &s) int StringHelper::fromHex2Int(const std::string &s)
{ {
int result = 0; int result = 0;
sscanf(s.c_str(), "%x", &result); sscanf(s.c_str(), "%x", &result);
return result; return result;
} }
static int hex2code(char s) static int hex2code(char s)
{ {
if (s >= '0' && s <= '9') if (s >= '0' && s <= '9')
return s - '0'; return s - '0';
if (s >= 'a' && s <= 'f') if (s >= 'a' && s <= 'f')
return s - 'a' + 10; return s - 'a' + 10;
if (s >= 'A' && s <= 'F') if (s >= 'A' && s <= 'F')
return s - 'A' + 10; return s - 'A' + 10;
return 0; return 0;
} }
static int hex2code(const char* s) static int hex2code(const char* s)
{ {
return (hex2code(s[0]) << 4) + hex2code(s[1]); return (hex2code(s[0]) << 4) + hex2code(s[1]);
} }
std::string StringHelper::fromHex2String(const std::string& s) std::string StringHelper::fromHex2String(const std::string& s)
{ {
std::string result; result.resize(s.size() / 2); std::string result; result.resize(s.size() / 2);
const char* t = s.c_str(); const char* t = s.c_str();
for (size_t i = 0; i < result.size(); i++) for (size_t i = 0; i < result.size(); i++)
result[i] = hex2code(t[i*2]); result[i] = hex2code(t[i*2]);
return result; return result;
} }
std::string StringHelper::replace(const std::string& s, char f, char r) std::string StringHelper::replace(const std::string& s, char f, char r)
{ {
std::string result(s); std::string result(s);
for (std::string::size_type i = 0; i < result.size(); i++) for (std::string::size_type i = 0; i < result.size(); i++)
if (result[i] == 'f') if (result[i] == 'f')
result[i] = r; result[i] = r;
return result; return result;
} }
std::string StringHelper::replace(const std::string& s, const std::string& tmpl, const std::string& n) std::string StringHelper::replace(const std::string& s, const std::string& tmpl, const std::string& n)
{ {
std::string result(s); std::string result(s);
std::string::size_type p; std::string::size_type p;
while ( (p = result.find(tmpl)) != std::string::npos) while ( (p = result.find(tmpl)) != std::string::npos)
{ {
result.replace(p, tmpl.size(), n); result.replace(p, tmpl.size(), n);
} }
return result; return result;
} }
std::string StringHelper::decodeUri(const std::string& s) std::string StringHelper::decodeUri(const std::string& s)
{ {
std::string ret; std::string ret;
ret.reserve(s.size()); ret.reserve(s.size());
char ch; char ch;
int i, ii; int i, ii;
for (i=0; i<(int)s.length(); i++) for (i=0; i<(int)s.length(); i++)
{
if (s[i] == 37)
{ {
sscanf(s.substr(i+1,2).c_str(), "%x", &ii); if (s[i] == 37)
ch = static_cast<char>(ii); {
ret += ch; sscanf(s.substr(i+1,2).c_str(), "%x", &ii);
i += 2; ch = static_cast<char>(ii);
ret += ch;
i += 2;
}
else
ret += s[i];
} }
else return ret;
ret += s[i]; }
}
return ret; bool StringHelper::startsWith(const std::string& s, const std::string& prefix)
{
std::string::size_type p = s.find(prefix);
return p == 0;
} }
#define XML_HEADER "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" #define XML_HEADER "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
// --------------------- XcapHelper ----------------- // --------------------- XcapHelper -----------------
std::string XcapHelper::buildBuddyList(std::string listName, std::vector<std::string> buddies) std::string XcapHelper::buildBuddyList(std::string listName, std::vector<std::string> buddies)
{ {
std::ostringstream result; std::ostringstream result;
result << XML_HEADER << result << XML_HEADER <<
"<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" << "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" <<
"<list name=\"" << listName.c_str() << "\">"; "<list name=\"" << listName.c_str() << "\">";
// to test CT only! // to test CT only!
//result << "<entry uri=\"" << "sip:dbogovych1@10.11.1.25" << "\"/>"; //result << "<entry uri=\"" << "sip:dbogovych1@10.11.1.25" << "\"/>";
//result << "<entry uri=\"" << "sip:dbogovych2@10.11.1.25" << "\"/>"; //result << "<entry uri=\"" << "sip:dbogovych2@10.11.1.25" << "\"/>";
for (unsigned i = 0; i<buddies.size(); i++) for (unsigned i = 0; i<buddies.size(); i++)
{ {
result << "<entry uri=\"" << normalizeSipUri(buddies[i]).c_str() << "\"/>"; result << "<entry uri=\"" << normalizeSipUri(buddies[i]).c_str() << "\"/>";
} }
result << "</list></resource-lists>"; result << "</list></resource-lists>";
return result.str(); return result.str();
} }
std::string XcapHelper::buildRules(std::vector<std::string> buddies) std::string XcapHelper::buildRules(std::vector<std::string> buddies)
{ {
std::ostringstream result; std::ostringstream result;
result << XML_HEADER << result << XML_HEADER <<
"<ruleset xmlns=\"urn:ietf:params:xml:ns:common-policy\">" << "<ruleset xmlns=\"urn:ietf:params:xml:ns:common-policy\">" <<
"<rule id=\"presence_allow\">" << "<rule id=\"presence_allow\">" <<
"<conditions>"; "<conditions>";
for (unsigned i = 0; i<buddies.size(); i++) for (unsigned i = 0; i<buddies.size(); i++)
{ {
result << "<identity><one id=\"" << result << "<identity><one id=\"" <<
normalizeSipUri(buddies[i]).c_str() << "\"/></identity>"; normalizeSipUri(buddies[i]).c_str() << "\"/></identity>";
} }
result << "</conditions>" << result << "</conditions>" <<
"<actions>" << "<actions>" <<
"<sub-handling xmlns=\"urn:ietf:params:xml:ns:pres-rules\">" << "<sub-handling xmlns=\"urn:ietf:params:xml:ns:pres-rules\">" <<
"allow" << "allow" <<
"</sub-handling>" << "</sub-handling>" <<
"</actions>" << "</actions>" <<
"<transformations>" << "<transformations>" <<
"<provide-devices xmlns=\"urn:ietf:params:xml:ns:pres-rules\">" << "<provide-devices xmlns=\"urn:ietf:params:xml:ns:pres-rules\">" <<
"<all-devices/>" << "<all-devices/>" <<
"</provide-devices>" << "</provide-devices>" <<
"<provide-persons xmlns=\"urn:ietf:params:xml:ns:pres-rules\">" << "<provide-persons xmlns=\"urn:ietf:params:xml:ns:pres-rules\">" <<
"<all-persons/>" << "<all-persons/>" <<
"</provide-persons>" << "</provide-persons>" <<
"<provide-services xmlns=\"urn:ietf:params:xml:ns:pres-rules\">" << "<provide-services xmlns=\"urn:ietf:params:xml:ns:pres-rules\">" <<
"<all-services/>" << "<all-services/>" <<
"</provide-services>" << "</provide-services>" <<
"</transformations>" << "</transformations>" <<
"</rule>" << "</rule>" <<
"</ruleset>"; "</ruleset>";
return result.str(); return result.str();
} }
std::string XcapHelper::buildServices(std::string serviceUri, std::string listRef) std::string XcapHelper::buildServices(std::string serviceUri, std::string listRef)
{ {
std::ostringstream result; std::ostringstream result;
result << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl << result << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl <<
"<rls-services xmlns=\"urn:ietf:params:xml:ns:rls-services\"" << std::endl << "<rls-services xmlns=\"urn:ietf:params:xml:ns:rls-services\"" << std::endl <<
"xmlns:rl=\"urn:ietf:params:xml:ns:resource-lists\"" << std::endl << "xmlns:rl=\"urn:ietf:params:xml:ns:resource-lists\"" << std::endl <<
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" << std::endl << "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" << std::endl <<
"<service uri=\"" << normalizeSipUri(serviceUri).c_str() << "\">" << std::endl << "<service uri=\"" << normalizeSipUri(serviceUri).c_str() << "\">" << std::endl <<
"<resource-list>" << listRef.c_str() << "</resource-list>" << std::endl << "<resource-list>" << listRef.c_str() << "</resource-list>" << std::endl <<
"<packages>" << std::endl << "<packages>" << std::endl <<
"<package>presence</package>" << std::endl << "<package>presence</package>" << std::endl <<
"</packages>" << std::endl << "</packages>" << std::endl <<
"</service>" << std::endl << "</service>" << std::endl <<
"</rls-services>"; "</rls-services>";
return result.str(); return result.str();
} }
std::string XcapHelper::normalizeSipUri(std::string uri) std::string XcapHelper::normalizeSipUri(std::string uri)
{ {
if (uri.length())
{
if (uri[0] == '<')
uri.erase(0,1);
if (uri.length()) if (uri.length())
{ {
if (uri[uri.length()-1] == '>') if (uri[0] == '<')
uri.erase(uri.length()-1, 1); uri.erase(0,1);
if (uri.length())
{
if (uri[uri.length()-1] == '>')
uri.erase(uri.length()-1, 1);
}
} }
} return uri;
return uri;
} }

View File

@ -19,54 +19,55 @@
class StringHelper class StringHelper
{ {
public: public:
static std::string extractFilename(const std::string& path); static std::string extractFilename(const std::string& path);
static std::string makeUtf8(const std::tstring& arg); static std::string makeUtf8(const std::tstring& arg);
static std::tstring makeTstring(const std::string& arg); static std::tstring makeTstring(const std::string& arg);
static int toInt(const char* s, int defaultValue, bool* isOk = nullptr); static int toInt(const char* s, int defaultValue, bool* isOk = nullptr);
static uint64_t toUint64(const char* s, uint64_t def, bool *isOk = nullptr); static uint64_t toUint64(const char* s, uint64_t def, bool *isOk = nullptr);
static std::string toHex(unsigned int value); static std::string toHex(unsigned int value);
static std::string toHex(const void* ptr); static std::string toHex(const void* ptr);
static std::string toHex(const uint8_t* input, size_t inputLength); static std::string toHex(const uint8_t* input, size_t inputLength);
static std::string intToString(int value); static std::string intToString(int value);
static std::string prefixLines(const std::string& source, const std::string& prefix); static std::string prefixLines(const std::string& source, const std::string& prefix);
static std::string doubleToString(double value, int precision); static std::string doubleToString(double value, int precision);
static const char* findSubstring(const char* buffer, const char* substring, size_t bufferLength); static const char* findSubstring(const char* buffer, const char* substring, size_t bufferLength);
static void split(const std::string& src, std::vector<std::string>& dst, const std::string& delims); static void split(const std::string& src, std::vector<std::string>& dst, const std::string& delims);
template <typename T> template <typename T>
static std::string join(const std::vector<T>& v, const std::string& delimiter) static std::string join(const std::vector<T>& v, const std::string& delimiter)
{
std::ostringstream s;
for (const auto& i : v)
{ {
if (&i != &v[0]) std::ostringstream s;
s << delimiter; for (const auto& i : v)
s << i; {
if (&i != &v[0])
s << delimiter;
s << i;
}
return s.str();
} }
return s.str();
}
static std::pair<std::string, int> parseHost(const std::string& host, int defaultPort); static std::pair<std::string, int> parseHost(const std::string& host, int defaultPort);
static std::pair<std::string, std::string> parseAssignment(const std::string& s, bool trimQuotes = true); static std::pair<std::string, std::string> parseAssignment(const std::string& s, bool trimQuotes = true);
static float toFloat(const std::string& s, float defaultValue = 0.0, bool* isOk = nullptr); static float toFloat(const std::string& s, float defaultValue = 0.0, bool* isOk = nullptr);
static std::string trim(const std::string& s); static std::string trim(const std::string& s);
static std::string timeToString(time_t t); static std::string timeToString(time_t t);
static std::string millisecondsToString(uint64_t t); static std::string millisecondsToString(uint64_t t);
static int fromHex2Int(const std::string& s); static int fromHex2Int(const std::string& s);
static std::string fromHex2String(const std::string& s); static std::string fromHex2String(const std::string& s);
static std::string replace(const std::string& s, char f, char r); static std::string replace(const std::string& s, char f, char r);
static std::string replace(const std::string& s, const std::string& tmpl, const std::string& n); static std::string replace(const std::string& s, const std::string& tmpl, const std::string& n);
static std::string decodeUri(const std::string& s); static std::string decodeUri(const std::string& s);
static bool startsWith(const std::string& s, const std::string& prefix);
}; };
class XcapHelper class XcapHelper
{ {
public: public:
static std::string buildBuddyList(std::string listName, std::vector<std::string> buddies); static std::string buildBuddyList(std::string listName, std::vector<std::string> buddies);
static std::string buildRules(std::vector<std::string> buddies); static std::string buildRules(std::vector<std::string> buddies);
static std::string buildServices(std::string serviceUri, std::string listRef); static std::string buildServices(std::string serviceUri, std::string listRef);
static std::string normalizeSipUri(std::string uri); static std::string normalizeSipUri(std::string uri);
}; };