79756334

Date: 2025-09-05 00:45:10
Score: 2.5
Natty:
Report link

So, it looks like in Linux I can't use the constructor

string (const char* s, size_t n)

(as Kevin suggested above).

This leaves me with two options. If I want to truncate the read line (remove the trailing newline), I can either truncate the C-string prior to using it to create the C++ string:

        if !keep_newlines {
                line![readCount - 1] = 0
            }
         let cpps = std.string(line)
         free(line)
         return cpps

or I can truncate the C++ string after it was created:

            var cpps = std.string(line)
            free(line)
            if !keep_newlines {
                cpps.pop_back()
            }
            return cpps

Both options work and the performance is pretty much the same. @PaulMcKenzie, @Kevin, @Remy Lebeau - Thanks for your suggestions.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @PaulMcKenzie
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Artur P