Alexandria
2.14.1
Please provide a description of the project.
XYDataset
src
lib
StringFunctions.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2012-2020 Euclid Science Ground Segment
3
*
4
* This library is free software; you can redistribute it and/or modify it under
5
* the terms of the GNU Lesser General Public License as published by the Free
6
* Software Foundation; either version 3.0 of the License, or (at your option)
7
* any later version.
8
*
9
* This library is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12
* details.
13
*
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this library; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
*/
18
26
#include "
StringFunctions.h
"
27
28
namespace
Euclid
{
29
namespace
XYDataset {
30
31
//
32
// Make sure the string does start with only one "/" character
33
//
34
std::string
checkBeginSlashes
(
const
std::string
& input_str) {
35
36
std::string
output_str{};
37
size_t
pos = input_str.
find_first_not_of
(
"/"
) ;
38
if
(pos != std::string::npos && pos != 0) {
39
output_str = input_str.
substr
(pos);
40
output_str =
"/"
+ output_str;
41
}
42
else
{
43
// no slash at the beginning
44
output_str =
"/"
+ input_str;
45
}
46
47
return
(output_str);
48
}
49
50
//
51
// Make sure the string does not start with a "/" character
52
//
53
std::string
checkNoBeginSlashes
(
const
std::string
& input_str) {
54
55
std::string
output_str{};
56
57
if
(! input_str.
empty
()) {
58
size_t
pos = input_str.
find_first_not_of
(
"/"
) ;
59
if
( pos != 0) {
60
output_str = input_str.
substr
(pos);
61
}
62
else
{
63
// no slash
64
output_str = input_str;
65
}
66
}
67
68
return
(output_str);
69
}
70
71
//
72
// Make sure the string finishes with a "/" character and only one
73
//
74
std::string
checkEndSlashes
(
const
std::string
& input_str) {
75
76
std::string
output_str{};
77
78
size_t
pos = input_str.
find_last_not_of
(
"/"
);
79
if
( pos != input_str.
length
()-1) {
80
// add one
81
output_str = input_str.
substr
(0, pos+1) +
"/"
;
82
}
83
else
{
84
// No slash at the end
85
output_str = input_str +
"/"
;
86
}
87
88
return
(output_str);
89
}
90
91
//
92
// Remove an extension, so any character after the last "." character
93
//
94
std::string
removeExtension
(
const
std::string
& input_str) {
95
96
std::string
output_str{};
97
98
if
(! input_str.
empty
()) {
99
// Remove any file extension
100
size_t
pos = input_str.
find_last_of
(
"."
);
101
if
( pos != std::string::npos) {
102
output_str = input_str.
substr
(0,pos);
103
}
104
else
{
105
output_str = input_str;
106
}
107
}
108
109
return
(output_str);
110
}
111
112
//
113
// Remove all characters before the last "/" character
114
//
115
std::string
removeAllBeforeLastSlash
(
const
std::string
& input_str) {
116
117
std::string
output_str{};
118
119
if
(! input_str.
empty
()) {
120
// Remove any file extension
121
size_t
pos = input_str.
find_last_of
(
"/"
);
122
if
( pos != std::string::npos) {
123
output_str = input_str.
substr
(pos+1);
124
}
125
else
{
126
output_str = input_str;
127
}
128
}
129
130
return
(output_str);
131
}
132
133
}
// XYDataset namespace
134
}
// end of namespace Euclid
135
std::string
STL class.
std::string::find_last_not_of
T find_last_not_of(T... args)
std::string::length
T length(T... args)
Euclid::XYDataset::checkEndSlashes
std::string checkEndSlashes(const std::string &input_str)
Definition:
StringFunctions.cpp:74
StringFunctions.h
std::string::find_first_not_of
T find_first_not_of(T... args)
Euclid::XYDataset::removeAllBeforeLastSlash
std::string removeAllBeforeLastSlash(const std::string &input_str)
Definition:
StringFunctions.cpp:115
std::string::find_last_of
T find_last_of(T... args)
Euclid::XYDataset::removeExtension
std::string removeExtension(const std::string &input_str)
Definition:
StringFunctions.cpp:94
std::string::substr
T substr(T... args)
Euclid::XYDataset::checkNoBeginSlashes
std::string checkNoBeginSlashes(const std::string &input_str)
Definition:
StringFunctions.cpp:53
std::string::empty
T empty(T... args)
Euclid::XYDataset::checkBeginSlashes
std::string checkBeginSlashes(const std::string &input_str)
Definition:
StringFunctions.cpp:34
Euclid
Definition:
InstOrRefHolder.h:29
Generated by
1.8.17