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.

167 lines
5.6 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/string/case_functions.hpp
  3. *
  4. * Purpose: String utility functions for manipulating case.
  5. *
  6. * Created: 1st April 2005
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2005-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 stlsoft/string/case_functions.hpp
  40. *
  41. * \brief [C++ only] String utility functions for manipulating case
  42. * (\ref group__library__string "String" Library).
  43. */
  44. #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CASE_FUNCTIONS
  45. #define STLSOFT_INCL_STLSOFT_STRING_HPP_CASE_FUNCTIONS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_CASE_FUNCTIONS_MAJOR 2
  48. # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_CASE_FUNCTIONS_MINOR 0
  49. # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_CASE_FUNCTIONS_REVISION 2
  50. # define STLSOFT_VER_INCL_STLSOFT_STRING_HPP_CASE_FUNCTIONS_EDIT 18
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  56. # include <stlsoft/stlsoft.h>
  57. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  58. #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CTYPE_TRAITS
  59. # include <stlsoft/string/ctype_traits.hpp>
  60. #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_CTYPE_TRAITS */
  61. #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS
  62. # include <stlsoft/string/string_traits.hpp>
  63. #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS */
  64. #ifndef STLSOFT_INCL_STLSOFT_ALGORITHM_STD_HPP_ALT
  65. # include <stlsoft/algorithms/std/alt.hpp>
  66. #endif /* !STLSOFT_INCL_STLSOFT_ALGORITHM_STD_HPP_ALT */
  67. /* /////////////////////////////////////////////////////////////////////////
  68. * Namespace
  69. */
  70. #ifndef _STLSOFT_NO_NAMESPACE
  71. namespace stlsoft
  72. {
  73. #endif /* _STLSOFT_NO_NAMESPACE */
  74. /* ////////////////////////////////////////////////////////////////////// */
  75. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  76. template< ss_typename_param_k S
  77. , ss_typename_param_k F
  78. >
  79. inline S& transform_impl(S& s, F f)
  80. {
  81. std_transform(s.begin(), s.end(), s.begin(), f);
  82. return s;
  83. }
  84. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  85. /** \brief Converts all characters in the string to upper case.
  86. *
  87. * \ingroup group__library__string
  88. */
  89. template <ss_typename_param_k S>
  90. inline S& make_upper(S& s)
  91. {
  92. typedef string_traits<S> string_traits_t;
  93. typedef ss_typename_type_k string_traits_t::char_type char_t;
  94. typedef ctype_traits<char_t> ctype_traits_t;
  95. return transform_impl(s, &ctype_traits_t::to_upper);
  96. }
  97. /** \brief Converts all characters in the string to lower case.
  98. *
  99. * \ingroup group__library__string
  100. */
  101. template <ss_typename_param_k S>
  102. inline S& make_lower(S& s)
  103. {
  104. typedef string_traits<S> string_traits_t;
  105. typedef ss_typename_type_k string_traits_t::char_type char_t;
  106. typedef ctype_traits<char_t> ctype_traits_t;
  107. return transform_impl(s, &ctype_traits_t::to_lower);
  108. }
  109. /** \brief Returns a copy of the source string in which all characters have
  110. * been converted to upper case.
  111. *
  112. * \ingroup group__library__string
  113. */
  114. template <ss_typename_param_k S>
  115. inline S to_upper(S const& s)
  116. {
  117. S r(s);
  118. make_upper(r);
  119. return r;
  120. }
  121. /** \brief Returns a copy of the source string in which all characters have
  122. * been converted to lower case.
  123. *
  124. * \ingroup group__library__string
  125. */
  126. template <ss_typename_param_k S>
  127. inline S to_lower(S const& s)
  128. {
  129. S r(s);
  130. make_lower(r);
  131. return r;
  132. }
  133. /* ////////////////////////////////////////////////////////////////////// */
  134. #ifndef _STLSOFT_NO_NAMESPACE
  135. } // namespace stlsoft
  136. #endif /* _STLSOFT_NO_NAMESPACE */
  137. /* ////////////////////////////////////////////////////////////////////// */
  138. #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_CASE_FUNCTIONS */
  139. /* ///////////////////////////// end of file //////////////////////////// */