STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - Template Software for the Active Template Library COMSTL - The Standard Template Library meets the Component Object Model .netSTL - Standard Template Library meets the Microsoft.NET Common Language Runtime InetSTL - The Standard Template Library meets WinInet MFCSTL - Template Software for the Microsoft Foundation Classes UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

stlsoft_string_access.h

Go to the documentation of this file.
00001 /* 
00002  * File:        stlsoft_string_access.h
00003  *
00004  * Purpose:     Contains the c_str_ptr, c_str_ptr_null, c_str_len, and
00005  *              c_str_size accessors.
00006  *
00007  * Created:     16th January 2002
00008  * Updated:     11th September 2004
00009  *
00010  * Thanks to:   Robert Kreger for spotting a bug in the discrimination of wide
00011  *              character support on GCC 3.3.3.
00012  *
00013  * Home:        http://stlsoft.org/
00014  *
00015  * Copyright (c) 2002-2004, Matthew Wilson and Synesis Software
00016  * All rights reserved.
00017  *
00018  * Redistribution and use in source and binary forms, with or without
00019  * modification, are permitted provided that the following conditions are met:
00020  *
00021  * - Redistributions of source code must retain the above copyright notice, this
00022  *   list of conditions and the following disclaimer.
00023  * - Redistributions in binary form must reproduce the above copyright notice,
00024  *   this list of conditions and the following disclaimer in the documentation
00025  *   and/or other materials provided with the distribution.
00026  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00027  *   any contributors may be used to endorse or promote products derived from
00028  *   this software without specific prior written permission.
00029  *
00030  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00031  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00032  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00033  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00034  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00035  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00036  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00037  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00038  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00039  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00040  * POSSIBILITY OF SUCH DAMAGE.
00041  *
00042  * 
00043 
00044 
00048 
00049 #ifndef STLSOFT_INCL_H_STLSOFT_STRING_ACCESS
00050 #define STLSOFT_INCL_H_STLSOFT_STRING_ACCESS
00051 
00052 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define STLSOFT_VER_H_STLSOFT_STRING_ACCESS_MAJOR       2
00054 # define STLSOFT_VER_H_STLSOFT_STRING_ACCESS_MINOR       0
00055 # define STLSOFT_VER_H_STLSOFT_STRING_ACCESS_REVISION    1
00056 # define STLSOFT_VER_H_STLSOFT_STRING_ACCESS_EDIT        54
00057 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00058 
00059 /* 
00060  * Includes
00061  */
00062 
00063 #ifndef STLSOFT_INCL_H_STLSOFT
00064 # include "stlsoft.h"               // Include the STLSoft root header
00065 #endif /* !STLSOFT_INCL_H_STLSOFT */
00066 
00067 #ifdef __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits
00068 # undef __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits
00069 #endif /* __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits */
00070 
00071 /* No currently supported Watcom version can handle std::string. */
00072 #ifdef __STLSOFT_COMPILER_IS_WATCOM
00073 # define STLSOFT_STRING_ACCESS_NO_STD_STRING
00074 #endif /* __STLSOFT_COMPILER_IS_WATCOM */
00075 
00076 /* <string> is included for two reasons:
00077  *
00078  * (i) for std::string
00079  * (ii) for std::char_traits
00080  *
00081  * If STLSOFT_STRING_ACCESS_NO_STD_STRING is defined, then <string> is not
00082  * included, and __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits is not
00083  * defined.
00084  *
00085  * If _STLSOFT_NO_NAMESPACE is defined then
00086  * __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits is not defined.
00087  *
00088  * If __STLSOFT_CF_std_char_traits_AVAILABLE is not defined then
00089  * __STLSOFT_CF_STRING_ACCESS_USE_std_char_traits is not defined.
00090  *
00091  */
00092 
00093 #ifdef _STLSOFT_STRING_ACCESS_NO_STD_STRING
00094 # define STLSOFT_STRING_ACCESS_NO_STD_STRING
00095 #endif /* _STLSOFT_STRING_ACCESS_NO_STD_STRING */
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 /* Use char_traits? */
00106 
00107 /* Are we going to cater for std::(w)string? */
00108 #ifndef STLSOFT_STRING_ACCESS_NO_STD_STRING
00109 # include <string>                      // std::string classes
00110 #endif /* STLSOFT_STRING_ACCESS_NO_STD_STRING */
00111 
00112 /* Include stlsoft_char_traits if not using std::string, or std::char_traits
00113  * is not available.
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"      // stlsoft::char_traits
00118 # endif /* !STLSOFT_INCL_H_STLSOFT_CHAR_TRAITS */
00119 #endif /* !__STLSOFT_CF_STRING_ACCESS_USE_std_char_traits */
00120 
00121 #if defined(__STLSOFT_COMPILER_IS_GCC)
00122 # include <wchar.h>
00123 #endif /* __STLSOFT_COMPILER_IS_GCC */
00124 
00125 /* 
00126  * Pre-processor control
00127  *
00128  * By default, conversions from non-const strings, or rather from pointers to
00129  * non-const characters, are not allowed, since the implied semantics for a
00130  * pointer-to-const character representing a null-terminated string are stronger
00131  * than those for a pointer-to-non-const character.
00132  *
00133  * However, you can override this by defining the symbol
00134  * _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST, which will then treat both the types
00135  * (in fact all four types: char*; char const*; wchar_t*; wchar_t const*) as
00136  * representing null-terminated strings.
00137  */
00138 
00139 /* 
00140  * Namespace
00141  */
00142 
00143 #ifndef _STLSOFT_NO_NAMESPACE
00144 namespace stlsoft
00145 {
00146 #endif /* _STLSOFT_NO_NAMESPACE */
00147 
00148 /* 
00149 
00151 
00154 
00158 
00163 
00164 /* 
00165  * Typedefs
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 /* TODO: This is probably not needed now, so may remove it in a future version ... */ || \
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 /* __STLSOFT_COMPILER_IS_GCC) && __GNUC__ < 3 */
00178 #endif /* STLSOFT_STRING_ACCESS_NO_STD_STRING */
00179 
00180 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00181 
00182 /* 
00183  * c_str_ptr_null
00184  *
00185  * This can be applied to an expression, and the return value is either a
00186  * pointer to the character string or NULL.
00187  */
00188 
00189 /* C-style ANSI string */
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 /* C-style Unicode string */
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 /* C-style ANSI string */
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 /* C-style Unicode string */
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 /* _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST */
00242 
00243 /* std::basic_string */
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 /* !__STLSOFT_COMPILER_IS_GCC || !(__GNUC__ < 3) */
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 /* __STLSOFT_COMPILER_IS_MSVC && _MSC_VER < 1100 */
00294 #endif /* STLSOFT_STRING_ACCESS_NO_STD_STRING */
00295 
00296 /* stlport::basic_string */
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 /* _STLP_USE_NAMESPACES && _STLP_USE_OWN_NAMESPACE */
00319 
00320 /* 
00321  * c_str_ptr
00322  *
00323  * This can be applied to an expression, and the return value is either a
00324  * pointer to the character string or to an empty string.
00325  */
00326 
00327 /* C-style ANSI string */
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 /* C-style Unicode string */
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 /* C-style ANSI string */
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 /* C-style Unicode string */
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 /* _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST */
00380 
00381 /* std::basic_string */
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 /* !__STLSOFT_COMPILER_IS_GCC || !(__GNUC__ < 3) */
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 /* __STLSOFT_COMPILER_IS_MSVC && _MSC_VER < 1100 */
00431 #endif /* STLSOFT_STRING_ACCESS_NO_STD_STRING */
00432 
00433 /* stlport::basic_string */
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 /* _STLP_USE_NAMESPACES && _STLP_USE_OWN_NAMESPACE */
00456 
00457 /* 
00458  * c_str_len
00459  *
00460  * This can be applied to an expression, and the return value is the number of
00461  * characters in the character string in the expression.
00462  */
00463 
00464 /* C-style ANSI string */
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 /* !__STLSOFT_CF_std_char_traits_AVAILABLE */
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 /* C-style Unicode string */
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 /* !__STLSOFT_CF_STRING_ACCESS_USE_std_char_traits */
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 /* C-style ANSI string */
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 /* C-style Unicode string */
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 /* _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST */
00527 
00528 /* std::basic_string */
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 /* !__STLSOFT_COMPILER_IS_GCC || !(__GNUC__ < 3) */
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 /* __STLSOFT_COMPILER_IS_MSVC && _MSC_VER < 1100 */
00578 #endif /* STLSOFT_STRING_ACCESS_NO_STD_STRING */
00579 
00580 /* stlport::basic_string */
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 /* _STLP_USE_NAMESPACES && _STLP_USE_OWN_NAMESPACE */
00603 
00604 /* 
00605  * c_str_size
00606  *
00607  * This can be applied to an expression, and the return value is the number of
00608  * bytes required to store the character string in the expression, NOT including
00609  * the null-terminating character.
00610  */
00611 
00612 /* C-style ANSI string */
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 /* C-style Unicode string */
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 /* C-style ANSI string */
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 /* C-style Unicode string */
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 /* _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST */
00665 
00666 /* std::basic_string */
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 /* !__STLSOFT_COMPILER_IS_GCC || !(__GNUC__ < 3) */
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 /* __STLSOFT_COMPILER_IS_MSVC && _MSC_VER < 1100 */
00716 #endif /* STLSOFT_STRING_ACCESS_NO_STD_STRING */
00717 
00718 /* stlport::basic_string */
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 /* _STLP_USE_NAMESPACES && _STLP_USE_OWN_NAMESPACE */
00741 
00743 // Unit-testing
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 } // namespace unittest
00783 
00784 #endif /* STLSOFT_UNITTEST */
00785 
00786 /* 
00787 
00789 
00790 /* 
00791 
00792 #ifndef _STLSOFT_NO_NAMESPACE
00793 } // namespace stlsoft
00794 #endif /* _STLSOFT_NO_NAMESPACE */
00795 
00796 /* 
00797 
00798 #endif /* !STLSOFT_INCL_H_STLSOFT_STRING_ACCESS */
00799 
00800 /* 

STLSoft Libraries documentation © Synesis Software Pty Ltd, 2001-2004