Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-xt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
ag-ohlberger
dune-community
dune-xt
Commits
66374f74
Commit
66374f74
authored
12 years ago
by
Dr. Felix Tobias Schindler
Browse files
Options
Downloads
Patches
Plain Diff
[common.color] added highlightString() which takes Colors::color
parent
5891aa5d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/stuff/common/color.hh
+25
-21
25 additions, 21 deletions
dune/stuff/common/color.hh
with
25 additions
and
21 deletions
dune/stuff/common/color.hh
+
25
−
21
View file @
66374f74
...
...
@@ -156,29 +156,33 @@ std::string highlightTemplate(std::string str, int maxlevel = 10000)
std
::
string
highlightString
(
std
::
string
str
,
int
colornr
=
0
)
{
return
"
\033
[38;5;"
+
toString
(
colornr
%
256
)
+
"m"
+
str
+
"
\033
[38;5;0m"
;
}
/**
* @brief Highlights a substring of another string in a specified color.
*
* @param str The string where you want to highlight substrings.
* @param substr The sub string you want to highlight in str.
* @param colornr A color number from a 256 color map between 0 and 255.
* @returns The highlighted string.
*/
std
::
string
highlightSearchString
(
std
::
string
str
,
std
::
string
substr
,
int
colornr
=
0
)
{
int
index
=
str
.
find
(
substr
,
0
);
while
(
index
!=
int
(
std
::
string
::
npos
))
{
std
::
string
dummy
=
"
\033
[38;5;"
+
toString
(
colornr
%
256
)
+
"m"
;
std
::
string
dummy2
=
"
\033
[38;5;0m"
;
str
.
insert
(
index
,
dummy
);
str
.
insert
(
index
+
substr
.
size
()
+
dummy
.
size
(),
dummy2
);
index
=
str
.
find
(
substr
,
index
+
dummy
.
size
()
+
substr
.
size
()
+
dummy2
.
size
());
std
::
string
highlightString
(
const
std
::
string
string
,
const
std
::
string
color
=
Colors
::
red
)
{
return
color
+
string
+
"
\033
[0m"
;
}
return
str
;
}
// highlightSearchString
/**
* @brief Highlights a substring of another string in a specified color.
*
* @param str The string where you want to highlight substrings.
* @param substr The sub string you want to highlight in str.
* @param colornr A color number from a 256 color map between 0 and 255.
* @returns The highlighted string.
*/
std
::
string
highlightSearchString
(
std
::
string
str
,
std
::
string
substr
,
int
colornr
=
0
)
{
int
index
=
str
.
find
(
substr
,
0
);
while
(
index
!=
int
(
std
::
string
::
npos
))
{
std
::
string
dummy
=
"
\033
[38;5;"
+
toString
(
colornr
%
256
)
+
"m"
;
std
::
string
dummy2
=
"
\033
[38;5;0m"
;
str
.
insert
(
index
,
dummy
);
str
.
insert
(
index
+
substr
.
size
()
+
dummy
.
size
(),
dummy2
);
index
=
str
.
find
(
substr
,
index
+
dummy
.
size
()
+
substr
.
size
()
+
dummy2
.
size
());
}
return
str
;
}
// highlightSearchString
}
// namespace Common
}
// namespace Stuff
...
...
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