Browse Source

Add getProtocolFromURL to StringUtils

pull/2/head
Nubben 5 years ago
parent
commit
fbaf5878dd
  1. 15
      src/StringUtils.cpp
  2. 3
      src/StringUtils.h

15
src/StringUtils.cpp

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
* @param fileName a filename string
* @return '' or a string with the found extension
*/
std::string getFilenameExtension(std::string const& fileName) {
const std::string getFilenameExtension(std::string const& fileName) {
auto dotPos = fileName.find_last_of('.');
if (dotPos != std::string::npos && dotPos + 1 != std::string::npos) {
//std::cout << "StringUtils::getFilenameExtension - " << fileName.substr(dotPos + 1) << std::endl;
@ -56,6 +56,19 @@ const std::string getHostFromURL(const std::string &url) { @@ -56,6 +56,19 @@ const std::string getHostFromURL(const std::string &url) {
return "";
}
/**
* get protocol from a url
* @param url url string
* @return '' or a string with the found protocol
*/
const std::string getProtocolFromURL(const std::string &url) {
auto colonDoubleSlash = url.find("://");
if (colonDoubleSlash != std::string::npos) {
return url.substr(0, colonDoubleSlash);
}
return "";
}
/**
* convert string to lowercase
* @param str string

3
src/StringUtils.h

@ -3,9 +3,10 @@ @@ -3,9 +3,10 @@
#include <string>
std::string getFilenameExtension(std::string const& fileName);
const std::string getFilenameExtension(std::string const& fileName);
const std::string getDocumentFromURL(const std::string &url);
const std::string getHostFromURL(const std::string &url);
const std::string getProtocolFromURL(const std::string &url);
const std::string toLowercase(const std::string &str);
#endif

Loading…
Cancel
Save