Skip to content

Commit 7631f72

Browse files
authored
Merge pull request #15 from clhsieh/direct_return_wrapper
Implement the wrapper for direct return vector<string> for issue #12
2 parents b62203a + 8d1bdb2 commit 7631f72

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pystring.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ namespace pystring
150150
/// not found, the original string will be returned with two empty strings.
151151
///
152152
void partition( const std::string & str, const std::string & sep, std::vector< std::string > & result );
153+
inline std::vector< std::string > partition( const std::string & str, const std::string & sep )
154+
{
155+
std::vector< std::string > result;
156+
partition( str, sep, result );
157+
return result;
158+
}
153159

154160
//////////////////////////////////////////////////////////////////////////////////////////////
155161
/// @brief Return a copy of the string with all occurrences of substring old replaced by new. If
@@ -183,6 +189,12 @@ namespace pystring
183189
/// not found, the original string will be returned with two empty strings.
184190
///
185191
void rpartition( const std::string & str, const std::string & sep, std::vector< std::string > & result );
192+
inline std::vector< std::string > rpartition ( const std::string & str, const std::string & sep )
193+
{
194+
std::vector< std::string > result;
195+
rpartition( str, sep, result );
196+
return result;
197+
}
186198

187199
//////////////////////////////////////////////////////////////////////////////////////////////
188200
/// @brief Return a copy of the string with trailing characters removed. If chars is "", whitespace
@@ -197,6 +209,12 @@ namespace pystring
197209
/// any whitespace string is a separator.
198210
///
199211
void split( const std::string & str, std::vector< std::string > & result, const std::string & sep = "", int maxsplit = -1);
212+
inline std::vector< std::string > split( const std::string & str, const std::string & sep = "", int maxsplit = -1)
213+
{
214+
std::vector< std::string > result;
215+
split( str, result, sep, maxsplit );
216+
return result;
217+
}
200218

201219
//////////////////////////////////////////////////////////////////////////////////////////////
202220
/// @brief Fills the "result" list with the words in the string, using sep as the delimiter string.
@@ -206,12 +224,24 @@ namespace pystring
206224
/// any whitespace string is a separator.
207225
///
208226
void rsplit( const std::string & str, std::vector< std::string > & result, const std::string & sep = "", int maxsplit = -1);
227+
inline std::vector< std::string > rsplit( const std::string & str, const std::string & sep = "", int maxsplit = -1)
228+
{
229+
std::vector< std::string > result;
230+
rsplit( str, result, sep, maxsplit);
231+
return result;
232+
}
209233

210234
//////////////////////////////////////////////////////////////////////////////////////////////
211235
/// @brief Return a list of the lines in the string, breaking at line boundaries. Line breaks
212236
/// are not included in the resulting list unless keepends is given and true.
213237
///
214238
void splitlines( const std::string & str, std::vector< std::string > & result, bool keepends = false );
239+
inline std::vector< std::string > splitlines( const std::string & str, bool keepends = false )
240+
{
241+
std::vector< std::string > result;
242+
splitlines( str, result, keepends);
243+
return result;
244+
}
215245

216246
//////////////////////////////////////////////////////////////////////////////////////////////
217247
/// @brief Return True if string starts with the prefix, otherwise return False. With optional start,

0 commit comments

Comments
 (0)