source: NonGTP/Boost/boost/regex/v4/regex_cstring.hpp @ 857

Revision 857, 2.5 KB checked in by igarcia, 19 years ago (diff)
Line 
1/*
2 *
3 * Copyright (c) 1998-2002
4 * John Maddock
5 *
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 *
10 */
11 
12 /*
13  *   LOCATION:    see http://www.boost.org for most recent version.
14  *   FILE         regex_cstring.hpp
15  *   VERSION      see <boost/version.hpp>
16  *   DESCRIPTION: This is an internal header file, do not include directly.
17  *                String support and helper functions, for regular
18  *                expression library.
19  */
20
21#ifndef BOOST_REGEX_CSTRING_HPP
22#define BOOST_REGEX_CSTRING_HPP
23
24#ifndef BOOST_REGEX_CONFIG_HPP
25#include <boost/regex/config.hpp>
26#endif
27
28#include <cstring>
29
30namespace boost{
31   namespace re_detail{
32
33//
34// start by defining some template function aliases for C API functions:
35//
36
37template <class charT>
38std::size_t BOOST_REGEX_CALL re_strlen(const charT *s)
39{
40   std::size_t len = 0;
41   while(*s)
42   {
43      ++s;
44      ++len;
45   }
46   return len;
47}
48
49inline std::size_t BOOST_REGEX_CALL re_strlen(const char *s)
50{
51   return std::strlen(s);
52}
53
54#ifndef BOOST_NO_WREGEX
55
56inline std::size_t BOOST_REGEX_CALL re_strlen(const wchar_t *s)
57{
58   return std::wcslen(s);
59}
60
61#endif
62
63#ifndef BOOST_NO_WREGEX
64BOOST_REGEX_DECL void BOOST_REGEX_CALL re_transform(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
65#endif
66BOOST_REGEX_DECL void BOOST_REGEX_CALL re_transform(std::string& out, const std::string& in);
67
68template <class charT>
69void BOOST_REGEX_CALL re_trunc_primary(std::basic_string<charT>& s)
70{
71   for(unsigned int i = 0; i < s.size(); ++i)
72   {
73      if(s[i] <= 1)
74      {
75         s.erase(i);
76         break;
77      }
78   }
79}
80
81inline char* BOOST_REGEX_CALL re_strcpy(char *s1, const char *s2)
82{
83   #if defined(__BORLANDC__) && defined(strcpy)
84   return ::strcpy(s1, s2);
85   #else
86   return std::strcpy(s1, s2);
87   #endif
88}
89
90#ifndef BOOST_NO_WREGEX
91
92inline wchar_t* BOOST_REGEX_CALL re_strcpy(wchar_t *s1, const wchar_t *s2)
93{
94   return std::wcscpy(s1, s2);
95}
96
97#endif
98
99
100template <class charT>
101charT* BOOST_REGEX_CALL re_strdup(const charT* p)
102{
103   charT* buf = new charT[re_strlen(p) + 1];
104   re_strcpy(buf, p);
105   return buf;
106}
107
108template <class charT>
109inline void BOOST_REGEX_CALL re_strfree(charT* p)
110{
111   delete[] p;
112}
113
114} // namespace re_detail
115} // namespace boost
116
117#endif  // BOOST_REGEX_CSTRING_HPP
118
119
120
121
122
123
Note: See TracBrowser for help on using the repository browser.