1--TEST--
2grapheme_* functions with out-of-bounds offsets
3--FILE--
4<?php
5
6// Offset == Length is legal.
7var_dump(grapheme_strpos("foo", "bar", 3));
8var_dump(grapheme_stripos("foo", "bar", 3));
9var_dump(grapheme_strrpos("foo", "bar", 3));
10var_dump(grapheme_strripos("foo", "bar", 3));
11var_dump(grapheme_strpos("äöü", "bar", 3));
12var_dump(grapheme_stripos("äöü", "bar", 3));
13var_dump(grapheme_strrpos("äöü", "bar", 3));
14var_dump(grapheme_strripos("äöü", "bar", 3));
15echo "\n";
16
17// Offset == -Length is legal.
18var_dump(grapheme_strpos("foo", "bar", -3));
19var_dump(grapheme_stripos("foo", "bar", -3));
20var_dump(grapheme_strrpos("foo", "bar", -3));
21var_dump(grapheme_strripos("foo", "bar", -3));
22var_dump(grapheme_strpos("äöü", "bar", -3));
23var_dump(grapheme_stripos("äöü", "bar", -3));
24var_dump(grapheme_strrpos("äöü", "bar", -3));
25var_dump(grapheme_strripos("äöü", "bar", -3));
26echo "\n";
27
28// Offset == Length is legal.
29var_dump(grapheme_strpos("", "bar", 0));
30var_dump(grapheme_stripos("", "bar", 0));
31var_dump(grapheme_strrpos("", "bar", 0));
32var_dump(grapheme_strripos("", "bar", 0));
33echo "\n";
34
35// Positive out of bounds.
36try {
37    var_dump(grapheme_strpos("foo", "bar", 4));
38} catch (ValueError $e) {
39    echo $e->getMessage(), "\n";
40}
41try {
42    var_dump(grapheme_stripos("foo", "bar", 4));
43} catch (ValueError $e) {
44    echo $e->getMessage(), "\n";
45}
46try {
47    var_dump(grapheme_strrpos("foo", "bar", 4));
48} catch (ValueError $e) {
49    echo $e->getMessage(), "\n";
50}
51try {
52    var_dump(grapheme_strripos("foo", "bar", 4));
53} catch (ValueError $e) {
54    echo $e->getMessage(), "\n";
55}
56try {
57    var_dump(grapheme_strpos("äöü", "bar", 4));
58} catch (ValueError $e) {
59    echo $e->getMessage(), "\n";
60}
61try {
62    var_dump(grapheme_stripos("äöü", "bar", 4));
63} catch (ValueError $e) {
64    echo $e->getMessage(), "\n";
65}
66try {
67    var_dump(grapheme_strrpos("äöü", "bar", 4));
68} catch (ValueError $e) {
69    echo $e->getMessage(), "\n";
70}
71try {
72    var_dump(grapheme_strripos("äöü", "bar", 4));
73} catch (ValueError $e) {
74    echo $e->getMessage(), "\n";
75}
76echo "\n";
77
78// Negative out of bounds.
79try {
80    var_dump(grapheme_strpos("foo", "bar", -4));
81} catch (ValueError $e) {
82    echo $e->getMessage(), "\n";
83}
84try {
85    var_dump(grapheme_stripos("foo", "bar", -4));
86} catch (ValueError $e) {
87    echo $e->getMessage(), "\n";
88}
89try {
90    var_dump(grapheme_strrpos("foo", "bar", -4));
91} catch (ValueError $e) {
92    echo $e->getMessage(), "\n";
93}
94try {
95    var_dump(grapheme_strripos("foo", "bar", -4));
96} catch (ValueError $e) {
97    echo $e->getMessage(), "\n";
98}
99try {
100    var_dump(grapheme_strpos("äöü", "bar", -4));
101} catch (ValueError $e) {
102    echo $e->getMessage(), "\n";
103}
104try {
105    var_dump(grapheme_stripos("äöü", "bar", -4));
106} catch (ValueError $e) {
107    echo $e->getMessage(), "\n";
108}
109try {
110    var_dump(grapheme_strrpos("äöü", "bar", -4));
111} catch (ValueError $e) {
112    echo $e->getMessage(), "\n";
113}
114try {
115    var_dump(grapheme_strripos("äöü", "bar", -4));
116} catch (ValueError $e) {
117    echo $e->getMessage(), "\n";
118}
119echo "\n";
120
121// Empty needle +  out of bounds
122try {
123    var_dump(grapheme_strpos("äöü", "", 4));
124} catch (ValueError $e) {
125    echo $e->getMessage(), "\n";
126}
127try {
128    var_dump(grapheme_stripos("äöü", "", 4));
129} catch (ValueError $e) {
130    echo $e->getMessage(), "\n";
131}
132try {
133    var_dump(grapheme_strrpos("äöü", "", 4));
134} catch (ValueError $e) {
135    echo $e->getMessage(), "\n";
136}
137try {
138    var_dump(grapheme_strripos("äöü", "", 4));
139} catch (ValueError $e) {
140    echo $e->getMessage(), "\n";
141}
142try {
143    var_dump(grapheme_strpos("äöü", "", -4));
144} catch (ValueError $e) {
145    echo $e->getMessage(), "\n";
146}
147try {
148    var_dump(grapheme_stripos("äöü", "", -4));
149} catch (ValueError $e) {
150    echo $e->getMessage(), "\n";
151}
152try {
153    var_dump(grapheme_strrpos("äöü", "", -4));
154} catch (ValueError $e) {
155    echo $e->getMessage(), "\n";
156}
157try {
158    var_dump(grapheme_strripos("äöü", "", -4));
159} catch (ValueError $e) {
160    echo $e->getMessage(), "\n";
161}
162echo "\n";
163
164var_dump(grapheme_substr("foo", 3));
165var_dump(grapheme_substr("foo", -3));
166var_dump(grapheme_substr("foo", 4));
167var_dump(grapheme_substr("foo", -4));
168var_dump(grapheme_substr("äöü", 3));
169var_dump(grapheme_substr("äöü", -3));
170var_dump(grapheme_substr("äöü", 4));
171var_dump(grapheme_substr("äöü", -4));
172var_dump(grapheme_substr("foo", 0, 3));
173var_dump(grapheme_substr("foo", 0, -3));
174var_dump(grapheme_substr("foo", 0, 4));
175var_dump(grapheme_substr("foo", 0, -4));
176var_dump(grapheme_substr("äöü", 0, 3));
177var_dump(grapheme_substr("äöü", 0, -3));
178var_dump(grapheme_substr("äöü", 0, 4));
179var_dump(grapheme_substr("äöü", 0, -4));
180var_dump(grapheme_substr("äöü", -4, 1));
181var_dump(grapheme_substr("äöü", -4, -1));
182var_dump(grapheme_substr("äöü", 2, -2));
183
184?>
185--EXPECT--
186bool(false)
187bool(false)
188bool(false)
189bool(false)
190bool(false)
191bool(false)
192bool(false)
193bool(false)
194
195bool(false)
196bool(false)
197bool(false)
198bool(false)
199bool(false)
200bool(false)
201bool(false)
202bool(false)
203
204bool(false)
205bool(false)
206bool(false)
207bool(false)
208
209grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
210grapheme_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
211grapheme_strrpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
212grapheme_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
213grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
214grapheme_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
215grapheme_strrpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
216grapheme_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
217
218grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
219grapheme_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
220grapheme_strrpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
221grapheme_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
222grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
223grapheme_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
224grapheme_strrpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
225grapheme_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
226
227grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
228grapheme_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
229grapheme_strrpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
230grapheme_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
231grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
232grapheme_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
233grapheme_strrpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
234grapheme_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
235
236string(0) ""
237string(3) "foo"
238string(0) ""
239string(3) "foo"
240string(0) ""
241string(6) "äöü"
242string(0) ""
243string(6) "äöü"
244string(3) "foo"
245string(0) ""
246string(3) "foo"
247string(0) ""
248string(6) "äöü"
249string(0) ""
250string(6) "äöü"
251string(0) ""
252string(2) "ä"
253string(4) "äö"
254string(0) ""
255