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
00041
00042
00049 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CONTAINER_SLICE_FUNCTIONS
00050 #define STLSOFT_INCL_STLSOFT_STRING_HPP_CONTAINER_SLICE_FUNCTIONS
00051
00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_CONTAINER_SLICE_FUNCTIONS_MAJOR 2
00054 # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_CONTAINER_SLICE_FUNCTIONS_MINOR 1
00055 # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_CONTAINER_SLICE_FUNCTIONS_REVISION 3
00056 # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_CONTAINER_SLICE_FUNCTIONS_EDIT 22
00057 #endif
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00074 # include <stlsoft/stlsoft.h>
00075 #endif
00076 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS
00077 # include <stlsoft/string/string_traits.hpp>
00078 #endif
00079 #if !defined(STLSOFT_STRING_CONTAINER_SLICE_FNS_STRING_TEMPLATE)
00080 # if defined(STLSOFT_STRING_CONTAINERS_SLICE_FNS_USE_std_basic_string) || \
00081 defined(STLSOFT_STRING_CONTAINERS_SLICE_FNS_USE_STD_BASIC_STRING)
00082 # include <string>
00083 # else
00084 # ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
00085 # include <stlsoft/string/simple_string.hpp>
00086 # endif
00087 # endif
00088 #endif
00089 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_MINMAX
00090 # include <stlsoft/util/minmax.hpp>
00091 #endif
00092 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00093 # include <stlsoft/shims/access/string.hpp>
00094 #endif
00095
00096 #ifdef STLSOFT_UNITTEST
00097 # include <string>
00098 # ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
00099 # include <stlsoft/string/simple_string.hpp>
00100 # endif
00101 #if 0
00102 # if defined(WIN32) && \
00103 ( defined(STLSOFT_COMPILER_IS_INTEL) || \
00104 defined(STLSOFT_COMPILER_IS_MSVC))
00105 # include <afx.h>
00106 # ifndef MFCSTL_INCL_MFCSTL_SHIMS_ACCESS_HPP_STRING
00107 # include <mfcstl/shims/access/string.hpp>
00108 # endif
00109 # ifndef MFCSTL_INCL_MFCSTL_HPP_STRING_TRAITS
00110 # include <mfcstl/string_traits.hpp>
00111 # endif
00112 # endif
00113 #endif
00114 #endif
00115
00116
00117
00118
00119
00120 #ifndef _STLSOFT_NO_NAMESPACE
00121 namespace stlsoft
00122 {
00123 #endif
00124
00125
00126
00127
00128
00129 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00130
00131 template <ss_typename_param_k S>
00132 inline ss_size_t left_len(S const& s, ss_size_t n)
00133 {
00134 const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);
00135
00136 if(n > len)
00137 {
00138 n = len;
00139 }
00140
00141 return n;
00142 }
00143
00144 #endif
00145
00146
00147
00148
00149
00154 template <ss_typename_param_k S>
00155 inline S left(S const& s, ss_size_t n)
00156 {
00157 typedef string_traits<S> traits_t;
00158
00159 return traits_t::construct(s, 0, left_len(s, n));
00160 }
00161
00166 template <ss_typename_param_k S>
00167 inline S right(S const& s, ss_size_t n)
00168 {
00169 typedef string_traits<S> traits_t;
00170
00171 const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);
00172
00173 if(n > len)
00174 {
00175 n = len;
00176 }
00177
00178 return traits_t::construct(s, len - n, n);
00179 }
00180
00185 template <ss_typename_param_k S>
00186 inline S mid(S const& s, ss_size_t pos, ss_size_t n)
00187 {
00188 typedef string_traits<S> traits_t;
00189
00190 const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);
00191
00192 if(pos > len)
00193 {
00194 pos = len;
00195 }
00196
00197 if(n > len - pos)
00198 {
00199 n = len - pos;
00200 }
00201
00202 return traits_t::construct(s, pos, n);
00203 }
00204
00205
00206
00207
00208
00209 #if defined(STLSOFT_STRING_CONTAINER_SLICE_FNS_STRING_TEMPLATE)
00210 # define _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE STLSOFT_STRING_CONTAINER_SLICE_FNS_STRING_TEMPLATE
00211 #elif defined(STLSOFT_STRING_CONTAINERS_SLICE_FNS_USE_std_basic_string) || \
00212 defined(STLSOFT_STRING_CONTAINERS_SLICE_FNS_USE_STD_BASIC_STRING)
00213 # define _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE stlsoft_ns_qual_std(basic_string)
00214 #else
00215 # define _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE stlsoft_ns_qual(basic_simple_string)
00216 #endif
00217
00218
00223 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_a_t> left(ss_char_a_t const* s, ss_size_t n)
00224 {
00225 typedef _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_a_t> string_t;
00226
00227 return string_t(s, left_len(s, n));
00228 }
00229
00234 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_a_t> left(ss_char_a_t *s, ss_size_t n)
00235 {
00236 return left(const_cast<ss_char_a_t const*>(s), n);
00237 }
00238
00243 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_w_t> left(ss_char_w_t const* s, ss_size_t n)
00244 {
00245 typedef _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_w_t> string_t;
00246
00247 return string_t(s, left_len(s, n));
00248 }
00249
00254 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_w_t> left(ss_char_w_t *s, ss_size_t n)
00255 {
00256 return left(const_cast<ss_char_w_t const*>(s), n);
00257 }
00258
00259
00264 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_a_t> right(ss_char_a_t const* s, ss_size_t n)
00265 {
00266 typedef _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_a_t> string_t;
00267
00268 const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);
00269
00270 if(n > len)
00271 {
00272 n = len;
00273 }
00274
00275 return string_t(s + (len - n), n);
00276 }
00277
00282 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_a_t> right(ss_char_a_t *s, ss_size_t n)
00283 {
00284 return right(const_cast<ss_char_a_t const*>(s), n);
00285 }
00286
00291 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_w_t> right(ss_char_w_t const* s, ss_size_t n)
00292 {
00293 typedef _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_w_t> string_t;
00294
00295 const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);
00296
00297 if(n > len)
00298 {
00299 n = len;
00300 }
00301
00302 return string_t(s + (len - n), n);
00303 }
00304
00309 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_w_t> right(ss_char_w_t *s, ss_size_t n)
00310 {
00311 return right(const_cast<ss_char_w_t const*>(s), n);
00312 }
00313
00314
00319 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_a_t> mid(ss_char_a_t const* s, ss_size_t pos, ss_size_t n)
00320 {
00321 typedef _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_a_t> string_t;
00322
00323 const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);
00324
00325 if(pos > len)
00326 {
00327 pos = len;
00328 }
00329
00330 if(n > len - pos)
00331 {
00332 n = len - pos;
00333 }
00334
00335 return string_t(s + pos, n);
00336 }
00337
00342 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_a_t> mid(ss_char_a_t *s, ss_size_t pos, ss_size_t n)
00343 {
00344 return mid(const_cast<ss_char_a_t const*>(s), pos, n);
00345 }
00346
00351 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_w_t> mid(ss_char_w_t const* s, ss_size_t pos, ss_size_t n)
00352 {
00353 typedef _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_w_t> string_t;
00354
00355 const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);
00356
00357 if(pos > len)
00358 {
00359 pos = len;
00360 }
00361
00362 if(n > len - pos)
00363 {
00364 n = len - pos;
00365 }
00366
00367 return string_t(s + pos, n);
00368 }
00369
00374 inline _STLSOFT_STRING_CONTAINER_SLICE_FUNCTIONS_RETURN_TEMPLATE<ss_char_w_t> mid(ss_char_w_t *s, ss_size_t pos, ss_size_t n)
00375 {
00376 return mid(const_cast<ss_char_w_t const*>(s), pos, n);
00377 }
00378
00380
00381
00382 #ifdef STLSOFT_UNITTEST
00383 # include "./unittest/container_slice_functions_unittest_.h"
00384 #endif
00385
00386
00387
00388 #ifndef _STLSOFT_NO_NAMESPACE
00389 }
00390 #endif
00391
00392
00393
00394 #endif
00395
00396