Skip to content

Commit 7a96a53

Browse files
committed
udt-wstring: INSTR, INSTRREV, will accept UDT as z|wstring
1 parent adc12dd commit 7a96a53

File tree

6 files changed

+867
-0
lines changed

6 files changed

+867
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Version 1.07.0
1212
- LTRIM/RTRIM/TRIM will accept UDT as Z|WSTRING
1313
- LCASE/UCASE will accept UDT as Z|WSTRING
1414
- Cxxx() conversion functions will accept UDT as Z|WSTRING
15+
- INSTR/INSTRREV will accept UDT as Z|WSTRING
1516

1617
[fixed]
1718
- sf.net #881: C backend: support for varadic function parameters in gcc using __builtin_va_list type and related macros

src/compiler/rtl-string.bas

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,11 @@ function rtlStrInstr _
34253425

34263426
function = NULL
34273427

3428+
astTryOvlStringCONV( nd_text )
3429+
if( nd_pattern ) then
3430+
astTryOvlStringCONV( nd_pattern )
3431+
end if
3432+
34283433
dtype = astGetDataType( nd_text )
34293434

34303435
''
@@ -3476,6 +3481,11 @@ function rtlStrInstrRev _
34763481

34773482
function = NULL
34783483

3484+
astTryOvlStringCONV( nd_text )
3485+
if( nd_pattern ) then
3486+
astTryOvlStringCONV( nd_pattern )
3487+
end if
3488+
34793489
dtype = astGetDataType( nd_text )
34803490

34813491
''

tests/udt-wstring/instr.bas

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
#include "fbcunit.bi"
2+
#include once "uwstring-fixed.bi"
3+
#include once "chk-wstring.bi"
4+
5+
#define ustring UWSTRING_FIXED
6+
7+
SUITE( fbc_tests.udt_wstring_.instr_ )
8+
9+
'' INSTR( wstring, wstring )
10+
#macro check_0( result, text, pattern )
11+
scope
12+
dim st as wstring * 50 = text
13+
dim ut as ustring = st
14+
dim sp as wstring * 50 = pattern
15+
dim up as ustring = sp
16+
17+
CU_ASSERT_EQUAL( result, instr( st, sp ) )
18+
CU_ASSERT_EQUAL( result, instr( st, up ) )
19+
CU_ASSERT_EQUAL( result, instr( ut, sp ) )
20+
CU_ASSERT_EQUAL( result, instr( ut, up ) )
21+
end scope
22+
#endmacro
23+
24+
'' INSTR( index, wstring, wstring )
25+
#macro check_x( result, index, text, pattern )
26+
scope
27+
dim st as wstring * 50 = text
28+
dim ut as ustring = st
29+
dim sp as wstring * 50 = pattern
30+
dim up as ustring = sp
31+
32+
CU_ASSERT_EQUAL( result, instr( index, st, sp ) )
33+
CU_ASSERT_EQUAL( result, instr( index, st, up ) )
34+
CU_ASSERT_EQUAL( result, instr( index, ut, sp ) )
35+
CU_ASSERT_EQUAL( result, instr( index, ut, up ) )
36+
end scope
37+
#endmacro
38+
39+
'' INSTR( wstring, wstring )
40+
#macro check_0_any( result, text, pattern )
41+
scope
42+
dim st as wstring * 50 = text
43+
dim ut as ustring = st
44+
dim sp as wstring * 50 = pattern
45+
dim up as ustring = sp
46+
47+
CU_ASSERT_EQUAL( result, instr( st, any sp ) )
48+
CU_ASSERT_EQUAL( result, instr( st, any up ) )
49+
CU_ASSERT_EQUAL( result, instr( ut, any sp ) )
50+
CU_ASSERT_EQUAL( result, instr( ut, any up ) )
51+
end scope
52+
#endmacro
53+
54+
'' INSTR( index, wstring, wstring )
55+
#macro check_x_any( result, index, text, pattern )
56+
scope
57+
dim st as wstring * 50 = text
58+
dim ut as ustring = st
59+
dim sp as wstring * 50 = pattern
60+
dim up as ustring = sp
61+
62+
CU_ASSERT_EQUAL( result, instr( index, st, any sp ) )
63+
CU_ASSERT_EQUAL( result, instr( index, st, any up ) )
64+
CU_ASSERT_EQUAL( result, instr( index, ut, any sp ) )
65+
CU_ASSERT_EQUAL( result, instr( index, ut, any up ) )
66+
end scope
67+
#endmacro
68+
69+
TEST( instr_0 )
70+
check_0( 0, !"", !"" )
71+
check_0( 0, !"x", !"" )
72+
check_0( 0, !"", !"x" )
73+
check_0( 1, !"x", !"x" )
74+
check_0( 2, !"yx", !"x" )
75+
76+
check_0( 1, !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043" )
77+
check_0( 2, !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3045" )
78+
check_0( 3, !"\u3041\u3043\u3045\u3047\u3049", !"\u3045\u3047" )
79+
check_0( 4, !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049" )
80+
END_TEST
81+
82+
TEST( instr_x )
83+
check_x( 0, -1, !"", !"" )
84+
check_x( 0, 0, !"", !"" )
85+
check_x( 0, 1, !"", !"" )
86+
check_x( 0, 2, !"", !"" )
87+
88+
check_x( 0, -1, !"x", !"" )
89+
check_x( 0, 0, !"x", !"" )
90+
check_x( 0, 1, !"x", !"" )
91+
check_x( 0, 2, !"x", !"" )
92+
93+
check_x( 0, -1, !"", !"x" )
94+
check_x( 0, 0, !"", !"x" )
95+
check_x( 0, 1, !"", !"x" )
96+
check_x( 0, 2, !"", !"x" )
97+
98+
check_x( 0, -1, !"x", !"x" )
99+
check_x( 0, 0, !"x", !"x" )
100+
check_x( 1, 1, !"x", !"x" )
101+
check_x( 0, 2, !"x", !"x" )
102+
check_x( 0, 3, !"x", !"x" )
103+
104+
check_x( 0, -1, !"xy", !"x" )
105+
check_x( 0, 0, !"xy", !"x" )
106+
check_x( 1, 1, !"xy", !"x" )
107+
check_x( 0, 2, !"xy", !"x" )
108+
check_x( 0, 3, !"xy", !"x" )
109+
110+
check_x( 0, -1, !"yx", !"x" )
111+
check_x( 0, 0, !"yx", !"x" )
112+
check_x( 2, 1, !"yx", !"x" )
113+
check_x( 2, 2, !"yx", !"x" )
114+
check_x( 0, 3, !"yx", !"x" )
115+
116+
check_x( 0, 0, !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043" )
117+
check_x( 1, 1, !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043" )
118+
check_x( 0, 2, !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043" )
119+
120+
check_x( 2, 1, !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3045" )
121+
check_x( 2, 2, !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3045" )
122+
check_x( 0, 3, !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3045" )
123+
124+
check_x( 3, 2, !"\u3041\u3043\u3045\u3047\u3049", !"\u3045\u3047" )
125+
check_x( 3, 3, !"\u3041\u3043\u3045\u3047\u3049", !"\u3045\u3047" )
126+
check_x( 0, 4, !"\u3041\u3043\u3045\u3047\u3049", !"\u3045\u3047" )
127+
128+
check_x( 4, 3, !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049" )
129+
check_x( 4, 4, !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049" )
130+
check_x( 0, 5, !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049" )
131+
END_TEST
132+
133+
TEST( instr_0_any )
134+
check_0_any( 0, !"", !"" )
135+
check_0_any( 0, !"x", !"" )
136+
check_0_any( 0, !"", !"x" )
137+
check_0_any( 1, !"x", !"x" )
138+
check_0_any( 1, !"xy", !"x" )
139+
check_0_any( 2, !"yx", !"x" )
140+
141+
check_0_any( 1, !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043" )
142+
check_0_any( 2, !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3045" )
143+
check_0_any( 3, !"\u3041\u3043\u3045\u3047\u3049", !"\u3045\u3047" )
144+
check_0_any( 4, !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049" )
145+
END_TEST
146+
147+
TEST( instr_x_any )
148+
check_x_any( 0, -1, !"", !"" )
149+
check_x_any( 0, 0, !"", !"" )
150+
check_x_any( 0, 1, !"", !"" )
151+
check_x_any( 0, 2, !"", !"" )
152+
153+
check_x_any( 0, -1, !"x", !"" )
154+
check_x_any( 0, 0, !"x", !"" )
155+
check_x_any( 0, 1, !"x", !"" )
156+
check_x_any( 0, 2, !"x", !"" )
157+
158+
check_x_any( 0, -1, !"", !"x" )
159+
check_x_any( 0, 0, !"", !"x" )
160+
check_x_any( 0, 1, !"", !"x" )
161+
check_x_any( 0, 2, !"", !"x" )
162+
163+
check_x_any( 0, -1, !"x", !"x" )
164+
check_x_any( 0, 0, !"x", !"x" )
165+
check_x_any( 1, 1, !"x", !"x" )
166+
check_x_any( 0, 2, !"x", !"x" )
167+
168+
check_x_any( 0, -1, !"xy", !"x" )
169+
check_x_any( 0, 0, !"xy", !"x" )
170+
check_x_any( 1, 1, !"xy", !"x" )
171+
check_x_any( 0, 2, !"xy", !"x" )
172+
check_x_any( 0, 3, !"xy", !"x" )
173+
174+
check_x_any( 0, -1, !"yx", !"x" )
175+
check_x_any( 0, 0, !"yx", !"x" )
176+
check_x_any( 2, 1, !"yx", !"x" )
177+
check_x_any( 2, 2, !"yx", !"x" )
178+
check_x_any( 0, 3, !"yx", !"x" )
179+
180+
check_x_any( 0, 0, !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043" )
181+
check_x_any( 1, 1, !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043" )
182+
check_x_any( 2, 2, !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043" )
183+
check_x_any( 0, 3, !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043" )
184+
185+
check_x_any( 2, 1, !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3045" )
186+
check_x_any( 2, 2, !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3045" )
187+
check_x_any( 3, 3, !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3045" )
188+
check_x_any( 0, 4, !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3045" )
189+
190+
check_x_any( 3, 2, !"\u3041\u3043\u3045\u3047\u3049", !"\u3045\u3047" )
191+
check_x_any( 3, 3, !"\u3041\u3043\u3045\u3047\u3049", !"\u3045\u3047" )
192+
check_x_any( 4, 4, !"\u3041\u3043\u3045\u3047\u3049", !"\u3045\u3047" )
193+
check_x_any( 0, 5, !"\u3041\u3043\u3045\u3047\u3049", !"\u3045\u3047" )
194+
195+
check_x_any( 4, 3, !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049" )
196+
check_x_any( 4, 4, !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049" )
197+
check_x_any( 5, 5, !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049" )
198+
check_x_any( 0, 6, !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049" )
199+
END_TEST
200+
201+
END_SUITE

0 commit comments

Comments
 (0)