Skip to content
Snippets Groups Projects
Commit 52c6bdfd authored by Franck Dary's avatar Franck Dary
Browse files

Fixed problem in string shrinking

parent ab5ce4a9
No related branches found
No related tags found
No related merge requests found
...@@ -472,15 +472,29 @@ std::string shrinkString(const std::string & base, int maxSize, const std::strin ...@@ -472,15 +472,29 @@ std::string shrinkString(const std::string & base, int maxSize, const std::strin
int tokenSize = getNbSymbols(token); int tokenSize = getNbSymbols(token);
if (baseSize <= maxSize) if (baseSize <= maxSize)
{
if (!utf8::is_valid(base.begin(), base.end()))
{
fprintf(stderr, "ERROR (%s) : ShrinkString with base=<%s> maxSize=<%d> token=<%s> produced the following invalid UTF-8 string <%s>. Aborting.\n", ERRINFO, base.c_str(), maxSize, token.c_str(), base.c_str());
exit(1);
}
return base; return base;
}
int nbToTakeBegin = ((maxSize-tokenSize) / 2) + ((maxSize-tokenSize)%2); int nbToTakeBegin = ((maxSize-tokenSize) / 2) + ((maxSize-tokenSize)%2);
int nbToTakeEnd = maxSize-tokenSize-nbToTakeBegin; int nbToTakeEnd = maxSize-tokenSize-nbToTakeBegin;
std::string result(base.begin(), base.begin()+getEndIndexOfNthSymbol(base, nbToTakeBegin)); std::string result(base.begin(), base.begin()+getEndIndexOfNthSymbol(base, nbToTakeBegin-1)+1);
std::string strBegin = result;
result += token; result += token;
result += std::string(base.begin()+getStartIndexOfNthSymbol(base,baseSize-nbToTakeEnd), base.end()); result += std::string(base.begin()+getStartIndexOfNthSymbol(base,baseSize-nbToTakeEnd), base.end());
if (!utf8::is_valid(result.begin(), result.end()))
{
fprintf(stderr, "ERROR (%s) : ShrinkString with base=<%s> maxSize=<%d> token=<%s> produced the following invalid UTF-8 string <%s>. Aborting.\n", ERRINFO, base.c_str(), maxSize, token.c_str(), result.c_str());
exit(1);
}
return result; return result;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment