Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
289fdcc5
Commit
289fdcc5
authored
Dec 05, 2013
by
Denis Krjuchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/Traits: implement GetBase/GetParent/Build using templates
parent
83e6e3e3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
22 deletions
+88
-22
Traits.cxx
src/fs/Traits.cxx
+63
-22
Traits.hxx
src/fs/Traits.hxx
+25
-0
No files found.
src/fs/Traits.cxx
View file @
289fdcc5
...
@@ -22,24 +22,25 @@
...
@@ -22,24 +22,25 @@
#include <string.h>
#include <string.h>
PathTraitsFS
::
string
template
<
typename
Traits
>
PathTraitsFS
::
Build
(
PathTraitsFS
::
const_pointer
a
,
size_t
a_size
,
typename
Traits
::
string
PathTraitsFS
::
const_pointer
b
,
size_t
b_size
)
BuildPathImpl
(
typename
Traits
::
const_pointer
a
,
size_t
a_size
,
typename
Traits
::
const_pointer
b
,
size_t
b_size
)
{
{
assert
(
a
!=
nullptr
);
assert
(
a
!=
nullptr
);
assert
(
b
!=
nullptr
);
assert
(
b
!=
nullptr
);
if
(
a_size
==
0
)
if
(
a_size
==
0
)
return
string
(
b
,
b_size
);
return
typename
Traits
::
string
(
b
,
b_size
);
if
(
b_size
==
0
)
if
(
b_size
==
0
)
return
string
(
a
,
a_size
);
return
typename
Traits
::
string
(
a
,
a_size
);
string
result
(
a
,
a_size
);
typename
Traits
::
string
result
(
a
,
a_size
);
if
(
!
IsSeparator
(
a
[
a_size
-
1
]))
if
(
!
Traits
::
IsSeparator
(
a
[
a_size
-
1
]))
result
.
push_back
(
SEPARATOR
);
result
.
push_back
(
Traits
::
SEPARATOR
);
if
(
IsSeparator
(
b
[
0
]))
if
(
Traits
::
IsSeparator
(
b
[
0
]))
result
.
append
(
b
+
1
,
b_size
-
1
);
result
.
append
(
b
+
1
,
b_size
-
1
);
else
else
result
.
append
(
b
,
b_size
);
result
.
append
(
b
,
b_size
);
...
@@ -47,26 +48,66 @@ PathTraitsFS::Build(PathTraitsFS::const_pointer a, size_t a_size,
...
@@ -47,26 +48,66 @@ PathTraitsFS::Build(PathTraitsFS::const_pointer a, size_t a_size,
return
result
;
return
result
;
}
}
PathTraitsUTF8
::
const_pointer
template
<
typename
Traits
>
PathTraitsUTF8
::
GetBase
(
PathTraitsUTF8
::
const_pointer
p
)
typename
Traits
::
const_pointer
GetBasePathImpl
(
typename
Traits
::
const_pointer
p
)
{
{
assert
(
p
!=
nullptr
);
assert
(
p
!=
nullptr
);
const
char
*
slash
=
strrchr
(
p
,
SEPARATOR
);
typename
Traits
::
const_pointer
sep
=
Traits
::
FindLastSeparator
(
p
);
return
s
lash
!=
nullptr
return
s
ep
!=
nullptr
?
s
lash
+
1
?
s
ep
+
1
:
p
;
:
p
;
}
}
PathTraitsUTF8
::
string
template
<
typename
Traits
>
PathTraitsUTF8
::
GetParent
(
PathTraitsUTF8
::
const_pointer
p
)
typename
Traits
::
string
GetParentPathImpl
(
typename
Traits
::
const_pointer
p
)
{
{
assert
(
p
!=
nullptr
);
assert
(
p
!=
nullptr
);
const
char
*
slash
=
strrchr
(
p
,
SEPARATOR
);
typename
Traits
::
const_pointer
sep
=
Traits
::
FindLastSeparator
(
p
);
if
(
slash
==
nullptr
)
if
(
sep
==
nullptr
)
return
std
::
string
(
"."
);
return
typename
Traits
::
string
(
"."
);
if
(
slash
==
p
)
if
(
sep
==
p
)
return
std
::
string
(
p
,
p
+
1
);
return
typename
Traits
::
string
(
p
,
p
+
1
);
return
std
::
string
(
p
,
slash
);
return
typename
Traits
::
string
(
p
,
sep
);
}
PathTraitsFS
::
string
PathTraitsFS
::
Build
(
PathTraitsFS
::
const_pointer
a
,
size_t
a_size
,
PathTraitsFS
::
const_pointer
b
,
size_t
b_size
)
{
return
BuildPathImpl
<
PathTraitsFS
>
(
a
,
a_size
,
b
,
b_size
);
}
PathTraitsFS
::
const_pointer
PathTraitsFS
::
GetBase
(
PathTraitsFS
::
const_pointer
p
)
{
return
GetBasePathImpl
<
PathTraitsFS
>
(
p
);
}
PathTraitsFS
::
string
PathTraitsFS
::
GetParent
(
PathTraitsFS
::
const_pointer
p
)
{
return
GetParentPathImpl
<
PathTraitsFS
>
(
p
);
}
PathTraitsUTF8
::
string
PathTraitsUTF8
::
Build
(
PathTraitsUTF8
::
const_pointer
a
,
size_t
a_size
,
PathTraitsUTF8
::
const_pointer
b
,
size_t
b_size
)
{
return
BuildPathImpl
<
PathTraitsUTF8
>
(
a
,
a_size
,
b
,
b_size
);
}
PathTraitsUTF8
::
const_pointer
PathTraitsUTF8
::
GetBase
(
PathTraitsUTF8
::
const_pointer
p
)
{
return
GetBasePathImpl
<
PathTraitsUTF8
>
(
p
);
}
PathTraitsUTF8
::
string
PathTraitsUTF8
::
GetParent
(
PathTraitsUTF8
::
const_pointer
p
)
{
return
GetParentPathImpl
<
PathTraitsUTF8
>
(
p
);
}
}
src/fs/Traits.hxx
View file @
289fdcc5
...
@@ -84,6 +84,21 @@ struct PathTraitsFS {
...
@@ -84,6 +84,21 @@ struct PathTraitsFS {
}
}
/**
/**
* Determine the "base" file name of the given native path.
* The return value points inside the given string.
*/
gcc_pure
gcc_nonnull_all
static
const_pointer
GetBase
(
const_pointer
p
);
/**
* Determine the "parent" file name of the given native path.
* As a special case, returns the string "." if there is no
* separator in the given input string.
*/
gcc_pure
gcc_nonnull_all
static
string
GetParent
(
const_pointer
p
);
/**
* Constructs the path from the given components.
* Constructs the path from the given components.
* If either of the components is empty string,
* If either of the components is empty string,
* remaining component is returned unchanged.
* remaining component is returned unchanged.
...
@@ -139,6 +154,16 @@ struct PathTraitsUTF8 {
...
@@ -139,6 +154,16 @@ struct PathTraitsUTF8 {
*/
*/
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
static
string
GetParent
(
const_pointer
p
);
static
string
GetParent
(
const_pointer
p
);
/**
* Constructs the path from the given components.
* If either of the components is empty string,
* remaining component is returned unchanged.
* If both components are empty strings, empty string is returned.
*/
gcc_pure
gcc_nonnull_all
static
string
Build
(
const_pointer
a
,
size_t
a_size
,
const_pointer
b
,
size_t
b_size
);
};
};
#endif
#endif
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