Replies: 2 comments
-
On 12/20/24 09:17, MarcusE1W wrote:
Hi. I am playing with Advent of code 2024, day 2, where you have to read integers from one line. That works well with IO.GetInt. However, I also need to know when the last Int of that line has been read. An End of line flag.
I searched and it looks like IO, Rd, etc. does not provide a EOL flag. Is there a way to check for EOL?
The only idea I head is to read ahead every time before reading an int and to check if the next char is \n.
Or I read the whole line and then take that string into pieces.
Feels a bit inefficient and inelegant.
Is there a good way to spot EOL in a text file?
I presume you want to know even if there are trailing blanks before the EOL?
Obviously either you or some library code will have to read the EOL to know it's there.
Any time you don't know in advance what is next, there has to be lookahead, and
you have what amounts to a mini lexical scanner.
If you know the line has only blanks, integers, and EOL, you can just TRY Lex.Int
(IO.Int does the same) and see if it raises Lex.Error. This would mean there was
not an integer or anything else but blanks remaining on the line. If not, you have
just gotten an integer. Note that \n is not an OS-independent EOL sequence,
if you want to consume it and look for another line.
For a more general way, but using IO.Int, etc, look at Lex.Skip,
Rd.GetChar, and Rd.UnGetChar.
Most generally, use Rd.GetLine or Rd.GetSub to get the whole line in and scan it
yourself one character at a time.
… —
Reply to this email directly, view it on GitHub <#1197>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABSVZNFLYO22PNQMJ6LMHL32GQYJXAVCNFSM6AAAAABT7KND3CVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZXG4ZDANRWGQ>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
On 12/20/24 13:15, Rodney Bates wrote:
On 12/20/24 09:17, MarcusE1W wrote:
>
> Hi. I am playing with Advent of code 2024, day 2, where you have to read integers from one line. That works well with IO.GetInt. However, I also need to know when the last Int of that line has been read. An End of line flag.
>
> I searched and it looks like IO, Rd, etc. does not provide a EOL flag. Is there a way to check for EOL?
>
> The only idea I head is to read ahead every time before reading an int and to check if the next char is \n.
> Or I read the whole line and then take that string into pieces.
> Feels a bit inefficient and inelegant.
>
> Is there a good way to spot EOL in a text file?
>
I presume you want to know even if there are trailing blanks before the EOL?
Obviously either you or some library code will have to read the EOL to know it's there.
Any time you don't know in advance what is next, there has to be lookahead, and
you have what amounts to a mini lexical scanner.
If you know the line has only blanks, integers, and EOL, you can just TRY Lex.Int
(IO.Int does the same) and see if it raises Lex.Error. This would mean there was
^IO.GetInt --------------------------------------------
… not an integer or anything else but blanks remaining on the line. If not, you have
just gotten an integer. Note that \n is not an OS-independent EOL sequence,
if you want to consume it and look for another line.
For a more general way, but using IO.Int, etc, look at Lex.Skip,
Rd.GetChar, and Rd.UnGetChar.
Most generally, use Rd.GetLine or Rd.GetSub to get the whole line in and scan it
yourself one character at a time.
> —
> Reply to this email directly, view it on GitHub <#1197>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABSVZNFLYO22PNQMJ6LMHL32GQYJXAVCNFSM6AAAAABT7KND3CVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZXG4ZDANRWGQ>.
> You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I am playing with Advent of code 2024, day 2, where you have to read integers from one line. That works well with IO.GetInt. However, I also need to know when the last Int of that line has been read. An End of line flag.
I searched and it looks like IO, Rd, etc. does not provide a EOL flag. Is there a way to check for EOL?
The only idea I head is to read ahead every time before reading an int and to check if the next char is \n.
Or I read the whole line and then take that string into pieces.
Feels a bit inefficient and inelegant.
Is there a good way to spot EOL in a text file?
Beta Was this translation helpful? Give feedback.
All reactions