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-04-17 15:01

>>79
Nobody gives a shit about utf8. your programs should know how to work with any kind of encoding.

Name: Anonymous 2016-04-17 18:13

>>79
and use an ICU library
An inherit its overhead and vulnerabilities for something as simple as this? No thanks.

>>80
Take a step away from enterprise and a step towards purity.

>>81
UTF-8 is the only worthy encoding. I suppose you think all programs should be equipped with image recognition so they can read ancient egyptian inscriptions on walls as well.

Name: Anonymous 2016-04-17 18:47

>>81
your programs should know how to work with any kind of encoding.

God, no. There's no advantage to perpetuating a bunch of shitty ancient code pages and other defective text encodings.

Most programs should accept only UTF-8 and emit only UTF-8. In the odd case where you need to accept non-UTF8 input, force the client to specify the encoding - don't autodetect.

Name: Anonymous 2016-04-17 19:07

Shift_JIS is the only standard we really need.

Name: Anonymous 2016-04-17 19:49

>>83
Who said anything about autodetect? For the case >>79 was talking about you do not need to even know the encoding.

Name: Anonymous 2016-04-18 8:00

>>83
Fuck you. I do a lot of imaging old software & docs, and systems should have knowledge of all the shitty old encodings for when you need them. It's not like they take any considerable space or slow anything down.

All you backwards fucknuts need to have the machine fucking working for you, instead of trying to let the machine off the hook for complex cases. Are you dickheads are afraid of computing? This is what computers are for!

Name: Anonymous 2016-04-19 0:21

>>86
Legacy encodings considered harmful

Name: Anonymous 2016-04-19 2:36

>>87
Damn straight, I'll shove my glock in your face for that shit.

Name: Anonymous 2016-04-19 3:21

>>87
Harmful to whom or to what? Nothing!

Name: Anonymous 2016-04-23 23:32

>>89
To everyone who is bothered by them, so everyone.

Name: Anonymous 2016-04-24 5:08

>>90
The rest of the world is bothered by you, so now what?

Kill yourself!

Name: Anonymous 2016-04-26 2:36

>>83
Elitist pricks. The whole world doesn't revolve around your UTF-8 narcissism, if anything forcing it leaves for less compatibility which is precisely what I'm paying you for, programmer boy

Name: Anonymous 2016-04-26 23:29

>>92
Compatibility with inferior solutions is not an advantage. The herd must be culled.

Name: Anonymous 2016-04-27 2:07

(slime-restart-inferior-lisp)

Name: Anonymous 2016-04-30 23:49

>>92
Do we really have a rockstar manager on our /prog/?

Name: Anonymous 2016-05-01 6:08

>>93
Are you going to go through all the files of humanity and convert the non-UTF-8 ones? Are you going to force people to use external converter applications to bring them in? Just support the fucking encodings. They're tiny to include.

Name: Anonymous 2016-05-01 14:08

Are you going to force people to use external converter applications to bring them in?
Yes, because they shouldn't have used those encodings to begin with.

Name: Anonymous 2016-05-02 7:04

>>97
And in 30 years, whatever has readily supplanted UTF-8 will say you shouldn't have used UTF-8 to begin with. Go fuck yourself.

Name: Anonymous 2016-05-03 0:04

>>98
Won't happen. UTF-8 is good enough for everyone, even if every emoji codepoint comes in 10 flavors.

Name: Anonymous 2016-05-03 1:02

>>99
Nice dubs bro!

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.

Name: Anonymous 2016-05-04 1:27

>>101
Granted, the Unicode spec is complex. But you can use UTF-8 as an encoding without having to worry about most of the additional technical standards. I mean, you should probably at least normalize input when saving it to a persistent store, but hell - you can just ignore it and fail hard on all kinds of foreign language edge cases like all American software. UTF-8 don't care.

Name: Anonymous 2016-05-04 15:31

>>102
Until you try to get the length of a string, or try to equate strings.

Name: Anonymous 2016-05-04 23:04

>>103
The byte length should be sufficient

Name: Anonymous 2016-05-04 23:45

>>104
...says the person who never had to truly work with Unicode strings.

Name: Anonymous 2016-05-07 8:04

>>105
No. Byte length is sufficient.

Name: Anonymous 2016-05-07 15:22

>>106
Your comprehension is insufficient.

Name: Anonymous 2016-05-07 18:49

>>107
No. The problem specification is insufficient.

Name: Anonymous 2016-05-07 21:55

>>108
No. The flow of cum into my anus is insufficient.

Name: Anonymous 2016-05-09 7:48

>>109
HAX MY ANUS

Name: Anonymous 2016-05-09 9:59

Please read: an urgent appeal to check these trips

Name: Anonymous 2016-05-09 19:28

111
That's pretty neat.

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