Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CMake
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Johnny Jazeix
CMake
Commits
e5d3ea22
Commit
e5d3ea22
authored
5 years ago
by
Sebastian Holtermann
Browse files
Options
Downloads
Patches
Plain Diff
cmStringAlgorithms: Add cmCatViews and cmStrCat functions
parent
a7d0fe9c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Source/CMakeLists.txt
+1
-0
1 addition, 0 deletions
Source/CMakeLists.txt
Source/cmStringAlgorithms.cxx
+73
-0
73 additions, 0 deletions
Source/cmStringAlgorithms.cxx
Source/cmStringAlgorithms.h
+50
-0
50 additions, 0 deletions
Source/cmStringAlgorithms.h
bootstrap
+1
-0
1 addition, 0 deletions
bootstrap
with
125 additions
and
0 deletions
Source/CMakeLists.txt
+
1
−
0
View file @
e5d3ea22
...
@@ -404,6 +404,7 @@ set(SRCS
...
@@ -404,6 +404,7 @@ set(SRCS
cmStateSnapshot.cxx
cmStateSnapshot.cxx
cmStateSnapshot.h
cmStateSnapshot.h
cmStateTypes.h
cmStateTypes.h
cmStringAlgorithms.cxx
cmStringAlgorithms.h
cmStringAlgorithms.h
cmSystemTools.cxx
cmSystemTools.cxx
cmSystemTools.h
cmSystemTools.h
...
...
This diff is collapsed.
Click to expand it.
Source/cmStringAlgorithms.cxx
0 → 100644
+
73
−
0
View file @
e5d3ea22
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include
"cmStringAlgorithms.h"
#include
<algorithm>
#include
<cstdio>
namespace
{
template
<
std
::
size_t
N
,
typename
T
>
inline
void
MakeDigits
(
cm
::
string_view
&
view
,
char
(
&
digits
)[
N
],
const
char
*
pattern
,
T
value
)
{
int
res
=
std
::
snprintf
(
digits
,
N
,
pattern
,
value
);
if
(
res
>
0
&&
res
<
static_cast
<
int
>
(
N
))
{
view
=
cm
::
string_view
(
digits
,
static_cast
<
std
::
size_t
>
(
res
));
}
}
}
// unnamed namespace
cmAlphaNum
::
cmAlphaNum
(
int
val
)
{
MakeDigits
(
View_
,
Digits_
,
"%i"
,
val
);
}
cmAlphaNum
::
cmAlphaNum
(
unsigned
int
val
)
{
MakeDigits
(
View_
,
Digits_
,
"%u"
,
val
);
}
cmAlphaNum
::
cmAlphaNum
(
long
int
val
)
{
MakeDigits
(
View_
,
Digits_
,
"%li"
,
val
);
}
cmAlphaNum
::
cmAlphaNum
(
unsigned
long
int
val
)
{
MakeDigits
(
View_
,
Digits_
,
"%lu"
,
val
);
}
cmAlphaNum
::
cmAlphaNum
(
long
long
int
val
)
{
MakeDigits
(
View_
,
Digits_
,
"%lli"
,
val
);
}
cmAlphaNum
::
cmAlphaNum
(
unsigned
long
long
int
val
)
{
MakeDigits
(
View_
,
Digits_
,
"%llu"
,
val
);
}
cmAlphaNum
::
cmAlphaNum
(
float
val
)
{
MakeDigits
(
View_
,
Digits_
,
"%g"
,
static_cast
<
double
>
(
val
));
}
cmAlphaNum
::
cmAlphaNum
(
double
val
)
{
MakeDigits
(
View_
,
Digits_
,
"%g"
,
val
);
}
std
::
string
cmCatViews
(
std
::
initializer_list
<
cm
::
string_view
>
views
)
{
std
::
size_t
total_size
=
0
;
for
(
cm
::
string_view
const
&
view
:
views
)
{
total_size
+=
view
.
size
();
}
std
::
string
result
(
total_size
,
'\0'
);
std
::
string
::
iterator
sit
=
result
.
begin
();
for
(
cm
::
string_view
const
&
view
:
views
)
{
sit
=
std
::
copy_n
(
view
.
data
(),
view
.
size
(),
sit
);
}
return
result
;
}
This diff is collapsed.
Click to expand it.
Source/cmStringAlgorithms.h
+
50
−
0
View file @
e5d3ea22
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include
"cmRange.h"
#include
"cmRange.h"
#include
"cm_string_view.hxx"
#include
"cm_string_view.hxx"
#include
<initializer_list>
#include
<sstream>
#include
<sstream>
#include
<string.h>
#include
<string.h>
#include
<string>
#include
<string>
...
@@ -48,6 +49,55 @@ std::string cmJoin(Range const& rng, cm::string_view separator)
...
@@ -48,6 +49,55 @@ std::string cmJoin(Range const& rng, cm::string_view separator)
return
os
.
str
();
return
os
.
str
();
}
}
/** Concatenate string pieces into a single string. */
std
::
string
cmCatViews
(
std
::
initializer_list
<
cm
::
string_view
>
views
);
/** Utility class for cmStrCat. */
class
cmAlphaNum
{
public:
cmAlphaNum
(
cm
::
string_view
view
)
:
View_
(
view
)
{
}
cmAlphaNum
(
std
::
string
const
&
str
)
:
View_
(
str
)
{
}
cmAlphaNum
(
const
char
*
str
)
:
View_
(
str
)
{
}
cmAlphaNum
(
char
ch
)
:
View_
(
Digits_
,
1
)
{
Digits_
[
0
]
=
ch
;
}
cmAlphaNum
(
int
val
);
cmAlphaNum
(
unsigned
int
val
);
cmAlphaNum
(
long
int
val
);
cmAlphaNum
(
unsigned
long
int
val
);
cmAlphaNum
(
long
long
int
val
);
cmAlphaNum
(
unsigned
long
long
int
val
);
cmAlphaNum
(
float
val
);
cmAlphaNum
(
double
val
);
cm
::
string_view
View
()
const
{
return
View_
;
}
private
:
cm
::
string_view
View_
;
char
Digits_
[
32
];
};
/** Concatenate string pieces and numbers into a single string. */
template
<
typename
...
AV
>
inline
std
::
string
cmStrCat
(
cmAlphaNum
const
&
a
,
cmAlphaNum
const
&
b
,
AV
const
&
...
args
)
{
return
cmCatViews
(
{
a
.
View
(),
b
.
View
(),
static_cast
<
cmAlphaNum
const
&>
(
args
).
View
()...
});
}
template
<
typename
Range
>
template
<
typename
Range
>
std
::
string
cmWrap
(
std
::
string
const
&
prefix
,
Range
const
&
r
,
std
::
string
cmWrap
(
std
::
string
const
&
prefix
,
Range
const
&
r
,
std
::
string
const
&
suffix
,
std
::
string
const
&
sep
)
std
::
string
const
&
suffix
,
std
::
string
const
&
sep
)
...
...
This diff is collapsed.
Click to expand it.
bootstrap
+
1
−
0
View file @
e5d3ea22
...
@@ -422,6 +422,7 @@ CMAKE_CXX_SOURCES="\
...
@@ -422,6 +422,7 @@ CMAKE_CXX_SOURCES="\
cmState
\
cmState
\
cmStateDirectory
\
cmStateDirectory
\
cmStateSnapshot
\
cmStateSnapshot
\
cmStringAlgorithms
\
cmStringReplaceHelper
\
cmStringReplaceHelper
\
cmStringCommand
\
cmStringCommand
\
cmSubdirCommand
\
cmSubdirCommand
\
...
...
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