Skip to content

Commit

Permalink
use some auto
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jul 15, 2022
1 parent 8c3d852 commit 90c3e90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
28 changes: 13 additions & 15 deletions src/futils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,17 @@ void Uri::Decode(Uri& uri) {
Uri Uri::Parse(const std::string& uri) {
Uri result;

using iterator_t = std::string::const_iterator;

if (!uri.length())
return result;

iterator_t uriEnd = uri.end();
auto uriEnd = uri.end();

// get query start
iterator_t queryStart = std::find(uri.begin(), uriEnd, '?');
auto queryStart = std::find(uri.begin(), uriEnd, '?');

// protocol
iterator_t protocolStart = uri.begin();
iterator_t protocolEnd = std::find(protocolStart, uriEnd, ':'); //"://");
auto protocolStart = uri.begin();
auto protocolEnd = std::find(protocolStart, uriEnd, ':'); //"://");

if (protocolEnd != uriEnd) {
std::string prot = &*(protocolEnd);
Expand All @@ -284,11 +282,11 @@ Uri Uri::Parse(const std::string& uri) {
protocolEnd = uri.begin(); // no protocol

// username & password
iterator_t authStart = protocolEnd;
iterator_t authEnd = std::find(protocolEnd, uriEnd, '@');
auto authStart = protocolEnd;
auto authEnd = std::find(protocolEnd, uriEnd, '@');
if (authEnd != uriEnd) {
iterator_t userStart = authStart;
iterator_t userEnd = std::find(authStart, authEnd, ':');
auto userStart = authStart;
auto userEnd = std::find(authStart, authEnd, ':');
if (userEnd != authEnd) {
result.Username = std::string(userStart, userEnd);
++userEnd;
Expand All @@ -302,19 +300,19 @@ Uri Uri::Parse(const std::string& uri) {
}

// host
iterator_t hostStart = authEnd;
iterator_t pathStart = std::find(hostStart, uriEnd, '/'); // get pathStart
auto hostStart = authEnd;
auto pathStart = std::find(hostStart, uriEnd, '/'); // get pathStart

iterator_t hostEnd = std::find(authEnd, (pathStart != uriEnd) ? pathStart : queryStart,
':'); // check for port
auto hostEnd = std::find(authEnd, (pathStart != uriEnd) ? pathStart : queryStart,
':'); // check for port

result.Host = std::string(hostStart, hostEnd);

// port
if ((hostEnd != uriEnd) && ((&*(hostEnd))[0] == ':')) // we have a port
{
++hostEnd;
iterator_t portEnd = (pathStart != uriEnd) ? pathStart : queryStart;
auto portEnd = (pathStart != uriEnd) ? pathStart : queryStart;
result.Port = std::string(hostEnd, portEnd);
}
if (!result.Port.length() && result.Protocol == "http")
Expand Down
3 changes: 1 addition & 2 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

#include <algorithm>
#include <cctype>
#include <iterator>

namespace Exiv2::Internal {

std::string upper(const std::string& str) {
std::string result;
std::transform(str.begin(), str.end(), std::back_inserter(result), ::toupper);
std::transform(str.begin(), str.end(), result.begin(), ::toupper);
return result;
}

Expand Down

0 comments on commit 90c3e90

Please sign in to comment.