Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The issue I have with this is a lack of specification. Left pad _what_?

Numbers or ASCII-only-printing? OK that's a reasonable. Is there a desired overflow behavior?

Past that it becomes more an issue of where and why. The suddenly not-trivial example includes questions about fonts, layout, and multi-byte characters. Emoji, etc.

Incidentally, in pseudoscope:

Create a valid full-space pad string (termination / etc), then decrement back from the end of the source string and over-write the pad characters from the end to the start of the string, exiting either on no more pad characters or no more input.

A second algorithm might combine those two steps as one pass, fill the output buffer from back to front. Only for C style strings would this be an issue given the dynamic end point for the data structure.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: