passenger 4.0.27 → 4.0.28

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (156) hide show
  1. data.tar.gz.asc +7 -7
  2. data/.gitignore +1 -0
  3. data/NEWS +22 -0
  4. data/build/preprocessor.rb +10 -0
  5. data/build/rpm.rb +74 -65
  6. data/debian.template/rules.template +8 -0
  7. data/dev/copy_boost_headers.rb +11 -2
  8. data/doc/Users guide Apache.idmap.txt +161 -145
  9. data/doc/Users guide Apache.txt +12 -1
  10. data/doc/Users guide Nginx.idmap.txt +142 -126
  11. data/doc/Users guide Nginx.txt +14 -1
  12. data/doc/Users guide Standalone.txt +1 -0
  13. data/doc/users_guide_snippets/environment_variables.txt +1 -1
  14. data/doc/users_guide_snippets/installation.txt +2 -0
  15. data/doc/users_guide_snippets/tips.txt +118 -0
  16. data/ext/apache2/Configuration.cpp +0 -6
  17. data/ext/apache2/Configuration.hpp +0 -5
  18. data/ext/apache2/ConfigurationCommands.cpp +7 -0
  19. data/ext/apache2/ConfigurationFields.hpp +2 -0
  20. data/ext/apache2/ConfigurationSetters.cpp +24 -0
  21. data/ext/apache2/CreateDirConfig.cpp +1 -0
  22. data/ext/apache2/Hooks.cpp +0 -1
  23. data/ext/apache2/MergeDirConfig.cpp +7 -0
  24. data/ext/apache2/SetHeaders.cpp +5 -1
  25. data/ext/boost/cregex.hpp +39 -0
  26. data/ext/boost/libs/regex/src/c_regex_traits.cpp +193 -0
  27. data/ext/boost/libs/regex/src/cpp_regex_traits.cpp +117 -0
  28. data/ext/boost/libs/regex/src/cregex.cpp +660 -0
  29. data/ext/boost/libs/regex/src/instances.cpp +32 -0
  30. data/ext/boost/libs/regex/src/internals.hpp +35 -0
  31. data/ext/boost/libs/regex/src/posix_api.cpp +296 -0
  32. data/ext/boost/libs/regex/src/regex.cpp +227 -0
  33. data/ext/boost/libs/regex/src/regex_debug.cpp +59 -0
  34. data/ext/boost/libs/regex/src/regex_raw_buffer.cpp +72 -0
  35. data/ext/boost/libs/regex/src/regex_traits_defaults.cpp +692 -0
  36. data/ext/boost/libs/regex/src/static_mutex.cpp +179 -0
  37. data/ext/boost/libs/regex/src/wc_regex_traits.cpp +301 -0
  38. data/ext/boost/libs/regex/src/wide_posix_api.cpp +315 -0
  39. data/ext/boost/libs/regex/src/winstances.cpp +35 -0
  40. data/ext/boost/regex.h +100 -0
  41. data/ext/boost/regex.hpp +37 -0
  42. data/ext/boost/regex/concepts.hpp +1128 -0
  43. data/ext/boost/regex/config.hpp +435 -0
  44. data/ext/boost/regex/config/borland.hpp +72 -0
  45. data/ext/boost/regex/config/cwchar.hpp +207 -0
  46. data/ext/boost/regex/mfc.hpp +190 -0
  47. data/ext/boost/regex/pattern_except.hpp +100 -0
  48. data/ext/boost/regex/pending/object_cache.hpp +165 -0
  49. data/ext/boost/regex/pending/static_mutex.hpp +179 -0
  50. data/ext/boost/regex/pending/unicode_iterator.hpp +776 -0
  51. data/ext/boost/regex/regex_traits.hpp +35 -0
  52. data/ext/boost/regex/user.hpp +93 -0
  53. data/ext/boost/regex/v4/basic_regex.hpp +782 -0
  54. data/ext/boost/regex/v4/basic_regex_creator.hpp +1571 -0
  55. data/ext/boost/regex/v4/basic_regex_parser.hpp +2874 -0
  56. data/ext/boost/regex/v4/c_regex_traits.hpp +211 -0
  57. data/ext/boost/regex/v4/char_regex_traits.hpp +81 -0
  58. data/ext/boost/regex/v4/cpp_regex_traits.hpp +1099 -0
  59. data/ext/boost/regex/v4/cregex.hpp +330 -0
  60. data/ext/boost/regex/v4/error_type.hpp +59 -0
  61. data/ext/boost/regex/v4/fileiter.hpp +455 -0
  62. data/ext/boost/regex/v4/instances.hpp +222 -0
  63. data/ext/boost/regex/v4/iterator_category.hpp +91 -0
  64. data/ext/boost/regex/v4/iterator_traits.hpp +135 -0
  65. data/ext/boost/regex/v4/match_flags.hpp +138 -0
  66. data/ext/boost/regex/v4/match_results.hpp +702 -0
  67. data/ext/boost/regex/v4/mem_block_cache.hpp +99 -0
  68. data/ext/boost/regex/v4/perl_matcher.hpp +587 -0
  69. data/ext/boost/regex/v4/perl_matcher_common.hpp +996 -0
  70. data/ext/boost/regex/v4/perl_matcher_non_recursive.hpp +1642 -0
  71. data/ext/boost/regex/v4/perl_matcher_recursive.hpp +991 -0
  72. data/ext/boost/regex/v4/primary_transform.hpp +146 -0
  73. data/ext/boost/regex/v4/protected_call.hpp +81 -0
  74. data/ext/boost/regex/v4/regbase.hpp +180 -0
  75. data/ext/boost/regex/v4/regex.hpp +202 -0
  76. data/ext/boost/regex/v4/regex_format.hpp +1156 -0
  77. data/ext/boost/regex/v4/regex_fwd.hpp +73 -0
  78. data/ext/boost/regex/v4/regex_grep.hpp +155 -0
  79. data/ext/boost/regex/v4/regex_iterator.hpp +201 -0
  80. data/ext/boost/regex/v4/regex_match.hpp +382 -0
  81. data/ext/boost/regex/v4/regex_merge.hpp +93 -0
  82. data/ext/boost/regex/v4/regex_raw_buffer.hpp +210 -0
  83. data/ext/boost/regex/v4/regex_replace.hpp +99 -0
  84. data/ext/boost/regex/v4/regex_search.hpp +217 -0
  85. data/ext/boost/regex/v4/regex_split.hpp +172 -0
  86. data/ext/boost/regex/v4/regex_token_iterator.hpp +342 -0
  87. data/ext/boost/regex/v4/regex_traits.hpp +189 -0
  88. data/ext/boost/regex/v4/regex_traits_defaults.hpp +371 -0
  89. data/ext/boost/regex/v4/regex_workaround.hpp +232 -0
  90. data/ext/boost/regex/v4/states.hpp +301 -0
  91. data/ext/boost/regex/v4/sub_match.hpp +512 -0
  92. data/ext/boost/regex/v4/syntax_type.hpp +105 -0
  93. data/ext/boost/regex/v4/u32regex_iterator.hpp +193 -0
  94. data/ext/boost/regex/v4/u32regex_token_iterator.hpp +377 -0
  95. data/ext/boost/regex/v4/w32_regex_traits.hpp +741 -0
  96. data/ext/boost/regex_fwd.hpp +33 -0
  97. data/ext/common/AgentsStarter.h +0 -11
  98. data/ext/common/ApplicationPool2/Common.h +1 -7
  99. data/ext/common/ApplicationPool2/DirectSpawner.h +3 -3
  100. data/ext/common/ApplicationPool2/Group.h +166 -69
  101. data/ext/common/ApplicationPool2/Implementation.cpp +55 -10
  102. data/ext/common/ApplicationPool2/Options.h +45 -10
  103. data/ext/common/ApplicationPool2/PipeWatcher.h +1 -2
  104. data/ext/common/ApplicationPool2/Pool.h +29 -7
  105. data/ext/common/ApplicationPool2/Process.h +22 -3
  106. data/ext/common/ApplicationPool2/Session.h +1 -0
  107. data/ext/common/ApplicationPool2/SmartSpawner.h +5 -10
  108. data/ext/common/ApplicationPool2/Spawner.h +10 -15
  109. data/ext/common/ApplicationPool2/SuperGroup.h +10 -9
  110. data/ext/common/Constants.h +1 -3
  111. data/ext/common/Hooks.h +193 -0
  112. data/ext/common/Logging.cpp +67 -2
  113. data/ext/common/Logging.h +23 -1
  114. data/ext/common/Utils.cpp +0 -21
  115. data/ext/common/Utils.h +0 -42
  116. data/ext/common/Utils/CachedFileStat.hpp +1 -1
  117. data/ext/common/Utils/StrIntUtils.h +61 -14
  118. data/ext/common/Utils/StringMap.h +4 -0
  119. data/ext/common/agents/HelperAgent/AgentOptions.h +4 -4
  120. data/ext/common/agents/HelperAgent/Main.cpp +2 -3
  121. data/ext/common/agents/HelperAgent/RequestHandler.h +65 -2
  122. data/ext/common/agents/LoggingAgent/FilterSupport.h +3 -1
  123. data/ext/common/agents/Watchdog/Main.cpp +8 -72
  124. data/ext/nginx/CacheLocationConfig.c +29 -1
  125. data/ext/nginx/Configuration.c +0 -12
  126. data/ext/nginx/Configuration.h +0 -1
  127. data/ext/nginx/ConfigurationCommands.c +10 -0
  128. data/ext/nginx/ConfigurationFields.h +2 -0
  129. data/ext/nginx/CreateLocationConfig.c +4 -0
  130. data/ext/nginx/MergeLocationConfig.c +6 -0
  131. data/ext/oxt/system_calls.cpp +7 -1
  132. data/ext/oxt/system_calls.hpp +7 -7
  133. data/helper-scripts/node-loader.js +6 -2
  134. data/helper-scripts/rack-loader.rb +5 -2
  135. data/helper-scripts/rack-preloader.rb +5 -2
  136. data/lib/phusion_passenger.rb +1 -1
  137. data/lib/phusion_passenger/apache2/config_options.rb +8 -0
  138. data/lib/phusion_passenger/constants.rb +0 -1
  139. data/lib/phusion_passenger/nginx/config_options.rb +9 -2
  140. data/lib/phusion_passenger/platform_info/apache.rb +2 -1
  141. data/lib/phusion_passenger/platform_info/compiler.rb +15 -1
  142. data/lib/phusion_passenger/platform_info/cxx_portability.rb +2 -0
  143. data/node_lib/phusion_passenger/httplib_emulation.js +85 -17
  144. data/node_lib/phusion_passenger/request_handler.js +10 -2
  145. data/rpm/Vagrantfile +32 -0
  146. data/rpm/get_distro_id.py +4 -0
  147. data/test/cxx/ApplicationPool2/DirectSpawnerTest.cpp +2 -2
  148. data/test/cxx/ApplicationPool2/PoolTest.cpp +60 -9
  149. data/test/cxx/ApplicationPool2/SmartSpawnerTest.cpp +2 -6
  150. data/test/cxx/CachedFileStatTest.cpp +5 -5
  151. data/test/cxx/RequestHandlerTest.cpp +3 -6
  152. data/test/cxx/UtilsTest.cpp +30 -0
  153. data/test/node/httplib_emulation_spec.js +491 -0
  154. data/test/node/spec_helper.js +25 -0
  155. metadata +78 -2
  156. metadata.gz.asc +7 -7
@@ -0,0 +1,105 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2003
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 syntax_type.hpp
15
+ * VERSION see <boost/version.hpp>
16
+ * DESCRIPTION: Declares regular expression synatx type enumerator.
17
+ */
18
+
19
+ #ifndef BOOST_REGEX_SYNTAX_TYPE_HPP
20
+ #define BOOST_REGEX_SYNTAX_TYPE_HPP
21
+
22
+ namespace boost{
23
+ namespace regex_constants{
24
+
25
+ typedef unsigned char syntax_type;
26
+
27
+ //
28
+ // values chosen are binary compatible with previous version:
29
+ //
30
+ static const syntax_type syntax_char = 0;
31
+ static const syntax_type syntax_open_mark = 1;
32
+ static const syntax_type syntax_close_mark = 2;
33
+ static const syntax_type syntax_dollar = 3;
34
+ static const syntax_type syntax_caret = 4;
35
+ static const syntax_type syntax_dot = 5;
36
+ static const syntax_type syntax_star = 6;
37
+ static const syntax_type syntax_plus = 7;
38
+ static const syntax_type syntax_question = 8;
39
+ static const syntax_type syntax_open_set = 9;
40
+ static const syntax_type syntax_close_set = 10;
41
+ static const syntax_type syntax_or = 11;
42
+ static const syntax_type syntax_escape = 12;
43
+ static const syntax_type syntax_dash = 14;
44
+ static const syntax_type syntax_open_brace = 15;
45
+ static const syntax_type syntax_close_brace = 16;
46
+ static const syntax_type syntax_digit = 17;
47
+ static const syntax_type syntax_comma = 27;
48
+ static const syntax_type syntax_equal = 37;
49
+ static const syntax_type syntax_colon = 36;
50
+ static const syntax_type syntax_not = 53;
51
+
52
+ // extensions:
53
+
54
+ static const syntax_type syntax_hash = 13;
55
+ static const syntax_type syntax_newline = 26;
56
+
57
+ // escapes:
58
+
59
+ typedef syntax_type escape_syntax_type;
60
+
61
+ static const escape_syntax_type escape_type_word_assert = 18;
62
+ static const escape_syntax_type escape_type_not_word_assert = 19;
63
+ static const escape_syntax_type escape_type_control_f = 29;
64
+ static const escape_syntax_type escape_type_control_n = 30;
65
+ static const escape_syntax_type escape_type_control_r = 31;
66
+ static const escape_syntax_type escape_type_control_t = 32;
67
+ static const escape_syntax_type escape_type_control_v = 33;
68
+ static const escape_syntax_type escape_type_ascii_control = 35;
69
+ static const escape_syntax_type escape_type_hex = 34;
70
+ static const escape_syntax_type escape_type_unicode = 0; // not used
71
+ static const escape_syntax_type escape_type_identity = 0; // not used
72
+ static const escape_syntax_type escape_type_backref = syntax_digit;
73
+ static const escape_syntax_type escape_type_decimal = syntax_digit; // not used
74
+ static const escape_syntax_type escape_type_class = 22;
75
+ static const escape_syntax_type escape_type_not_class = 23;
76
+
77
+ // extensions:
78
+
79
+ static const escape_syntax_type escape_type_left_word = 20;
80
+ static const escape_syntax_type escape_type_right_word = 21;
81
+ static const escape_syntax_type escape_type_start_buffer = 24; // for \`
82
+ static const escape_syntax_type escape_type_end_buffer = 25; // for \'
83
+ static const escape_syntax_type escape_type_control_a = 28; // for \a
84
+ static const escape_syntax_type escape_type_e = 38; // for \e
85
+ static const escape_syntax_type escape_type_E = 47; // for \Q\E
86
+ static const escape_syntax_type escape_type_Q = 48; // for \Q\E
87
+ static const escape_syntax_type escape_type_X = 49; // for \X
88
+ static const escape_syntax_type escape_type_C = 50; // for \C
89
+ static const escape_syntax_type escape_type_Z = 51; // for \Z
90
+ static const escape_syntax_type escape_type_G = 52; // for \G
91
+
92
+ static const escape_syntax_type escape_type_property = 54; // for \p
93
+ static const escape_syntax_type escape_type_not_property = 55; // for \P
94
+ static const escape_syntax_type escape_type_named_char = 56; // for \N
95
+ static const escape_syntax_type escape_type_extended_backref = 57; // for \g
96
+ static const escape_syntax_type escape_type_reset_start_mark = 58; // for \K
97
+ static const escape_syntax_type escape_type_line_ending = 59; // for \R
98
+
99
+ static const escape_syntax_type syntax_max = 60;
100
+
101
+ }
102
+ }
103
+
104
+
105
+ #endif
@@ -0,0 +1,193 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2003
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 u32regex_iterator.hpp
15
+ * VERSION see <boost/version.hpp>
16
+ * DESCRIPTION: Provides u32regex_iterator implementation.
17
+ */
18
+
19
+ #ifndef BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
20
+ #define BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
21
+
22
+ namespace boost{
23
+
24
+ #ifdef BOOST_HAS_ABI_HEADERS
25
+ # include BOOST_ABI_PREFIX
26
+ #endif
27
+
28
+ template <class BidirectionalIterator>
29
+ class u32regex_iterator_implementation
30
+ {
31
+ typedef u32regex regex_type;
32
+
33
+ match_results<BidirectionalIterator> what; // current match
34
+ BidirectionalIterator base; // start of sequence
35
+ BidirectionalIterator end; // end of sequence
36
+ const regex_type re; // the expression
37
+ match_flag_type flags; // flags for matching
38
+
39
+ public:
40
+ u32regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
41
+ : base(), end(last), re(*p), flags(f){}
42
+ bool init(BidirectionalIterator first)
43
+ {
44
+ base = first;
45
+ return u32regex_search(first, end, what, re, flags, base);
46
+ }
47
+ bool compare(const u32regex_iterator_implementation& that)
48
+ {
49
+ if(this == &that) return true;
50
+ return (&re.get_data() == &that.re.get_data()) && (end == that.end) && (flags == that.flags) && (what[0].first == that.what[0].first) && (what[0].second == that.what[0].second);
51
+ }
52
+ const match_results<BidirectionalIterator>& get()
53
+ { return what; }
54
+ bool next()
55
+ {
56
+ //if(what.prefix().first != what[0].second)
57
+ // flags |= match_prev_avail;
58
+ BidirectionalIterator next_start = what[0].second;
59
+ match_flag_type f(flags);
60
+ if(!what.length())
61
+ f |= regex_constants::match_not_initial_null;
62
+ //if(base != next_start)
63
+ // f |= regex_constants::match_not_bob;
64
+ bool result = u32regex_search(next_start, end, what, re, f, base);
65
+ if(result)
66
+ what.set_base(base);
67
+ return result;
68
+ }
69
+ private:
70
+ u32regex_iterator_implementation& operator=(const u32regex_iterator_implementation&);
71
+ };
72
+
73
+ template <class BidirectionalIterator>
74
+ class u32regex_iterator
75
+ #ifndef BOOST_NO_STD_ITERATOR
76
+ : public std::iterator<
77
+ std::forward_iterator_tag,
78
+ match_results<BidirectionalIterator>,
79
+ typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type,
80
+ const match_results<BidirectionalIterator>*,
81
+ const match_results<BidirectionalIterator>& >
82
+ #endif
83
+ {
84
+ private:
85
+ typedef u32regex_iterator_implementation<BidirectionalIterator> impl;
86
+ typedef shared_ptr<impl> pimpl;
87
+ public:
88
+ typedef u32regex regex_type;
89
+ typedef match_results<BidirectionalIterator> value_type;
90
+ typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
91
+ difference_type;
92
+ typedef const value_type* pointer;
93
+ typedef const value_type& reference;
94
+ typedef std::forward_iterator_tag iterator_category;
95
+
96
+ u32regex_iterator(){}
97
+ u32regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
98
+ const regex_type& re,
99
+ match_flag_type m = match_default)
100
+ : pdata(new impl(&re, b, m))
101
+ {
102
+ if(!pdata->init(a))
103
+ {
104
+ pdata.reset();
105
+ }
106
+ }
107
+ u32regex_iterator(const u32regex_iterator& that)
108
+ : pdata(that.pdata) {}
109
+ u32regex_iterator& operator=(const u32regex_iterator& that)
110
+ {
111
+ pdata = that.pdata;
112
+ return *this;
113
+ }
114
+ bool operator==(const u32regex_iterator& that)const
115
+ {
116
+ if((pdata.get() == 0) || (that.pdata.get() == 0))
117
+ return pdata.get() == that.pdata.get();
118
+ return pdata->compare(*(that.pdata.get()));
119
+ }
120
+ bool operator!=(const u32regex_iterator& that)const
121
+ { return !(*this == that); }
122
+ const value_type& operator*()const
123
+ { return pdata->get(); }
124
+ const value_type* operator->()const
125
+ { return &(pdata->get()); }
126
+ u32regex_iterator& operator++()
127
+ {
128
+ cow();
129
+ if(0 == pdata->next())
130
+ {
131
+ pdata.reset();
132
+ }
133
+ return *this;
134
+ }
135
+ u32regex_iterator operator++(int)
136
+ {
137
+ u32regex_iterator result(*this);
138
+ ++(*this);
139
+ return result;
140
+ }
141
+ private:
142
+
143
+ pimpl pdata;
144
+
145
+ void cow()
146
+ {
147
+ // copy-on-write
148
+ if(pdata.get() && !pdata.unique())
149
+ {
150
+ pdata.reset(new impl(*(pdata.get())));
151
+ }
152
+ }
153
+ };
154
+
155
+ typedef u32regex_iterator<const char*> utf8regex_iterator;
156
+ typedef u32regex_iterator<const UChar*> utf16regex_iterator;
157
+ typedef u32regex_iterator<const UChar32*> utf32regex_iterator;
158
+
159
+ inline u32regex_iterator<const char*> make_u32regex_iterator(const char* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
160
+ {
161
+ return u32regex_iterator<const char*>(p, p+std::strlen(p), e, m);
162
+ }
163
+ #ifndef BOOST_NO_WREGEX
164
+ inline u32regex_iterator<const wchar_t*> make_u32regex_iterator(const wchar_t* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
165
+ {
166
+ return u32regex_iterator<const wchar_t*>(p, p+std::wcslen(p), e, m);
167
+ }
168
+ #endif
169
+ #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
170
+ inline u32regex_iterator<const UChar*> make_u32regex_iterator(const UChar* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
171
+ {
172
+ return u32regex_iterator<const UChar*>(p, p+u_strlen(p), e, m);
173
+ }
174
+ #endif
175
+ template <class charT, class Traits, class Alloc>
176
+ inline u32regex_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
177
+ {
178
+ typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
179
+ return u32regex_iterator<iter_type>(p.begin(), p.end(), e, m);
180
+ }
181
+ inline u32regex_iterator<const UChar*> make_u32regex_iterator(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
182
+ {
183
+ return u32regex_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, m);
184
+ }
185
+
186
+ #ifdef BOOST_HAS_ABI_HEADERS
187
+ # include BOOST_ABI_SUFFIX
188
+ #endif
189
+
190
+ } // namespace boost
191
+
192
+ #endif // BOOST_REGEX_V4_REGEX_ITERATOR_HPP
193
+
@@ -0,0 +1,377 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2003
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 u32regex_token_iterator.hpp
15
+ * VERSION see <boost/version.hpp>
16
+ * DESCRIPTION: Provides u32regex_token_iterator implementation.
17
+ */
18
+
19
+ #ifndef BOOST_REGEX_V4_U32REGEX_TOKEN_ITERATOR_HPP
20
+ #define BOOST_REGEX_V4_U32REGEX_TOKEN_ITERATOR_HPP
21
+
22
+ #if (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
23
+ || BOOST_WORKAROUND(BOOST_MSVC, < 1300) \
24
+ || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
25
+ //
26
+ // Borland C++ Builder 6, and Visual C++ 6,
27
+ // can't cope with the array template constructor
28
+ // so we have a template member that will accept any type as
29
+ // argument, and then assert that is really is an array:
30
+ //
31
+ #include <boost/static_assert.hpp>
32
+ #include <boost/type_traits/is_array.hpp>
33
+ #endif
34
+
35
+ namespace boost{
36
+
37
+ #ifdef BOOST_HAS_ABI_HEADERS
38
+ # include BOOST_ABI_PREFIX
39
+ #endif
40
+ #if BOOST_WORKAROUND(BOOST_MSVC, > 1300)
41
+ # pragma warning(push)
42
+ # pragma warning(disable:4700)
43
+ #endif
44
+
45
+ template <class BidirectionalIterator>
46
+ class u32regex_token_iterator_implementation
47
+ {
48
+ typedef u32regex regex_type;
49
+ typedef sub_match<BidirectionalIterator> value_type;
50
+
51
+ match_results<BidirectionalIterator> what; // current match
52
+ BidirectionalIterator end; // end of search area
53
+ BidirectionalIterator base; // start of search area
54
+ const regex_type re; // the expression
55
+ match_flag_type flags; // match flags
56
+ value_type result; // the current string result
57
+ int N; // the current sub-expression being enumerated
58
+ std::vector<int> subs; // the sub-expressions to enumerate
59
+
60
+ public:
61
+ u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, int sub, match_flag_type f)
62
+ : end(last), re(*p), flags(f){ subs.push_back(sub); }
63
+ u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const std::vector<int>& v, match_flag_type f)
64
+ : end(last), re(*p), flags(f), subs(v){}
65
+ #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
66
+ // can't reliably get this to work....
67
+ #elif (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
68
+ || BOOST_WORKAROUND(BOOST_MSVC, < 1300) \
69
+ || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) \
70
+ || BOOST_WORKAROUND(__HP_aCC, < 60700)
71
+ template <class T>
72
+ u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const T& submatches, match_flag_type f)
73
+ : end(last), re(*p), flags(f)
74
+ {
75
+ // assert that T really is an array:
76
+ BOOST_STATIC_ASSERT(::boost::is_array<T>::value);
77
+ const std::size_t array_size = sizeof(T) / sizeof(submatches[0]);
78
+ for(std::size_t i = 0; i < array_size; ++i)
79
+ {
80
+ subs.push_back(submatches[i]);
81
+ }
82
+ }
83
+ #else
84
+ template <std::size_t CN>
85
+ u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const int (&submatches)[CN], match_flag_type f)
86
+ : end(last), re(*p), flags(f)
87
+ {
88
+ for(std::size_t i = 0; i < CN; ++i)
89
+ {
90
+ subs.push_back(submatches[i]);
91
+ }
92
+ }
93
+ #endif
94
+
95
+ bool init(BidirectionalIterator first)
96
+ {
97
+ base = first;
98
+ N = 0;
99
+ if(u32regex_search(first, end, what, re, flags, base) == true)
100
+ {
101
+ N = 0;
102
+ result = ((subs[N] == -1) ? what.prefix() : what[(int)subs[N]]);
103
+ return true;
104
+ }
105
+ else if((subs[N] == -1) && (first != end))
106
+ {
107
+ result.first = first;
108
+ result.second = end;
109
+ result.matched = (first != end);
110
+ N = -1;
111
+ return true;
112
+ }
113
+ return false;
114
+ }
115
+ bool compare(const u32regex_token_iterator_implementation& that)
116
+ {
117
+ if(this == &that) return true;
118
+ return (&re.get_data() == &that.re.get_data())
119
+ && (end == that.end)
120
+ && (flags == that.flags)
121
+ && (N == that.N)
122
+ && (what[0].first == that.what[0].first)
123
+ && (what[0].second == that.what[0].second);
124
+ }
125
+ const value_type& get()
126
+ { return result; }
127
+ bool next()
128
+ {
129
+ if(N == -1)
130
+ return false;
131
+ if(N+1 < (int)subs.size())
132
+ {
133
+ ++N;
134
+ result =((subs[N] == -1) ? what.prefix() : what[subs[N]]);
135
+ return true;
136
+ }
137
+ //if(what.prefix().first != what[0].second)
138
+ // flags |= match_prev_avail | regex_constants::match_not_bob;
139
+ BidirectionalIterator last_end(what[0].second);
140
+ if(u32regex_search(last_end, end, what, re, ((what[0].first == what[0].second) ? flags | regex_constants::match_not_initial_null : flags), base))
141
+ {
142
+ N =0;
143
+ result =((subs[N] == -1) ? what.prefix() : what[subs[N]]);
144
+ return true;
145
+ }
146
+ else if((last_end != end) && (subs[0] == -1))
147
+ {
148
+ N =-1;
149
+ result.first = last_end;
150
+ result.second = end;
151
+ result.matched = (last_end != end);
152
+ return true;
153
+ }
154
+ return false;
155
+ }
156
+ private:
157
+ u32regex_token_iterator_implementation& operator=(const u32regex_token_iterator_implementation&);
158
+ };
159
+
160
+ template <class BidirectionalIterator>
161
+ class u32regex_token_iterator
162
+ #ifndef BOOST_NO_STD_ITERATOR
163
+ : public std::iterator<
164
+ std::forward_iterator_tag,
165
+ sub_match<BidirectionalIterator>,
166
+ typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type,
167
+ const sub_match<BidirectionalIterator>*,
168
+ const sub_match<BidirectionalIterator>& >
169
+ #endif
170
+ {
171
+ private:
172
+ typedef u32regex_token_iterator_implementation<BidirectionalIterator> impl;
173
+ typedef shared_ptr<impl> pimpl;
174
+ public:
175
+ typedef u32regex regex_type;
176
+ typedef sub_match<BidirectionalIterator> value_type;
177
+ typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
178
+ difference_type;
179
+ typedef const value_type* pointer;
180
+ typedef const value_type& reference;
181
+ typedef std::forward_iterator_tag iterator_category;
182
+
183
+ u32regex_token_iterator(){}
184
+ u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
185
+ int submatch = 0, match_flag_type m = match_default)
186
+ : pdata(new impl(&re, b, submatch, m))
187
+ {
188
+ if(!pdata->init(a))
189
+ pdata.reset();
190
+ }
191
+ u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
192
+ const std::vector<int>& submatches, match_flag_type m = match_default)
193
+ : pdata(new impl(&re, b, submatches, m))
194
+ {
195
+ if(!pdata->init(a))
196
+ pdata.reset();
197
+ }
198
+ #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
199
+ // can't reliably get this to work....
200
+ #elif (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
201
+ || BOOST_WORKAROUND(BOOST_MSVC, < 1300) \
202
+ || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) \
203
+ || BOOST_WORKAROUND(__HP_aCC, < 60700)
204
+ template <class T>
205
+ u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
206
+ const T& submatches, match_flag_type m = match_default)
207
+ : pdata(new impl(&re, b, submatches, m))
208
+ {
209
+ if(!pdata->init(a))
210
+ pdata.reset();
211
+ }
212
+ #else
213
+ template <std::size_t N>
214
+ u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
215
+ const int (&submatches)[N], match_flag_type m = match_default)
216
+ : pdata(new impl(&re, b, submatches, m))
217
+ {
218
+ if(!pdata->init(a))
219
+ pdata.reset();
220
+ }
221
+ #endif
222
+ u32regex_token_iterator(const u32regex_token_iterator& that)
223
+ : pdata(that.pdata) {}
224
+ u32regex_token_iterator& operator=(const u32regex_token_iterator& that)
225
+ {
226
+ pdata = that.pdata;
227
+ return *this;
228
+ }
229
+ bool operator==(const u32regex_token_iterator& that)const
230
+ {
231
+ if((pdata.get() == 0) || (that.pdata.get() == 0))
232
+ return pdata.get() == that.pdata.get();
233
+ return pdata->compare(*(that.pdata.get()));
234
+ }
235
+ bool operator!=(const u32regex_token_iterator& that)const
236
+ { return !(*this == that); }
237
+ const value_type& operator*()const
238
+ { return pdata->get(); }
239
+ const value_type* operator->()const
240
+ { return &(pdata->get()); }
241
+ u32regex_token_iterator& operator++()
242
+ {
243
+ cow();
244
+ if(0 == pdata->next())
245
+ {
246
+ pdata.reset();
247
+ }
248
+ return *this;
249
+ }
250
+ u32regex_token_iterator operator++(int)
251
+ {
252
+ u32regex_token_iterator result(*this);
253
+ ++(*this);
254
+ return result;
255
+ }
256
+ private:
257
+
258
+ pimpl pdata;
259
+
260
+ void cow()
261
+ {
262
+ // copy-on-write
263
+ if(pdata.get() && !pdata.unique())
264
+ {
265
+ pdata.reset(new impl(*(pdata.get())));
266
+ }
267
+ }
268
+ };
269
+
270
+ typedef u32regex_token_iterator<const char*> utf8regex_token_iterator;
271
+ typedef u32regex_token_iterator<const UChar*> utf16regex_token_iterator;
272
+ typedef u32regex_token_iterator<const UChar32*> utf32regex_token_iterator;
273
+
274
+ // construction from an integral sub_match state_id:
275
+ inline u32regex_token_iterator<const char*> make_u32regex_token_iterator(const char* p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
276
+ {
277
+ return u32regex_token_iterator<const char*>(p, p+std::strlen(p), e, submatch, m);
278
+ }
279
+ #ifndef BOOST_NO_WREGEX
280
+ inline u32regex_token_iterator<const wchar_t*> make_u32regex_token_iterator(const wchar_t* p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
281
+ {
282
+ return u32regex_token_iterator<const wchar_t*>(p, p+std::wcslen(p), e, submatch, m);
283
+ }
284
+ #endif
285
+ #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
286
+ inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UChar* p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
287
+ {
288
+ return u32regex_token_iterator<const UChar*>(p, p+u_strlen(p), e, submatch, m);
289
+ }
290
+ #endif
291
+ template <class charT, class Traits, class Alloc>
292
+ inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_token_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
293
+ {
294
+ typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
295
+ return u32regex_token_iterator<iter_type>(p.begin(), p.end(), e, submatch, m);
296
+ }
297
+ inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
298
+ {
299
+ return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
300
+ }
301
+
302
+ #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
303
+ // construction from a reference to an array:
304
+ template <std::size_t N>
305
+ inline u32regex_token_iterator<const char*> make_u32regex_token_iterator(const char* p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
306
+ {
307
+ return u32regex_token_iterator<const char*>(p, p+std::strlen(p), e, submatch, m);
308
+ }
309
+ #ifndef BOOST_NO_WREGEX
310
+ template <std::size_t N>
311
+ inline u32regex_token_iterator<const wchar_t*> make_u32regex_token_iterator(const wchar_t* p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
312
+ {
313
+ return u32regex_token_iterator<const wchar_t*>(p, p+std::wcslen(p), e, submatch, m);
314
+ }
315
+ #endif
316
+ #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
317
+ template <std::size_t N>
318
+ inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UChar* p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
319
+ {
320
+ return u32regex_token_iterator<const UChar*>(p, p+u_strlen(p), e, submatch, m);
321
+ }
322
+ #endif
323
+ template <class charT, class Traits, class Alloc, std::size_t N>
324
+ inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_token_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
325
+ {
326
+ typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
327
+ return u32regex_token_iterator<iter_type>(p.begin(), p.end(), e, submatch, m);
328
+ }
329
+ template <std::size_t N>
330
+ inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
331
+ {
332
+ return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
333
+ }
334
+ #endif // BOOST_MSVC < 1300
335
+
336
+ // construction from a vector of sub_match state_id's:
337
+ inline u32regex_token_iterator<const char*> make_u32regex_token_iterator(const char* p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
338
+ {
339
+ return u32regex_token_iterator<const char*>(p, p+std::strlen(p), e, submatch, m);
340
+ }
341
+ #ifndef BOOST_NO_WREGEX
342
+ inline u32regex_token_iterator<const wchar_t*> make_u32regex_token_iterator(const wchar_t* p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
343
+ {
344
+ return u32regex_token_iterator<const wchar_t*>(p, p+std::wcslen(p), e, submatch, m);
345
+ }
346
+ #endif
347
+ #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
348
+ inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UChar* p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
349
+ {
350
+ return u32regex_token_iterator<const UChar*>(p, p+u_strlen(p), e, submatch, m);
351
+ }
352
+ #endif
353
+ template <class charT, class Traits, class Alloc>
354
+ inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_token_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
355
+ {
356
+ typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
357
+ return u32regex_token_iterator<iter_type>(p.begin(), p.end(), e, submatch, m);
358
+ }
359
+ inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
360
+ {
361
+ return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
362
+ }
363
+
364
+ #if BOOST_WORKAROUND(BOOST_MSVC, > 1300)
365
+ # pragma warning(pop)
366
+ #endif
367
+ #ifdef BOOST_HAS_ABI_HEADERS
368
+ # include BOOST_ABI_SUFFIX
369
+ #endif
370
+
371
+ } // namespace boost
372
+
373
+ #endif // BOOST_REGEX_V4_REGEX_TOKEN_ITERATOR_HPP
374
+
375
+
376
+
377
+