Skip to content

Commit

Permalink
Fix: #577
Browse files Browse the repository at this point in the history
  • Loading branch information
clanmills authored and piponazo committed Dec 9, 2018
1 parent 6f3e107 commit 56ba273
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/minoltamn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2011,25 +2011,21 @@ namespace Exiv2 {
return ltrim(rtrim(s, t), t);
}

//! http://www.sbin.org/doc/HOWTO/C++Programming-HOWTO-7.html
static void tokenize(const std::string& str,
std::vector<std::string>& tokens,
const std::string& delimiters = " ")
// https://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c
static std::vector<std::string> split(const std::string& str, const std::string& delim)
{
// Skip delimiters at beginning.
std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
std::string::size_type pos = str.find_first_of(delimiters, lastPos);

while (std::string::npos != pos || std::string::npos != lastPos)
std::vector<std::string> tokens;
size_t prev = 0, pos = 0;
do
{
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length();
std::string token = str.substr(prev, pos-prev);
if (!token.empty()) tokens.push_back(token);
prev = pos + delim.length();
}
while (pos < str.length() && prev < str.length());
return tokens;
}

static bool inRange(long value,long min,long max)
Expand All @@ -2040,8 +2036,7 @@ namespace Exiv2 {
static std::ostream& resolvedLens(std::ostream& os,long lensID,long index)
{
const TagDetails* td = find(minoltaSonyLensID, lensID);
std::vector<std::string> tokens;
tokenize(td[0].label_,tokens,"|");
std::vector<std::string> tokens = split(td[0].label_,"|");
return os << exvGettext(trim(tokens[index-1]).c_str());
}

Expand Down

0 comments on commit 56ba273

Please sign in to comment.