Usage of isleadbyte()

T

Tobias

Hey Guys

I'm programming a map which redefines some Unicode Characters like Äš
to the "normal" letter E, just for fun. My question is now how the
detailed usage of isleadbyte() works. I have some code here:
______________
/// gsUCHAR_CONVMAP is a tuple of char and char[] where the replacers an the map is defined.

std::string unicodevert(char ArrayToTransform[])
{
char *ToConv = ArrayToTransform; // Points ToConv on ConvSource
char *ptr; // iterating Pointer
char *anotherHelper;
for(int i=0; i <= 38; i++) { // * Do it for every Map table
ptr = strpbrk(ToConv,gsUCHAR_CONVMAP.MAP); // * Jump to first char to correct
while(NULL != ptr) // * Do this for the full string
{
if( isleadbyte(atoi(ptr)) = 0 )
ptr = strpbrk((ptr+2),gsUCHAR_CONVMAP.MAP);
else
{
memmove_s(ptr++, sizeof(*ptr), ptr++, sizeof(*ptr));
*ptr = gsUCHAR_CONVMAP.REPLACER; // ** Sóurce Char is
ptr = strpbrk(ptr++,gsUCHAR_CONVMAP.MAP); // ** Jump to
}
}
}
return (std::string)ToConv; //Returns the converted string in a String.
}

_____________

So, this is my problem:
if( isleadbyte(atoi(ptr)) = 0 )
I'd like to know if the char "ptr" is points to is a leadbyte or not.


best regards,
TSchmitt
 
T

Tobias

And isleadbyte() is part of the C++ standard library, or ...?  I never
heard of it and your example code doesn't #include anything,

/Jorgen

PS. Learn about const correctness.

Thanks for help!!!

Yes it is included in the standard library. My include is just
<iostream>. I also forgot to say that i use Visual Studio 2010 with an
empty Windows Console program template.
http://msdn.microsoft.com/de-de/library/dawbheet(VS.80).aspx This is
the MSDN page of the function. But I still dont get it, why i have to
pass an interger into a function, which is built to say me if the
parameter is an leadbyte. I also tried to pass &pointer, but it doesnt
work
 
T

tschmittldk

Thanks for help!!!

Yes it is included in the standard library. My include is just
<iostream>. I also forgot to say that i use Visual Studio 2010 with an
empty Windows Console program template.http://msdn.microsoft.com/de-de/library/dawbheet(VS.80).aspxThis is
the MSDN page of the function. But I still dont get it, why i have to
pass an interger into a function, which is built to say me if the
parameter is an leadbyte. I also tried to pass &pointer, but it doesnt
work- Zitierten Text ausblenden -

- Zitierten Text anzeigen -


So I already finished my method. Its working "fine" now, no problems
with the datatypes either. But i still have the problem, that
isleadbyte() always returns 0:

while(NULL != ptr)
}
if(0 == isleadbyte((int)*ptr))
{
ptr++;
ptr = strpbrk(ptr,gsUCHAR_CONVMAP.MAP);
}
else
{
memmove_s(ptr++, sizeof(*ptr), ptr++, sizeof(*ptr));
*ptr = gsUCHAR_CONVMAP.REPLACER;
ptr = strpbrk(ptr++,gsUCHAR_CONVMAP.MAP);
}
}

The conversion (int)*ptr works fine. btw the pointer points to char[]:
"\xc4\xa8\xc4\xaa\xc4\xac\xc4\xae\xc4\xa5\xc4\xa7
\xc4\x81\xc4\x83\xc4\x85" (it's a bunch of doublebyte chars. But no
matter on which of the single bytes the pointer points, he thinks it's
no leadbyte anyway. I'm getting really frustrated...
 
J

James Kanze

Yes it is included in the standard library.

No it is not. It sounds like it has something to do with UTF-8,
maybe, but I don't know. It's not mentionned in either C++03 or
the current draft of C++0x. It might be a Windows specific
function, or a function from some other library you're using, or
for all I know, a function you wrote yourself.
My include is just
<iostream>. I also forgot to say that i use Visual Studio 2010 with an
empty Windows Console program template.http://msdn.microsoft.com/de-de/library/dawbheet(VS.80).aspx
This is the MSDN page of the function.

So it's something specifically Windows.
But I still dont get it, why i have to pass an interger into
a function, which is built to say me if the parameter is an
leadbyte.

Just guessing, but it might be following the classical Unix
idiom, which uses int's to contain a character (in the range
0...UCHAR_MAX) *or* EOF (which must be negative), see for
example the functions in <ctype.h>. In that case, passing it
a char will result in undefined behavior, in a lot of cases,
because the range of char often contains negative values not
equal to EOF. Practically speaking, with such functions, you
have to cast your char to unsigned char before passing it.
I also tried to pass &pointer, but it doesnt
work

If the function expects an int, you can't pass it a pointer.
 
J

Jorgen Grahn

Yes it is included in the standard library. My include is just
<iostream>. I also forgot to say that i use Visual Studio 2010 with an
empty Windows Console program template.

I suspect that you are wrong. My system doesn't have it, and Google
only returns hits from Microsoft and a few oddball DOS compatibility
vendors ...

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top