Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update read_string_from_file to not include line feed #288

Merged

Conversation

MiranDMC
Copy link
Collaborator

Opcode reads until line feed, but line feed is included in the result. When I was doing some other quick test with file as input data it took me by surprise. It is also problematic as in most cases user do not want the line feed characters and there is no easy way to get rid of them in script.
DYOM also has bug where import objective texts from file feature adds unwanted "?" character at the end of every text. I'm not sure if this is DYOM's bug or maybe that feature worked differently in CLEO3.

@MiranDMC MiranDMC requested a review from x87 February 10, 2025 01:11
result.data[last] = '\0';
last--;
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oneliner

        // remove trailing line ending characters if present
        if (ok && !IsLegacyScript(thread))
        {
            result.data[strspn(result.data, "\n\r")] = '\0';
        }

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think it should be a default behavior for File::readString

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like opposite what we need

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like opposite what we need

what exactly?

Copy link
Collaborator Author

@MiranDMC MiranDMC Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strspn counts characters until first NOT included in second string occur.
So it would return 0 in most cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting. so we are going to keep \r in the string?

many modern software treat any combination of \r and \n as line endings. should we follow the same?

That would need extra logic as stream does not behave like that by default.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at some point we should modernize the codebase. I can't believe C++ in 2025 does not have any tools to solve it in more elegant way.

Copy link
Collaborator Author

@MiranDMC MiranDMC Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that creates some ambiguities. \r\n\r Should be single line or three? Currently only \n is considered new line and CR is threaten as helping character that may occur.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\r immediately followed by \n should be a single line endings. next \r is debatable, can be a line ending on it's own (very uncommon, especially on Windows) or be an input character (also uncommon). So, I'd say there are two lines: one empty and one with one character \r

1: ""
2: "\r"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we accept \r as line endings, you still have 2 lines, but both empty

1: ""
2: ""

@x87 x87 requested a review from Copilot February 10, 2025 01:28

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 3 changed files in this pull request and generated no comments.

Files not reviewed (2)
  • cleo_plugins/FileSystemOperations/FileSystemOperations.cpp: Language not supported
  • tests/cleo_tests/FilesystemOperations/0AD7.txt: Language not supported
@MiranDMC
Copy link
Collaborator Author

Copilot:
cleo_plugins/FileSystemOperations/FileSystemOperations.cpp: Language not supported

Wow, then why it even exists :P

@x87
Copy link

x87 commented Feb 10, 2025

Copilot: cleo_plugins/FileSystemOperations/FileSystemOperations.cpp: Language not supported

Wow, then why it even exists :P

yea, it surprised me as well. that's what it supports now

C#, Go, Java, JavaScript, Markdown, Python, Ruby, TypeScript

@MiranDMC MiranDMC merged commit 0ca2d4b into master Feb 10, 2025
@MiranDMC MiranDMC deleted the update_read_string_from_file_to_not_include_line_feed branch February 10, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants