Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Hurstel
CGoGN
Commits
42798448
Commit
42798448
authored
Feb 21, 2014
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utility fonction of path/name extractions
parent
928f2127
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
1 deletion
+40
-1
include/Utils/filename.h
include/Utils/filename.h
+40
-1
No files found.
include/Utils/filename.h
View file @
42798448
...
...
@@ -32,7 +32,7 @@ namespace CGoGN
namespace
Utils
{
/**
* @brief check
F
ile
N
ame
E
xtension
* @brief check
if f
ile
n
ame
has e
xtension
and add it if not
* @param filename
* @param extension (with . example ".svg")
* @return the modified (or not) filename
...
...
@@ -44,11 +44,50 @@ inline std::string checkFileNameExtension(const std::string &filename, const std
{
if
(
filename
[
filename
.
size
()
-
1
]
==
'.'
)
return
filename
.
substr
(
0
,
filename
.
size
()
-
1
)
+
extension
;
return
filename
+
extension
;
}
return
filename
;
}
/**
* @brief extract the path from a file-name
* @param filename
* @return the path (with ending /) if there is a / (or \) in filename
*/
inline
std
::
string
extractPathFromFileName
(
const
std
::
string
&
filename
)
{
std
::
size_t
found
=
filename
.
rfind
(
'/'
);
if
(
found
==
std
::
string
::
npos
)
found
=
filename
.
rfind
(
'\\'
);
// welcome on NTFS ;)
if
(
found
==
std
::
string
::
npos
)
return
""
;
return
filename
.
substr
(
0
,
found
+
1
);
}
/**
* @brief extract the name from a file-name
* @param filename
* @return the name of file (string behind last / (or /))
*/
inline
std
::
string
extractNameFromFileName
(
const
std
::
string
&
filename
)
{
std
::
size_t
found
=
filename
.
rfind
(
'/'
);
if
(
found
==
std
::
string
::
npos
)
found
=
filename
.
rfind
(
'\\'
);
// welcome on NTFS ;)
if
(
found
==
std
::
string
::
npos
)
return
filename
;
return
filename
.
substr
(
found
+
1
);
}
}
}
...
...
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