Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Optimized version of leftpad in plain C

Name: Anonymous 2016-03-23 21:32

#include <string.h>

static const char*
string_add(const char* first, const char* second)
{
const char* result = malloc(strlen(first) + strlen(second) + 1);
strcat(result, first);
strcat(result, second);
return result;
}

const char*
leftpad(const char* str, size_t len, char ch)
{
int i = -1;

if (ch == 0) ch = ' ';

int len = strlen(str);

while (++i < len) {
char buf[2] = { 0 };
buf[0] = ch;
str = string_add(buf, str);
}

return str;
}

Name: Anonymous 2016-05-03 5:57

>>99
The problem is not Unicode's ability to hold this many codepoints. It's a great advantage indeed.

The problem is complexity of the standard itself. There's more to it than mapping values to characters. And even that got its flaws in the implementation.

For example combining characters, "ö" vs. "ö", U+006F U+0308 vs. U+00F6. On top of that, all the UAX'es: Unicode Bidirectional Algorithm, East Asian Width, Unicode Line Breaking Algorithm, Unicode Normalization Forms and more. And these are all part of the standard, I'm not including "Unicode Technical Standards" with which software does not have to be conformant, to implement Unicode. Good luck parsing and implementing all quirks of Unicode.

Given that, emojis are just a minor problem.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List