bcc icon indicating copy to clipboard operation
bcc copied to clipboard

Slicing results of ReadLine(...).Split(...) doesn't work

Open AXKuhta opened this issue 2 years ago • 3 comments

Given a file test.txt that contains This is a test string. Sentence 1. Sentence 2. and the following program:

Framework BRL.StandardIO
Import BRL.Filesystem

Local File:TStream = ReadFile("test.txt")
Local Arr:String[] = ReadLine(File).Split(".")[1..]

Print(Arr[0])

The expected result is Sentence 1 but in reality it prints nothing.

Workaround:

- Local Arr:String[] = ReadLine(File).Split(".")[1..]
+ Local Arr:String[] = ReadLine(File).Split(".")
+ Arr = Arr[1..]

Diffing working C code against broken C code reveals what appears to be the problem:

- BBARRAY bbt_Arr=bbStringSplit((BBSTRING)brl_stream_ReadLine((struct brl_stream_TStream_obj*)bbt_File),&_s1);
- bbt_Arr=bbArraySlice("$",bbt_Arr,1,(bbt_Arr)->scales[0]);
+ BBARRAY bbt_Arr=bbArraySlice("$",bbStringSplit((BBSTRING)brl_stream_ReadLine((struct brl_stream_TStream_obj*)bbt_File),&_s1),1,(bbStringSplit((BBSTRING)brl_stream_ReadLine((struct brl_stream_TStream_obj*)bbt_File),&_s1))->scales[0]);

ReadLine(File).Split(".") gets executed twice!

BlitzMax version: BlitzMax_win32_0.129.3.45

AXKuhta avatar Feb 05 '23 03:02 AXKuhta