Skip to content
Snippets Groups Projects
Commit 32c9b13a authored by Eric Cano's avatar Eric Cano
Browse files

Added a pre-ellipsis function in the utils.

parent a425d203
Branches
Tags
No related merge requests found
......@@ -656,6 +656,7 @@ TEST_F(cta_UtilsTest, ellipses) {
ASSERT_EQ("1234567890", midEllipsis("1234567890", 12));
ASSERT_EQ("123[...]CDEF", midEllipsis("1234567890ABCDEF", 12));
ASSERT_EQ("1[...]ABCDEF", midEllipsis("1234567890ABCDEF", 12, 1));
ASSERT_EQ("[...]0ABCDEF", preEllipsis("1234567890ABCDEF", 12));
}
} // namespace unitTests
......@@ -285,6 +285,18 @@ std::string midEllipsis(const std::string &s, size_t maxSize, size_t beginingSiz
return s.substr(0, beginingSize) + ellipsis + s.substr(s.size() - maxSize + ellipsis.size() + beginingSize);
}
//------------------------------------------------------------------------------
// preEllipsis
//------------------------------------------------------------------------------
std::string preEllipsis(const std::string &s, size_t maxSize) {
std::string ellipsis = "[...]";
if (maxSize < ellipsis.size())
throw cta::exception::Exception("In cta::utils::postEllipsis(): maxSize cannot be smaller than ellipsis size");
if (s.size() <= maxSize)
return s;
return ellipsis + s.substr(s.size() - maxSize + ellipsis.size());
}
//------------------------------------------------------------------------------
// singleSpaceString
//------------------------------------------------------------------------------
......
......@@ -132,8 +132,18 @@ namespace utils {
* @param beginingSize
* @return the ellipsed string
*/
std::string midEllipsis(const std::string &s, size_t maxSize, size_t beginingSize = 0);
/**
* Returns a string with an ellipsis in the beginning if necessary so that the
* string plus ellipsis does not exceed the maxSize. The returned string is
* identical to s if it fits the maximum size.
* @param s the string
* @param maxSize
* @return the ellipsed string
*/
std::string preEllipsis(const std::string &s, size_t maxSize);
/**
* Returns uuid in the form of a string.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment