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
00043
00044
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #ifndef STLSOFT_INCL_H_STLSOFT
00064 # include "stlsoft.h"
00065 #endif
00066
00067 #ifdef __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits
00068 # undef __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits
00069 #endif
00070
00071
00072 #ifdef __STLSOFT_COMPILER_IS_WATCOM
00073 # define STLSOFT_STRING_ACCESS_NO_STD_STRING
00074 #endif
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 #ifdef _STLSOFT_STRING_ACCESS_NO_STD_STRING
00094 # define STLSOFT_STRING_ACCESS_NO_STD_STRING
00095 #endif
00096
00097 #if defined(STLSOFT_STRING_ACCESS_NO_STD_STRING)
00098 # undef __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits
00099 #elif defined(_STLSOFT_NO_NAMESPACE)
00100 # undef __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits
00101 #elif !defined(__STLSOFT_CF_std_char_traits_AVAILABLE)
00102 # undef __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits
00103 #else
00104 # define __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits
00105 #endif
00106
00107
00108 #ifndef STLSOFT_STRING_ACCESS_NO_STD_STRING
00109 # include <string>
00110 #endif
00111
00112
00113
00114
00115 #if !defined(__STLSOFT_CF_STRING_ACCESS_USE_std_char_traits)
00116 # ifndef STLSOFT_INCL_H_STLSOFT_CHAR_TRAITS
00117 # include "stlsoft_char_traits.h"
00118 # endif
00119 #endif
00120
00121 #if defined(__STLSOFT_COMPILER_IS_GCC)
00122 # include <wchar.h>
00123 #endif
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 #ifndef _STLSOFT_NO_NAMESPACE
00144 namespace stlsoft
00145 {
00146 #endif
00147
00148
00149
00151
00154
00158
00163
00164
00165
00166
00167
00168 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00169
00170 #ifndef STLSOFT_STRING_ACCESS_NO_STD_STRING
00171 # if defined(__STLSOFT_COMPILER_IS_GCC) && \
00172 ( __GNUC__ < 3 || \
00173 !defined(_GLIBCPP_USE_WCHAR_T)) // Thanks to Robert Kreger for suggesting this fix for GCC 3.3.3 on HP UX
00174 typedef stlsoft_ns_qual_std(basic_string)<ss_char_w_t> _stlsoft_wstring_t;
00175 # else
00176 typedef stlsoft_ns_qual_std(wstring) _stlsoft_wstring_t;
00177 # endif
00178 #endif
00179
00180 #endif
00181
00182
00183
00184
00185
00186
00187
00188
00189
00191 inline ss_char_a_t const *c_str_ptr_null_a(ss_char_a_t const *s)
00192 {
00193 return s;
00194 }
00195
00197 inline ss_char_a_t const *c_str_ptr_null(ss_char_a_t const *s)
00198 {
00199 return c_str_ptr_null_a(s);
00200 }
00201
00202
00204 inline ss_char_w_t const *c_str_ptr_null_w(ss_char_w_t const *s)
00205 {
00206 return s;
00207 }
00208
00210 inline ss_char_w_t const *c_str_ptr_null(ss_char_w_t const *s)
00211 {
00212 return c_str_ptr_null_w(s);
00213 }
00214
00215
00216 #ifdef _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST
00217
00218 inline ss_char_a_t const *c_str_ptr_null_a(ss_char_a_t *s)
00219 {
00220 return s;
00221 }
00222
00224 inline ss_char_a_t const *c_str_ptr_null(ss_char_a_t *s)
00225 {
00226 return c_str_ptr_null_a(s);
00227 }
00228
00229
00231 inline ss_char_w_t const *c_str_ptr_null_w(ss_char_w_t *s)
00232 {
00233 return s;
00234 }
00235
00237 inline ss_char_w_t const *c_str_ptr_null(ss_char_w_t *s)
00238 {
00239 return c_str_ptr_null_w(s);
00240 }
00241 #endif
00242
00243
00244 #ifndef STLSOFT_STRING_ACCESS_NO_STD_STRING
00245 # if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00246 _MSC_VER < 1100
00247
00248 inline ss_char_a_t const *c_str_ptr_null_a(string const &s)
00249 {
00250 return (s.length() == 0) ? 0 : s.c_str();
00251 }
00252
00254 inline ss_char_a_t const *c_str_ptr_null(string const &s)
00255 {
00256 return c_str_ptr_null_a(s);
00257 }
00258
00260 inline ss_char_w_t const *c_str_ptr_null_w(wstring const &s)
00261 {
00262 return (s.length() == 0) ? 0 : s.c_str();
00263 }
00264
00266 inline ss_char_w_t const *c_str_ptr_null(wstring const &s)
00267 {
00268 return c_str_ptr_null_w(s);
00269 }
00270 # else
00271
00272 inline ss_char_a_t const *c_str_ptr_null_a(stlsoft_ns_qual_std(string) const &s)
00273 {
00274 return (s.length() == 0) ? 0 : s.c_str();
00275 }
00276
00277 # if !defined(__STLSOFT_COMPILER_IS_GCC) || \
00278 !(__GNUC__ < 3)
00279
00280 inline ss_char_w_t const *c_str_ptr_null_w(_stlsoft_wstring_t const &s)
00281 {
00282 return (s.length() == 0) ? 0 : s.c_str();
00283 }
00284 # endif
00285
00287 template <class C>
00288 inline C const *c_str_ptr_null(stlsoft_ns_qual_std(basic_string)<C> const &s)
00289 {
00290 return (s.length() == 0) ? 0 : s.c_str();
00291 }
00292
00293 # endif
00294 #endif
00295
00296
00297 #if defined(_STLP_USE_NAMESPACES) && \
00298 defined(_STLP_USE_OWN_NAMESPACE) && \
00299 !defined(_STLP_REDEFINE_STD)
00300
00301 inline ss_char_a_t const *c_str_ptr_null_a(stlport::string const &s)
00302 {
00303 return (s.length() == 0) ? 0 : s.c_str();
00304 }
00305
00307 inline ss_char_w_t const *c_str_ptr_null_w(stlport::wstring const &s)
00308 {
00309 return (s.length() == 0) ? 0 : s.c_str();
00310 }
00311
00313 template <class C>
00314 inline C const *c_str_ptr_null(stlport::basic_string<C> const &s)
00315 {
00316 return (s.length() == 0) ? 0 : s.c_str();
00317 }
00318 #endif
00319
00320
00321
00322
00323
00324
00325
00326
00327
00329 inline ss_char_a_t const *c_str_ptr_a(ss_char_a_t const *s)
00330 {
00331 return (s != 0) ? s : "";
00332 }
00333
00335 inline ss_char_a_t const *c_str_ptr(ss_char_a_t const *s)
00336 {
00337 return c_str_ptr_a(s);
00338 }
00339
00340
00342 inline ss_char_w_t const *c_str_ptr_w(ss_char_w_t const *s)
00343 {
00344 return (s != 0) ? s : L"";
00345 }
00346
00348 inline ss_char_w_t const *c_str_ptr(ss_char_w_t const *s)
00349 {
00350 return c_str_ptr_w(s);
00351 }
00352
00353
00354 #ifdef _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST
00355
00356 inline ss_char_a_t const *c_str_ptr_a(ss_char_a_t *s)
00357 {
00358 return (s != 0) ? s : "";
00359 }
00360
00362 inline ss_char_a_t const *c_str_ptr(ss_char_a_t *s)
00363 {
00364 return c_str_ptr_a(s);
00365 }
00366
00367
00369 inline ss_char_w_t const *c_str_ptr_w(ss_char_w_t *s)
00370 {
00371 return (s != 0) ? s : L"";
00372 }
00373
00375 inline ss_char_w_t const *c_str_ptr(ss_char_w_t *s)
00376 {
00377 return c_str_ptr_w(s);
00378 }
00379 #endif
00380
00381
00382 #ifndef STLSOFT_STRING_ACCESS_NO_STD_STRING
00383 # if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00384 _MSC_VER < 1100
00385
00386 inline ss_char_a_t const *c_str_ptr_a(string const &s)
00387 {
00388 return s.c_str();
00389 }
00390
00392 inline ss_char_a_t const *c_str_ptr(string const &s)
00393 {
00394 return c_str_ptr_a(s);
00395 }
00396
00398 inline ss_char_w_t const *c_str_ptr_w(wstring const &s)
00399 {
00400 return s.c_str();
00401 }
00402
00404 inline ss_char_w_t const *c_str_ptr(wstring const &s)
00405 {
00406 return c_str_ptr_w(s);
00407 }
00408 # else
00409
00410 inline ss_char_a_t const *c_str_ptr_a(stlsoft_ns_qual_std(string) const &s)
00411 {
00412 return s.c_str();
00413 }
00414
00415 # if !defined(__STLSOFT_COMPILER_IS_GCC) || \
00416 !(__GNUC__ < 3)
00417
00418 inline ss_char_w_t const *c_str_ptr_w(_stlsoft_wstring_t const &s)
00419 {
00420 return s.c_str();
00421 }
00422 # endif
00423
00425 template <class C>
00426 inline C const *c_str_ptr(stlsoft_ns_qual_std(basic_string)<C> const &s)
00427 {
00428 return s.c_str();
00429 }
00430 # endif
00431 #endif
00432
00433
00434 #if defined(_STLP_USE_NAMESPACES) && \
00435 defined(_STLP_USE_OWN_NAMESPACE) && \
00436 !defined(_STLP_REDEFINE_STD)
00437
00438 inline ss_char_a_t const *c_str_ptr_a(stlport::string const &s)
00439 {
00440 return s.c_str();
00441 }
00442
00444 inline ss_char_w_t const *c_str_ptr_w(stlport::wstring const &s)
00445 {
00446 return s.c_str();
00447 }
00448
00450 template <class C>
00451 inline C const *c_str_ptr(stlport::basic_string<C> const &s)
00452 {
00453 return s.c_str();
00454 }
00455 #endif
00456
00457
00458
00459
00460
00461
00462
00463
00464
00466 inline ss_size_t c_str_len_a(ss_char_a_t const *s)
00467 {
00468 #if !defined(__STLSOFT_CF_STRING_ACCESS_USE_std_char_traits)
00469 return (s == 0) ? 0 : stlsoft_char_traits<ss_char_a_t>::length(s);
00470 #else
00471 return (s == 0) ? 0 : stlsoft_ns_qual_std(char_traits)<ss_char_a_t>::length(s);
00472 #endif
00473 }
00474
00476 inline ss_size_t c_str_len(ss_char_a_t const *s)
00477 {
00478 return c_str_len_a(s);
00479 }
00480
00481
00483 inline ss_size_t c_str_len_w(ss_char_w_t const *s)
00484 {
00485 #if defined(__STLSOFT_COMPILER_IS_GCC)
00486 return (s == 0) ? 0 : wcslen(s);
00487 #elif !defined(__STLSOFT_CF_STRING_ACCESS_USE_std_char_traits)
00488 return (s == 0) ? 0 : stlsoft_char_traits<ss_char_w_t>::length(s);
00489 #else
00490 return (s == 0) ? 0 : stlsoft_ns_qual_std(char_traits)<ss_char_w_t>::length(s);
00491 #endif
00492 }
00493
00495 inline ss_size_t c_str_len(ss_char_w_t const *s)
00496 {
00497 return c_str_len_w(s);
00498 }
00499
00500
00501 #ifdef _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST
00502
00503 inline ss_size_t c_str_len_a(ss_char_a_t *s)
00504 {
00505 return c_str_len_a(static_cast<ss_char_a_t const *>(s));
00506 }
00507
00509 inline ss_size_t c_str_len(ss_char_a_t *s)
00510 {
00511 return c_str_len_a(s);
00512 }
00513
00514
00516 inline ss_size_t c_str_len_w(ss_char_w_t *s)
00517 {
00518 return c_str_len_w(static_cast<ss_char_w_t const *>(s));
00519 }
00520
00522 inline ss_size_t c_str_len(ss_char_w_t *s)
00523 {
00524 return c_str_len_w(s);
00525 }
00526 #endif
00527
00528
00529 #ifndef STLSOFT_STRING_ACCESS_NO_STD_STRING
00530 # if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00531 _MSC_VER < 1100
00532
00533 inline ss_size_t c_str_len_a(string const &s)
00534 {
00535 return s.length();
00536 }
00537
00539 inline ss_size_t c_str_len(string const &s)
00540 {
00541 return c_str_len_a(s);
00542 }
00543
00545 inline ss_size_t c_str_len_w(wstring const &s)
00546 {
00547 return s.length();
00548 }
00549
00551 inline ss_size_t c_str_len(wstring const &s)
00552 {
00553 return c_str_len_w(s);
00554 }
00555 # else
00556
00557 inline ss_size_t c_str_len_a(stlsoft_ns_qual_std(string) const &s)
00558 {
00559 return s.length();
00560 }
00561
00562 # if !defined(__STLSOFT_COMPILER_IS_GCC) || \
00563 !(__GNUC__ < 3)
00564
00565 inline ss_size_t c_str_len_w(_stlsoft_wstring_t const &s)
00566 {
00567 return s.length();
00568 }
00569 # endif
00570
00572 template <class C>
00573 inline ss_size_t c_str_len(stlsoft_ns_qual_std(basic_string)<C> const &s)
00574 {
00575 return s.length();
00576 }
00577 # endif
00578 #endif
00579
00580
00581 #if defined(_STLP_USE_NAMESPACES) && \
00582 defined(_STLP_USE_OWN_NAMESPACE) && \
00583 !defined(_STLP_REDEFINE_STD)
00584
00585 inline ss_size_t c_str_len_a(stlport::string const &s)
00586 {
00587 return s.length();
00588 }
00589
00591 inline ss_size_t c_str_len_w(stlport::wstring const &s)
00592 {
00593 return s.length();
00594 }
00595
00597 template <class C>
00598 inline ss_size_t c_str_len(stlport::basic_string<C> const &s)
00599 {
00600 return s.length();
00601 }
00602 #endif
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00614 inline ss_size_t c_str_size_a(ss_char_a_t const *s)
00615 {
00616 return c_str_len(s) * sizeof(ss_char_a_t);
00617 }
00618
00620 inline ss_size_t c_str_size(ss_char_a_t const *s)
00621 {
00622 return c_str_size_a(s);
00623 }
00624
00625
00627 inline ss_size_t c_str_size_w(ss_char_w_t const *s)
00628 {
00629 return c_str_len(s) * sizeof(ss_char_w_t);
00630 }
00631
00633 inline ss_size_t c_str_size(ss_char_w_t const *s)
00634 {
00635 return c_str_size_w(s);
00636 }
00637
00638
00639 #ifdef _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST
00640
00641 inline ss_size_t c_str_size_a(ss_char_a_t *s)
00642 {
00643 return c_str_len(s) * sizeof(ss_char_a_t);
00644 }
00645
00647 inline ss_size_t c_str_size(ss_char_a_t *s)
00648 {
00649 return c_str_size_a(s);
00650 }
00651
00652
00654 inline ss_size_t c_str_size_w(ss_char_w_t *s)
00655 {
00656 return c_str_len(s) * sizeof(ss_char_w_t);
00657 }
00658
00660 inline ss_size_t c_str_size(ss_char_w_t *s)
00661 {
00662 return c_str_size_w(s);
00663 }
00664 #endif
00665
00666
00667 #ifndef STLSOFT_STRING_ACCESS_NO_STD_STRING
00668 # if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00669 _MSC_VER < 1100
00670
00671 inline ss_size_t c_str_size_a(string const &s)
00672 {
00673 return c_str_len(s) * sizeof(string::value_type);
00674 }
00675
00677 inline ss_size_t c_str_size(string const &s)
00678 {
00679 return c_str_size_a(s);
00680 }
00681
00683 inline ss_size_t c_str_size_w(wstring const &s)
00684 {
00685 return c_str_len(s) * sizeof(wstring::value_type);
00686 }
00687
00689 inline ss_size_t c_str_size(wstring const &s)
00690 {
00691 return c_str_size_w(s);
00692 }
00693 # else
00694
00695 inline ss_size_t c_str_size_a(stlsoft_ns_qual_std(string) const &s)
00696 {
00697 return c_str_len(s) * sizeof(ss_char_a_t);
00698 }
00699
00700 # if !defined(__STLSOFT_COMPILER_IS_GCC) || \
00701 !(__GNUC__ < 3)
00702
00703 inline ss_size_t c_str_size_w(_stlsoft_wstring_t const &s)
00704 {
00705 return c_str_len(s) * sizeof(ss_char_w_t);
00706 }
00707 # endif
00708
00710 template <class C>
00711 inline ss_size_t c_str_size(stlsoft_ns_qual_std(basic_string)<C> const &s)
00712 {
00713 return c_str_len(s) * sizeof(C);
00714 }
00715 # endif
00716 #endif
00717
00718
00720 #if defined(_STLP_USE_NAMESPACES) && \
00721 defined(_STLP_USE_OWN_NAMESPACE) && \
00722 !defined(_STLP_REDEFINE_STD)
00723 inline ss_size_t c_str_size_a(stlport::string const &s)
00724 {
00725 return c_str_len(s) * sizeof(ss_char_a_t);
00726 }
00727
00729 inline ss_size_t c_str_size_w(stlport::wstring const &s)
00730 {
00731 return c_str_len(s) * sizeof(ss_char_w_t);
00732 }
00733
00735 template <class C>
00736 inline ss_size_t c_str_size(stlport::basic_string<C> const &s)
00737 {
00738 return c_str_len(s) * sizeof(C);
00739 }
00740 #endif
00741
00743
00744
00745 #ifdef STLSOFT_UNITTEST
00746
00747 namespace unittest
00748 {
00749 ss_bool_t test_stlsoft_string_access(unittest_reporter *r)
00750 {
00751 ss_bool_t bSuccess = true;
00752
00753 unittest_initialiser init(r, "STLSoft", "string_access", __FILE__);
00754
00755 ss_char_a_t const *s1 = "String #1";
00756
00757 if(c_str_ptr(s1) != s1)
00758 {
00759 r->report("c_str_ptr(char*) failed ", __LINE__);
00760 bSuccess = false;
00761 }
00762
00763 ss_char_a_t const *s2 = c_str_ptr(static_cast<ss_char_a_t*>(NULL));
00764
00765 if(*s2 != '\0')
00766 {
00767 r->report("c_str_ptr(NULL) failed ", __LINE__);
00768 bSuccess = false;
00769 }
00770
00771 if(c_str_ptr_null(static_cast<ss_char_a_t*>(NULL)) != NULL)
00772 {
00773 r->report("c_str_ptr_null(NULL) failed ", __LINE__);
00774 bSuccess = false;
00775 }
00776
00777 return bSuccess;
00778 }
00779
00780 unittest_registrar unittest_stlsoft_string_access(test_stlsoft_string_access);
00781
00782 }
00783
00784 #endif
00785
00786
00787
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800