00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SPLIT_FUNCTIONS
00048 #define STLSOFT_INCL_STLSOFT_STRING_HPP_SPLIT_FUNCTIONS
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_SPLIT_FUNCTIONS_MAJOR 2
00052 # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_SPLIT_FUNCTIONS_MINOR 3
00053 # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_SPLIT_FUNCTIONS_REVISION 1
00054 # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_SPLIT_FUNCTIONS_EDIT 41
00055 #endif
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00075 # include <stlsoft/stlsoft.h>
00076 #endif
00077
00078 #if ( defined(STLSOFT_COMPILER_IS_BORLAND) && \
00079 __BORLANDC__ < 0x0560) || \
00080 ( defined(STLSOFT_COMPILER_IS_DMC) && \
00081 __DMC__ < 0x0844) || \
00082 ( defined(STLSOFT_COMPILER_IS_GCC) && \
00083 __GNUC__ < 3) || \
00084 ( defined(STLSOFT_COMPILER_IS_MSVC) && \
00085 _MSC_VER < 1200) || \
00086 defined(STLSOFT_COMPILER_IS_SUNPRO)
00087 # define STLSOFT_STRING_SPLIT_FUNCTIONS_CANNOT_USE_STATIC_ARRAY
00088 #endif
00089
00090 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00091 # include <stlsoft/shims/access/string.hpp>
00092 #endif
00093 #ifndef STLSOFT_STRING_SPLIT_FUNCTIONS_CANNOT_USE_STATIC_ARRAY
00094 # ifndef STLSOFT_INCL_STLSOFT_CONTAINERS_HPP_STATIC_ARRAY
00095 # include <stlsoft/containers/static_array.hpp>
00096 # endif
00097 #else
00098 # include <vector>
00099 #endif
00100
00101 #ifndef STLSOFT_INCL_ALGORITHM
00102 # define STLSOFT_INCL_ALGORITHM
00103 # include <algorithm>
00104 #endif
00105
00106 #ifdef STLSOFT_UNITTEST
00107 # include <stlsoft/string/simple_string.hpp>
00108 #endif
00109
00110
00111
00112
00113
00114 #ifndef _STLSOFT_NO_NAMESPACE
00115 namespace stlsoft
00116 {
00117 #endif
00118
00119
00120
00121
00122
00123 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00124
00125 template< ss_typename_param_k S
00126 , ss_typename_param_k C
00127 >
00128 inline ss_bool_t split_impl(C const* s, ss_size_t n, C delim, S& s0, S& s1)
00129 {
00130 C const* const b = s;
00131 C const* const e = s + n;
00132 C const* it = stlsoft_ns_qual_std(find)(b, e, delim);
00133
00134 s0 = S(b, it);
00135
00136 return (e == it) ? false : (++it, s1 = S(it, e), true);
00137 }
00138
00139 template< ss_typename_param_k S
00140 , ss_typename_param_k C
00141 >
00142 inline ss_uint_t split_impl(C const* s, ss_size_t cch, C delim, S& s0, S& s1, S& s2)
00143 {
00144 C const* const b = s;
00145 C const* const e = s + cch;
00146 C const* it0 = b;
00147 C const* it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00148 ss_uint_t n = it1 != it0;
00149
00150 s0 = S(it0, it1);
00151
00152 if(e != it1)
00153 {
00154 ++n;
00155 it0 = ++it1;
00156 it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00157 }
00158 else
00159 {
00160 it0 = it1;
00161 }
00162
00163 s1 = S(it0, it1);
00164
00165 if(e != it1)
00166 {
00167 ++n;
00168 it0 = ++it1;
00169 it1 = e;
00170 }
00171 else
00172 {
00173 it0 = it1;
00174 }
00175
00176 s2 = S(it0, it1);
00177
00178 return n;
00179 }
00180
00181 template< ss_typename_param_k S
00182 , ss_typename_param_k C
00183 >
00184 inline ss_uint_t split_impl(C const* s, ss_size_t cch, C delim, S& s0, S& s1, S& s2, S& s3)
00185 {
00186 C const* const b = s;
00187 C const* const e = s + cch;
00188 C const* it0 = b;
00189 C const* it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00190 ss_uint_t n = it1 != it0;
00191
00192 s0 = S(it0, it1);
00193
00194 if(e != it1)
00195 {
00196 ++n;
00197 it0 = ++it1;
00198 it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00199 }
00200 else
00201 {
00202 it0 = it1;
00203 }
00204
00205 s1 = S(it0, it1);
00206
00207 if(e != it1)
00208 {
00209 ++n;
00210 it0 = ++it1;
00211 it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00212 }
00213 else
00214 {
00215 it0 = it1;
00216 }
00217
00218 s2 = S(it0, it1);
00219
00220 if(e != it1)
00221 {
00222 ++n;
00223 it0 = ++it1;
00224 it1 = e;
00225 }
00226 else
00227 {
00228 it0 = it1;
00229 }
00230
00231 s3 = S(it0, it1);
00232
00233 return n;
00234 }
00235
00236 template< ss_typename_param_k S
00237 , ss_typename_param_k C
00238 >
00239 inline ss_uint_t split_impl(C const* s, ss_size_t cch, C delim, S& s0, S& s1, S& s2, S& s3, S& s4)
00240 {
00241 C const* const b = s;
00242 C const* const e = s + cch;
00243 C const* it0 = b;
00244 C const* it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00245 ss_uint_t n = it1 != it0;
00246
00247 s0 = S(it0, it1);
00248
00249 if(e != it1)
00250 {
00251 ++n;
00252 it0 = ++it1;
00253 it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00254 }
00255 else
00256 {
00257 it0 = it1;
00258 }
00259
00260 s1 = S(it0, it1);
00261
00262 if(e != it1)
00263 {
00264 ++n;
00265 it0 = ++it1;
00266 it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00267 }
00268 else
00269 {
00270 it0 = it1;
00271 }
00272
00273 s2 = S(it0, it1);
00274
00275 if(e != it1)
00276 {
00277 ++n;
00278 it0 = ++it1;
00279 it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00280 }
00281 else
00282 {
00283 it0 = it1;
00284 }
00285
00286 s3 = S(it0, it1);
00287
00288 if(e != it1)
00289 {
00290 ++n;
00291 it0 = ++it1;
00292 it1 = e;
00293 }
00294 else
00295 {
00296 it0 = it1;
00297 }
00298
00299 s4 = S(it0, it1);
00300
00301 return n;
00302 }
00303
00304 template< ss_typename_param_k S
00305 , ss_typename_param_k C
00306 >
00307 inline ss_uint_t split_impl(C const* s, ss_size_t cch, C delim, S& s0, S& s1, S& s2, S& s3, S& s4, S& s5)
00308 {
00309 C const* const b = s;
00310 C const* const e = s + cch;
00311 C const* it0 = b;
00312 C const* it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00313 ss_uint_t n = it1 != it0;
00314
00315 s0 = S(it0, it1);
00316
00317 if(e != it1)
00318 {
00319 ++n;
00320 it0 = ++it1;
00321 it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00322 }
00323 else
00324 {
00325 it0 = it1;
00326 }
00327
00328 s1 = S(it0, it1);
00329
00330 if(e != it1)
00331 {
00332 ++n;
00333 it0 = ++it1;
00334 it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00335 }
00336 else
00337 {
00338 it0 = it1;
00339 }
00340
00341 s2 = S(it0, it1);
00342
00343 if(e != it1)
00344 {
00345 ++n;
00346 it0 = ++it1;
00347 it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00348 }
00349 else
00350 {
00351 it0 = it1;
00352 }
00353
00354 s3 = S(it0, it1);
00355
00356 if(e != it1)
00357 {
00358 ++n;
00359 it0 = ++it1;
00360 it1 = stlsoft_ns_qual_std(find)(it0, e, delim);
00361 }
00362 else
00363 {
00364 it0 = it1;
00365 }
00366
00367 s4 = S(it0, it1);
00368
00369 if(e != it1)
00370 {
00371 ++n;
00372 it0 = ++it1;
00373 it1 = e;
00374 }
00375 else
00376 {
00377 it0 = it1;
00378 }
00379
00380 s5 = S(it0, it1);
00381
00382 return n;
00383 }
00384
00385 #endif
00386
00387
00388
00389
00390
00398 template< ss_typename_param_k S1
00399 , ss_typename_param_k S2
00400 , ss_typename_param_k C
00401 >
00402 inline ss_bool_t split(S1 const& s, C delim, S2& s0, S2& s1)
00403 {
00404 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s0));
00405 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s1));
00406
00407 return split_impl(c_str_data(s), c_str_len(s), delim, s0, s1);
00408 }
00409
00417 template< ss_typename_param_k S1
00418 , ss_typename_param_k S2
00419 , ss_typename_param_k C
00420 >
00421 inline ss_uint_t split(S1 const& s, C delim, S2& s0, S2& s1, S2& s2)
00422 {
00423 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s0));
00424 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s1));
00425 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s2));
00426
00427 return split_impl(c_str_data(s), c_str_len(s), delim, s0, s1, s2);
00428 }
00429
00437 template< ss_typename_param_k S1
00438 , ss_typename_param_k S2
00439 , ss_typename_param_k C
00440 >
00441 inline ss_uint_t split(S1 const& s, C delim, S2& s0, S2& s1, S2& s2, S2& s3)
00442 {
00443 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s0));
00444 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s1));
00445 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s2));
00446 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s3));
00447
00448 return split_impl(c_str_data(s), c_str_len(s), delim, s0, s1, s2, s3);
00449 }
00450
00458 template< ss_typename_param_k S1
00459 , ss_typename_param_k S2
00460 , ss_typename_param_k C
00461 >
00462 inline ss_uint_t split(S1 const& s, C delim, S2& s0, S2& s1, S2& s2, S2& s3, S2& s4)
00463 {
00464 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s0));
00465 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s1));
00466 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s2));
00467 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s3));
00468 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s4));
00469
00470 return split_impl(c_str_data(s), c_str_len(s), delim, s0, s1, s2, s3, s4);
00471 }
00472
00480 template< ss_typename_param_k S1
00481 , ss_typename_param_k S2
00482 , ss_typename_param_k C
00483 >
00484 inline ss_uint_t split(S1 const& s, C delim, S2& s0, S2& s1, S2& s2, S2& s3, S2& s4, S2& s5)
00485 {
00486 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s0));
00487 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s1));
00488 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s2));
00489 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s3));
00490 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s4));
00491 STLSOFT_MESSAGE_ASSERT("Source string specified as recipient!", static_cast<void const*>(&s) != static_cast<void const*>(&s5));
00492
00493 return split_impl(c_str_data(s), c_str_len(s), delim, s0, s1, s2, s3, s4, s5);
00494 }
00495
00501 template< ss_typename_param_k S
00502 , ss_typename_param_k C
00503 >
00504 #ifndef STLSOFT_STRING_SPLIT_FUNCTIONS_CANNOT_USE_STATIC_ARRAY
00505 inline static_array_1d<S, 2>
00506 #else
00507 inline stlsoft_ns_qual_std_(vector)<S>
00508 #endif
00509 split(S const& s, C delim)
00510 {
00511 #ifndef STLSOFT_STRING_SPLIT_FUNCTIONS_CANNOT_USE_STATIC_ARRAY
00512 static_array_1d<S, 2> r;
00513 #else
00514 stlsoft_ns_qual_std_(vector)<S> r(2);
00515 #endif
00516
00517 split_impl(c_str_data(s), c_str_len(s), delim, r[0], r[1]);
00518
00519 return r;
00520 }
00521
00523
00524
00525 #ifdef STLSOFT_UNITTEST
00526 # include "./unittest/split_functions_unittest_.h"
00527 #endif
00528
00529
00530
00531 #ifndef _STLSOFT_NO_NAMESPACE
00532 }
00533 #endif
00534
00535
00536
00537 #endif
00538
00539