Skip to content

Commit 2e7d606

Browse files
committed
udt-wstring: ASC function will accept UDT as Z|WSTRING
1 parent 135f364 commit 2e7d606

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Version 1.07.0
1818
- SADD/STRPTR will accept UDT as Z|WSTRING to return Z|WSTRING ptr
1919
- LSET/RSET statements will accept UDT as Z|WSTRING
2020
- MID statement will accept UDT as Z|WSTRING
21+
- ASC function will accept UDT as Z|WSTRING
2122

2223
[fixed]
2324
- 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,6 +3331,8 @@ function rtlStrAsc _
33313331

33323332
function = NULL
33333333

3334+
astTryOvlStringCONV( expr )
3335+
33343336
''
33353337
if( astGetDataType( expr ) <> FB_DATATYPE_WCHAR ) then
33363338
proc = astNewCALL( PROCLOOKUP( STRASC ) )

tests/udt-wstring/asc.bas

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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_.asc_ )
8+
9+
TEST( ascii )
10+
dim s as wstring * 256
11+
for i as uinteger = 1 to 255
12+
s[i-1] = i
13+
next
14+
dim u as ustring = s
15+
16+
CU_ASSERT_EQUAL( asc( s ), asc( u ) )
17+
18+
for i as integer = -2 to 257
19+
select case i
20+
case 1 to 255
21+
CU_ASSERT_EQUAL( i, asc( u, i ) )
22+
case else
23+
CU_ASSERT_EQUAL( 0, asc( u, i ) )
24+
end select
25+
next
26+
27+
END_TEST
28+
29+
TEST( ucs2 )
30+
dim s as wstring * 256
31+
for i as uinteger = 1 to 255
32+
s[i-1] = i shl 8
33+
next
34+
dim u as ustring = s
35+
36+
CU_ASSERT_EQUAL( asc( s ), asc( u ) )
37+
38+
for i as integer = -2 to 257
39+
select case i
40+
case 1 to 255
41+
CU_ASSERT_EQUAL( asc( s, i ), asc( u, i ) )
42+
case else
43+
CU_ASSERT_EQUAL( 0, asc( u, i ) )
44+
end select
45+
next
46+
47+
END_TEST
48+
49+
END_SUITE

tests/udt-zstring/asc.bas

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "fbcunit.bi"
2+
#include once "uzstring-fixed.bi"
3+
#include once "chk-zstring.bi"
4+
5+
#define ustring UZSTRING_FIXED
6+
7+
SUITE( fbc_tests.udt_zstring_.asc_ )
8+
9+
TEST( ascii )
10+
dim s as zstring * 256
11+
for i as uinteger = 1 to 255
12+
s[i-1] = i
13+
next
14+
dim u as ustring = s
15+
16+
CU_ASSERT_EQUAL( asc( s ), asc( u ) )
17+
18+
for i as integer = -2 to 257
19+
select case i
20+
case 1 to 255
21+
CU_ASSERT_EQUAL( i, asc( u, i ) )
22+
case else
23+
CU_ASSERT_EQUAL( 0, asc( u, i ) )
24+
end select
25+
next
26+
27+
END_TEST
28+
29+
TEST( ucs2 )
30+
dim s as zstring * 256
31+
for i as uinteger = 1 to 255
32+
s[i-1] = i shl 8
33+
next
34+
dim u as ustring = s
35+
36+
CU_ASSERT_EQUAL( asc( s ), asc( u ) )
37+
38+
for i as integer = -2 to 257
39+
select case i
40+
case 1 to 255
41+
CU_ASSERT_EQUAL( asc( s, i ), asc( u, i ) )
42+
case else
43+
CU_ASSERT_EQUAL( 0, asc( u, i ) )
44+
end select
45+
next
46+
47+
END_TEST
48+
49+
END_SUITE

tests/wstring/asc.bas

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,40 @@ SUITE( fbc_tests.wstring_.asc_ )
1919

2020
END_TEST
2121

22+
TEST( ascii )
23+
dim w as wstring * 256
24+
for i as integer = 1 to 255
25+
w[i-1] = i
26+
next
27+
28+
CU_ASSERT_EQUAL( 1, asc( w ) )
29+
30+
for i as integer = -2 to 257
31+
select case i
32+
case 1 to 255
33+
CU_ASSERT_EQUAL( i, asc( w, i ) )
34+
case else
35+
CU_ASSERT_EQUAL( 0, asc( w, i ) )
36+
end select
37+
next
38+
END_TEST
39+
40+
TEST( ucs2 )
41+
dim w as wstring * 256
42+
for i as integer = 1 to 255
43+
w[i-1] = i shl 8
44+
next
45+
46+
CU_ASSERT_EQUAL( 256, asc( w ) )
47+
48+
for i as integer = -2 to 257
49+
select case i
50+
case 1 to 255
51+
CU_ASSERT_EQUAL( w[i-1], asc( w, i ) )
52+
case else
53+
CU_ASSERT_EQUAL( 0, asc( w, i ) )
54+
end select
55+
next
56+
END_TEST
57+
2258
END_SUITE

0 commit comments

Comments
 (0)