-
Notifications
You must be signed in to change notification settings - Fork 20
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
Added new StringJoin() utility function #203
Conversation
The function joins a sequence of strings with an optional separator in between the elements. Ticket: None Changelog: None Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
There was an error running your pipeline, see logs for details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code looks so familiar to something I saw recently! ;) 🏆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me otherwise.
|
||
Writer *const writer = StringWriter(); | ||
const size_t len = SeqLength(seq); | ||
for (size_t i = 0; i < len; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd do i < (len -1)
writing the separator after every item and then writing the last item after the for
loop without a separator. But YMMV.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the program would crash if the sequence was empty, right ? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, but that's easy to check upfront. Which is better than having an unnecessary if
inside the loop.
The function joins a sequence of strings with an optional separator in between the elements.