Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
a2deb999
Commit
a2deb999
authored
Feb 29, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
4350ca0d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
str_util.h
jlib/util/str_util.h
+38
-0
test_strutil.cpp
test/test_strutil/test_strutil.cpp
+16
-0
No files found.
jlib/util/str_util.h
View file @
a2deb999
...
...
@@ -99,4 +99,42 @@ inline std::wstring remove_all_copy(std::wstring str, wchar_t c) {
}
/**************************** case-conv ***************************/
void
to_upper
(
std
::
string
&
str
)
{
std
::
for_each
(
str
.
begin
(),
str
.
end
(),
[](
char
&
c
)
{
c
=
::
toupper
(
c
);
});
}
void
to_upper
(
std
::
wstring
&
str
)
{
std
::
for_each
(
str
.
begin
(),
str
.
end
(),
[](
wchar_t
&
c
)
{
c
=
::
toupper
(
c
);
});
}
std
::
string
to_upper_copy
(
std
::
string
str
)
{
std
::
for_each
(
str
.
begin
(),
str
.
end
(),
[](
char
&
c
)
{
c
=
::
toupper
(
c
);
});
return
str
;
}
std
::
wstring
to_upper_copy
(
std
::
wstring
str
)
{
std
::
for_each
(
str
.
begin
(),
str
.
end
(),
[](
wchar_t
&
c
)
{
c
=
::
toupper
(
c
);
});
return
str
;
}
void
to_lower
(
std
::
string
&
str
)
{
std
::
for_each
(
str
.
begin
(),
str
.
end
(),
[](
char
&
c
)
{
c
=
::
tolower
(
c
);
});
}
void
to_lower
(
std
::
wstring
&
str
)
{
std
::
for_each
(
str
.
begin
(),
str
.
end
(),
[](
wchar_t
&
c
)
{
c
=
::
tolower
(
c
);
});
}
std
::
string
to_lower_copy
(
std
::
string
str
)
{
std
::
for_each
(
str
.
begin
(),
str
.
end
(),
[](
char
&
c
)
{
c
=
::
tolower
(
c
);
});
return
str
;
}
std
::
wstring
to_lower_copy
(
std
::
wstring
str
)
{
std
::
for_each
(
str
.
begin
(),
str
.
end
(),
[](
wchar_t
&
c
)
{
c
=
::
tolower
(
c
);
});
return
str
;
}
}
// namespace jlib
test/test_strutil/test_strutil.cpp
View file @
a2deb999
...
...
@@ -58,4 +58,20 @@ int main()
remove_all
(
wstr
,
L'b'
);
assert
(
wstr
==
L"cc"
);
remove_all
(
wstr
,
L'c'
);
assert
(
wstr
==
L""
);
}
// case-conv
{
string
str
=
"abc"
;
assert
(
to_upper_copy
(
str
)
==
"ABC"
);
to_upper
(
str
);
assert
(
str
==
"ABC"
);
assert
(
to_lower_copy
(
str
)
==
"abc"
);
to_lower
(
str
);
assert
(
str
==
"abc"
);
wstring
wstr
=
L"abc"
;
assert
(
to_upper_copy
(
wstr
)
==
L"ABC"
);
to_upper
(
wstr
);
assert
(
wstr
==
L"ABC"
);
assert
(
to_lower_copy
(
wstr
)
==
L"abc"
);
to_lower
(
wstr
);
assert
(
wstr
==
L"abc"
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment