Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
32c9b13a
Commit
32c9b13a
authored
8 years ago
by
Eric Cano
Browse files
Options
Downloads
Patches
Plain Diff
Added a pre-ellipsis function in the utils.
parent
a425d203
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common/utils/UtilsTest.cpp
+1
-0
1 addition, 0 deletions
common/utils/UtilsTest.cpp
common/utils/utils.cpp
+12
-0
12 additions, 0 deletions
common/utils/utils.cpp
common/utils/utils.hpp
+11
-1
11 additions, 1 deletion
common/utils/utils.hpp
with
24 additions
and
1 deletion
common/utils/UtilsTest.cpp
+
1
−
0
View file @
32c9b13a
...
...
@@ -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
This diff is collapsed.
Click to expand it.
common/utils/utils.cpp
+
12
−
0
View file @
32c9b13a
...
...
@@ -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
//------------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
common/utils/utils.hpp
+
11
−
1
View file @
32c9b13a
...
...
@@ -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.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment