You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
7.7 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: dotnetstl/shims/access/string/string.hpp
  3. *
  4. * Purpose: String access shims for .net.
  5. *
  6. * Created: 24th June 2003
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2003-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file dotnetstl/shims/access/string/string.hpp
  40. *
  41. * \brief [C++] Definition of the string access shims for
  42. * <code>System::String</code>
  43. * (\ref group__concept__shim__string_access "String Access Shims" Concept).
  44. */
  45. #ifndef DOTNETSTL_INCL_DOTNETSTL_SHIMS_ACCESS_STRING_HPP_STRING
  46. #define DOTNETSTL_INCL_DOTNETSTL_SHIMS_ACCESS_STRING_HPP_STRING
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define DOTNETSTL_VER_DOTNETSTL_SHIMS_ACCESS_STRING_HPP_STRING_MAJOR 2
  49. # define DOTNETSTL_VER_DOTNETSTL_SHIMS_ACCESS_STRING_HPP_STRING_MINOR 0
  50. # define DOTNETSTL_VER_DOTNETSTL_SHIMS_ACCESS_STRING_HPP_STRING_REVISION 4
  51. # define DOTNETSTL_VER_DOTNETSTL_SHIMS_ACCESS_STRING_HPP_STRING_EDIT 20
  52. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Includes
  55. */
  56. #ifndef DOTNETSTL_INCL_DOTNETSTL_HPP_DOTNETSTL
  57. # include <dotnetstl/dotnetstl.hpp>
  58. #endif /* !DOTNETSTL_INCL_DOTNETSTL_HPP_DOTNETSTL */
  59. #ifndef DOTNETSTL_INCL_DOTNETSTL_STRING_HPP_STRING_ACCESSOR
  60. # include <dotnetstl/string/string_accessor.hpp>
  61. #endif /* !DOTNETSTL_INCL_DOTNETSTL_STRING_HPP_STRING_ACCESSOR */
  62. #ifndef STLSOFT_INCL_H_STRING
  63. # define STLSOFT_INCL_H_STRING
  64. # include <string.h>
  65. #endif /* !STLSOFT_INCL_H_STRING */
  66. /* ////////////////////////////////////////////////////////////////////// */
  67. #ifdef _STLSOFT_NO_NAMESPACE
  68. /* There is no stlsoft namespace, so must define ::dotnetstl */
  69. namespace dotnetstl
  70. {
  71. #else
  72. /* Define stlsoft::dotnet_project */
  73. namespace stlsoft
  74. {
  75. namespace dotnetstl_project
  76. {
  77. #endif /* _STLSOFT_NO_NAMESPACE */
  78. /* /////////////////////////////////////////////////////////////////////////
  79. * Functions
  80. */
  81. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  82. namespace impl
  83. {
  84. typedef c_string_accessor<char> accessor_a_t;
  85. typedef c_string_accessor<wchar_t> accessor_w_t;
  86. #ifdef UNICODE
  87. typedef accessor_w_t accessor_t_t;
  88. #else /* ? UNICODE */
  89. typedef accessor_a_t accessor_t_t;
  90. #endif /* UNICODE */
  91. #if defined(DOTNETSTL_HAT_SYNTAX_SUPPORT)
  92. typedef System::String const ^string_pointer_const_type;
  93. typedef System::String ^string_pointer_type;
  94. #else /* DOTNETSTL_HAT_SYNTAX_SUPPORT */
  95. typedef System::String const* string_pointer_const_type;
  96. typedef System::String* string_pointer_type;
  97. #endif /* DOTNETSTL_HAT_SYNTAX_SUPPORT */
  98. } // namespace impl
  99. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  100. // c_str_data
  101. inline impl::accessor_a_t c_str_data_a(impl::string_pointer_const_type s)
  102. {
  103. return impl::accessor_a_t(s);
  104. }
  105. inline impl::accessor_w_t c_str_data_w(impl::string_pointer_const_type s)
  106. {
  107. return impl::accessor_w_t(s);
  108. }
  109. inline impl::accessor_t_t c_str_data(impl::string_pointer_const_type s)
  110. {
  111. return impl::accessor_t_t(s);
  112. }
  113. inline ds_size_t c_str_len_a(impl::string_pointer_const_type s)
  114. {
  115. return ::strlen(c_str_data_a(s));
  116. }
  117. inline ds_size_t c_str_len_w(impl::string_pointer_const_type s)
  118. {
  119. #if defined(DOTNETSTL_HAT_SYNTAX_SUPPORT)
  120. if(nullptr == s)
  121. #else /* DOTNETSTL_HAT_SYNTAX_SUPPORT */
  122. if(NULL == s)
  123. #endif /* DOTNETSTL_HAT_SYNTAX_SUPPORT */
  124. {
  125. return 0;
  126. }
  127. else
  128. {
  129. impl::string_pointer_type s_ = const_cast<impl::string_pointer_type>(s);
  130. #if defined(DOTNETSTL_HAT_SYNTAX_SUPPORT)
  131. return static_cast<ds_size_t>(s_->Length);
  132. #else /* DOTNETSTL_HAT_SYNTAX_SUPPORT */
  133. return static_cast<ds_size_t>(s_->get_Length());
  134. #endif /* DOTNETSTL_HAT_SYNTAX_SUPPORT */
  135. }
  136. }
  137. inline ds_size_t c_str_len(impl::string_pointer_const_type s)
  138. {
  139. return c_str_len_w(s);
  140. }
  141. inline impl::accessor_a_t c_str_ptr_a(impl::string_pointer_const_type s)
  142. {
  143. return impl::accessor_a_t(s);
  144. }
  145. inline impl::accessor_w_t c_str_ptr_w(impl::string_pointer_const_type s)
  146. {
  147. return impl::accessor_w_t(s);
  148. }
  149. inline impl::accessor_t_t c_str_ptr(impl::string_pointer_const_type s)
  150. {
  151. return impl::accessor_t_t(s);
  152. }
  153. ////////////////////////////////////////////////////////////////////////////
  154. // Unit-testing
  155. #ifdef STLSOFT_UNITTEST
  156. # include "./unittest/string_unittest_.h"
  157. #endif /* STLSOFT_UNITTEST */
  158. /* ////////////////////////////////////////////////////////////////////// */
  159. #ifdef _STLSOFT_NO_NAMESPACE
  160. } // namespace dotnetstl
  161. #else
  162. } // namespace dotnetstl_project
  163. } // namespace stlsoft
  164. #endif /* _STLSOFT_NO_NAMESPACE */
  165. /* /////////////////////////////////////////////////////////////////////////
  166. * Namespace
  167. *
  168. * The string access shims exist either in the stlsoft namespace, or in the
  169. * global namespace. This is required by the lookup rules.
  170. */
  171. #ifndef _DOTNETSTL_NO_NAMESPACE
  172. # if !defined(_STLSOFT_NO_NAMESPACE) && \
  173. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  174. namespace stlsoft
  175. {
  176. # else /* ? _STLSOFT_NO_NAMESPACE */
  177. /* There is no stlsoft namespace, so must define in the global namespace */
  178. # endif /* !_STLSOFT_NO_NAMESPACE */
  179. using ::dotnetstl::c_str_data;
  180. using ::dotnetstl::c_str_data_a;
  181. using ::dotnetstl::c_str_data_w;
  182. using ::dotnetstl::c_str_len;
  183. using ::dotnetstl::c_str_len_a;
  184. using ::dotnetstl::c_str_len_w;
  185. using ::dotnetstl::c_str_ptr;
  186. using ::dotnetstl::c_str_ptr_a;
  187. using ::dotnetstl::c_str_ptr_w;
  188. #if 0
  189. using ::dotnetstl::c_str_ptr_null;
  190. using ::dotnetstl::c_str_ptr_null_a;
  191. using ::dotnetstl::c_str_ptr_null_w;
  192. #endif /* 0 */
  193. # if !defined(_STLSOFT_NO_NAMESPACE) && \
  194. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  195. } // namespace stlsoft
  196. # else /* ? _STLSOFT_NO_NAMESPACE */
  197. /* There is no stlsoft namespace, so must define in the global namespace */
  198. # endif /* !_STLSOFT_NO_NAMESPACE */
  199. #endif /* !_DOTNETSTL_NO_NAMESPACE */
  200. /* ////////////////////////////////////////////////////////////////////// */
  201. #endif /* DOTNETSTL_INCL_DOTNETSTL_SHIMS_ACCESS_STRING_HPP_STRING */
  202. /* ///////////////////////////// end of file //////////////////////////// */