Commit 02a1a9fd authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

utils: Move url related function to its own file

parent 63617f2b
......@@ -74,6 +74,7 @@ libmedialibrary_la_SOURCES = \
src/parser/ParserService.cpp \
src/utils/Filename.cpp \
src/utils/ModificationsNotifier.cpp \
src/utils/Url.cpp \
src/utils/VLCInstance.cpp \
$(NULL)
......@@ -155,6 +156,7 @@ noinst_HEADERS = \
src/utils/Filename.h \
src/utils/ModificationsNotifier.h \
src/utils/SWMRLock.h \
src/utils/Url.h \
src/utils/VLCInstance.h \
src/VideoTrack.h \
src/compat/Thread.h \
......
......@@ -25,9 +25,9 @@
#endif
#include "utils/Filename.h"
#include "utils/Url.h"
#include <stdexcept>
#include <cstdlib>
#ifdef _WIN32
#define DIR_SEPARATOR '\\'
......@@ -167,27 +167,7 @@ std::string toLocalPath( const std::string& mrl )
{
if ( mrl.compare( 0, 7, "file://" ) != 0 )
throw std::runtime_error( mrl + " is not representing a local path" );
std::string res;
res.reserve( mrl.size() - 7 );
auto it = mrl.cbegin() + 7;
auto ite = mrl.cend();
for ( ; it != ite; ++it )
{
if ( *it == '%' )
{
++it;
char hex[3];
if ( ( hex[0] = *it) == 0 || ( hex[1] = *(it + 1) ) == 0 )
throw std::runtime_error( mrl + ": Incomplete character sequence" );
hex[2] = 0;
auto val = strtoul( hex, nullptr, 16 );
res.push_back( static_cast<std::string::value_type>( val ) );
++it;
}
else
res.push_back( *it );
}
return res;
return utils::url::decode( mrl.substr( 7 ) );
}
std::string scheme( const std::string& mrl )
......
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2017 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*****************************************************************************/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "Url.h"
#include <stdexcept>
#include <cstdlib>
namespace medialibrary
{
namespace utils
{
namespace url
{
std::string decode( const std::string& str )
{
std::string res;
res.reserve( str.size() );
auto it = str.cbegin();
auto ite = str.cend();
for ( ; it != ite; ++it )
{
if ( *it == '%' )
{
++it;
char hex[3];
if ( ( hex[0] = *it) == 0 || ( hex[1] = *(it + 1) ) == 0 )
throw std::runtime_error( str + ": Incomplete character sequence" );
hex[2] = 0;
auto val = strtoul( hex, nullptr, 16 );
res.push_back( static_cast<std::string::value_type>( val ) );
++it;
}
else
res.push_back( *it );
}
return res;
}
}
}
}
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2017 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*****************************************************************************/
#include <string>
namespace medialibrary
{
namespace utils
{
namespace url
{
std::string decode( const std::string& str );
}
}
}
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