Is there a c function that can convert all characters in a string to upper or lower case...

is there a c function that can convert all characters in a string to upper or lower case? the string is encoded in utf-8 and the language im using is c (if possible, i can use another language for this if there's no easy way to do this in c). any library is ok as long as it's not GPL.

Attached: 1566539031940.jpg (720x960, 136K)

Other urls found in this thread:

stackoverflow.com/a/36898054
ssl.icu-project.org/apiref/icu4c/ustring_8h.html#a14740e3b734ffa82205d4762fcacb5e1
ssl.icu-project.org/apiref/icu4c/group__ustring__ustrlen.html#gac4d8a5581fc5bde71d62ebd0a7a84ec5
stackoverflow.com/questions/4607413/c-library-to-convert-unicode-code-points-to-utf8
developer.gnome.org/glib/stable/glib-Unicode-Manipulation.html#g-utf8-strup
justfuckinggoogleit.com/
twitter.com/NSFWRedditVideo

who is that semen demon?

why is the top half of that cola colored in?

there won't be an in-place one. You'll have to update every reference to the string.

first answer my question.
idk.

so you can't see my reflection ;)

Search for yourself faggot

Use toUpper in a loop maybe?

for unicode? i don't think so.

Idk about libraries but can't we convert it to ASCII and add 26 to the value, and convert it back to char?

Just loop through the array you lazy nigger

no
it doesn't work like that user

stackoverflow.com/a/36898054

bro, a unicode char can have more than 1 byte

yeah but if you only need to worry about latin characters, you can just range check. Anything with the first bit flipped will be 127 so it doesn't even fall into the "lower-case" range
the first bit is flipped for all the bytes in a multi-byte char.

True but a utf-8 toupper that ignores something like äÄ is probably not that useful.

I have found something called ICU. Do you think I can use that?

Attached: 1568979628153.png (959x573, 126K)

If you dont mind having to include an entire unicode library: ssl.icu-project.org/apiref/icu4c/ustring_8h.html#a14740e3b734ffa82205d4762fcacb5e1

I guess it's ok. Also, is there an ICU function that can give me the amount of bytes a UTF-8 characters is contained of, given the first byte? I already have this function (I wrote it) but if I can use an ICU function for this why not?

Yeah, it's in the same page on the documentation. similar name to standard c function: ssl.icu-project.org/apiref/icu4c/group__ustring__ustrlen.html#gac4d8a5581fc5bde71d62ebd0a7a84ec5
But it might be more efficient to not calculate the size and instead pass an output buffer that is the size of the input buffer * 2 (i guess uppercase characters cant be more than 2 times longer than lowercase?), or on the safe side input buffer * 4.

#include

void toUp(char *name, int e)
{
int i;
for(i = 0; i < e - 1; ++i)
{
if(name[i] >= 97 && name[i] = 65 && name[i]

that's only ascii, OP asked for utf8

Btw, you can also just use regular c strlen, as it works with utf8 as well.

Oh, I see, how do you even handle utf-8 then?

Hmnmm are you sure this is it? My idea is something like this. For example, б is 0xd0b1. So I need
utf8_char_length(bee[0]);
to return 2.
Nope.

One character can be more than one byte in utf-8.
It's a bit complicated. Depending on the locale, after you convert to uppercase you can end up with more characters than you started with. You need to check the unicode standard and map the lowercase characters to one or more uppercase characters.

Notice that bee[0] is 0xd0.
Then it's not what I need.

Yeah there is ICU function for that if you look through the documentation. But why do you want to do that? you dont need that to uppercase a string. ICU can do everything you want with unicode

What should I pass for locale btw?

Bro.....

Attached: 2.jpg (490x736, 105K)

The uppercase can change depending on the locale you pass, so you would want something that fits whatever you want to do. I believe you can pass an empty string and it should work as you expect.

Just do a foor loop and sum the char difference between upper and lower

>Just do a foor loop and sum the char difference between upper and lower

Attached: 1567446943098.png (168x300, 7K)

Foor loops are my favorite, waaay better than those shitty for loops.

I'd loop around those milkies.

Attached: IMG_20190911_160636.jpg (1080x1290, 185K)

forr loops are proven to be superior to any other kind of loops

Since recursive functions can do that, and they are turing complete, and C is also turing complete, than you can comclude that such a C function does indeed exist. Q.E.D.

So I started using ICU and how much memory should I allocate for the converted UChar* string? 4, 6 or 12 times more?

Attached: girlwithflowers.jpg (289x540, 27K)

>nobody in this thread understands strings beyond ASCII char arrays

Attached: caveman_cs.png (287x176, 8K)

for (i = 0; string[i]; i++) string[i] = tolower(string[i]);

They are the same with more bytes moron

That's not fair, I understand UTF formats. I just fundamentally do not know what "Upper Case" and "Lower Case" means from the perspective of other languages and character sets. And I don't really want to know, the point of unicode libraries and culture helpers is it does that shit for me.

1. embed python3 interpreter
2. put your c string on the python stack
3. upper case it there
4. return it to c stack

Attached: 1547719731408.png (371x532, 281K)

awk '{print toupper($0)}'
You can use system to use it in a C program.
Why would we care about other strings? Utf8 is just superfluous complicated bloat that does nothing but allow foreigners to misuse our invention.

>Why would we care about other strings? Utf8 is just superfluous complicated bloat that does nothing but allow foreigners to misuse our invention.
I \xF0\x9F\x92\xA9 on your dumb ascii.

That's fair. Most people on this thread are telling OP to just do an ASCII upper case conversion though

s = 'op is gay'
print(s.lower(), s.upper())


C BTFO by the chad Python :^)

Use ctype, it exists for a reason. Calling printf every char isn't efficient.

>that does nothing but allow foreigners to misuse our invention.
based and redpilled

>string.upper in Lua
and anons keep praising C
my sides

How about you read the wikipedia article on UTF-8 and then get back to us

based lua

Is there a specific alphabet you are working on?

lua is basically a C API. based retards.

>no dude this is not a list of characters, its a list of characters but bigger!

Wow you just have to add a if string < 128 wtf everything is different

I have a possible solution, but fellow user, you should be able to figure this simple problem out for yourself.
That'll make you grow as a programmer and as a person.

There are upper and lower-cased characters outside of the ASCII range...

Just omit those literally :^)

>t. doesn't know the answer either
cringe

See the below replies

I have already figured it out. Using ICU. Now how to compile this with GCC? I get undefined references, it surely needs some additional -l flags?

map toUpper x

Oh wait, you're using a shitty language. My bad.

Someone had to create the algorithm for you, so, it's you that's shitty.

god i wish that were me

C is a bare bones lower level programming language. You would have to build your own function or just find one from github. Alternately, use Golang.

>iterate through string
>if >64 and if >96 and Ignore the rest

1. Convert utf8 to ascii
2. +- 32
3. Convert back to utf8

stackoverflow.com/questions/4607413/c-library-to-convert-unicode-code-points-to-utf8

all the utf8 latin upper/lowercase letters are offset from each other by 30 or something, just google the number and add it to the char

Also skip 1 char if you read the unicode special character marker

Also its 32, not 26, my bad

>look me! me so clever!
Just use ctype, faggot.

Poor solition. If he's using utf8 he's probably using non-ASCII letters.

If you don't mind having glib as a dependency there is a function for that. If you are using GTK+, glib is required anyway, so you might as well use it.

developer.gnome.org/glib/stable/glib-Unicode-Manipulation.html#g-utf8-strup

They're just memeing at that point. Nobody really can be this dumb.

Well, user?

>is there a c function that can convert all characters in a string to upper or lower case?

Of course, and you can find it, and other amazing things, here:
justfuckinggoogleit.com/