Hi,
I need to be able to tell if a character in the ISO-8859-15 codeset
(i.e. 8-bit ASCII, incorporating things like accented 'a' or euro currency
symbol) is printable. Ordinarily I'd use isprint(), but obviously this is
only going to work for 7-bit "true ASCII" characters.
I've thought of running the program in a different locale, but I want to
catch *all* printable characters, not only those used by a specific
locale. It'd be nice for the code to be as portable as possible, too.
I could just write a macro to range-check the character (it's not like the
standard's going to change), but I'd prefer a cleaner way if possible!
All help gratefully appreciated.
Cheers
- Ian
--
Ian Chard <ia*@tanagra.demon.co.uk>
"Resting" Unix systems administrator and RHCE
near Linlithgow, central Scotland 9 4440
"Ian Chard" <ia*@tanagra.demon.co.uk> writes: I need to be able to tell if a character in the ISO-8859-15 codeset (i.e. 8-bit ASCII, incorporating things like accented 'a' or euro currency symbol) is printable.
#define IS_ISO_8859_15(c) \
(((unsigned char)(c) >= 0x20 && (unsigned char)(c) < 0x7F) \
|| ((unsigned char)(c) >= 0xA0 && (unsigned char)(c) <= 0xFF))
or the function equivalent if a macro is not acceptable.
Ordinarily I'd use isprint(), but obviously this is only going to work for 7-bit "true ASCII" characters.
Actually, it is locale dependent how isprint behaves.
I've thought of running the program in a different locale, but I want to catch *all* printable characters, not only those used by a specific locale. It'd be nice for the code to be as portable as possible, too.
If you restrict yourself to a specific character encoding (ISO-8859-15),
the code will obviously not run correctly on systems with incompatible
character encodings. Therefore, it is by definition not portable.
If you want the most portable solution, use `isprint'.
I could just write a macro to range-check the character (it's not like the standard's going to change), but I'd prefer a cleaner way if possible!
If you want to check for a printable character in a portable way, use
`isprint'. If you want to check for a character printable in ISO-8859-15
encoding, use something like the macro above.
Martin
"Ian Chard" <ia*@tanagra.demon.co.uk> wrote in message
news:pa****************************@tanagra.demon. co.uk... I need to be able to tell if a character in the ISO-8859-15 codeset
[snip] I've thought of running the program in a different locale, but I want to catch *all* printable characters, not only those used by a specific locale.
A printable character in one locale may not be in another. In other words,
the concept of a printable character is inherently locale-specific.
You seem to be asking for the logical "or" of isprint() return values for
all possible locales - this does not make sense at all. Perhaps I
misunderstand what you are asking.
Alex
In <bp*************@news.t-online.com> Martin Dickopp <ex****************@zero-based.org> writes: "Ian Chard" <ia*@tanagra.demon.co.uk> writes:
I need to be able to tell if a character in the ISO-8859-15 codeset (i.e. 8-bit ASCII, incorporating things like accented 'a' or euro currency symbol) is printable.
#define IS_ISO_8859_15(c) \ (((unsigned char)(c) >= 0x20 && (unsigned char)(c) < 0x7F) \ || ((unsigned char)(c) >= 0xA0 && (unsigned char)(c) <= 0xFF))
The casts to unsigned char are wrong, drop them. They make
IS_ISO_8859_15(288) return true on any implementation with
UCHAR_MAX == 256.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de Da*****@cern.ch (Dan Pop) writes: In <bp*************@news.t-online.com> Martin Dickopp <ex****************@zero-based.org> writes:
"Ian Chard" <ia*@tanagra.demon.co.uk> writes:
I need to be able to tell if a character in the ISO-8859-15 codeset (i.e. 8-bit ASCII, incorporating things like accented 'a' or euro currency symbol) is printable.
#define IS_ISO_8859_15(c) \ (((unsigned char)(c) >= 0x20 && (unsigned char)(c) < 0x7F) \ || ((unsigned char)(c) >= 0xA0 && (unsigned char)(c) <= 0xFF))
The casts to unsigned char are wrong, drop them. They make IS_ISO_8859_15(288) return true on any implementation with UCHAR_MAX == 256.
Why does that make them wrong? I would expect the above macro to
be documented similar to "expects a char [or unsigned char] as
argument", in which case a caller giving an argument of 288
should /expect/ undefined results in the situation you've
described.
--
Micah J. Cowan mi***@cowan.name
In article <m3************@localhost.localdomain> Micah Cowan <mi***@cowan.name> writes: Da*****@cern.ch (Dan Pop) writes:
....#define IS_ISO_8859_15(c) \ (((unsigned char)(c) >= 0x20 && (unsigned char)(c) < 0x7F) \ || ((unsigned char)(c) >= 0xA0 && (unsigned char)(c) <= 0xFF))
The casts to unsigned char are wrong, drop them. They make IS_ISO_8859_15(288) return true on any implementation with UCHAR_MAX == 256.
Why does that make them wrong? I would expect the above macro to be documented similar to "expects a char [or unsigned char] as argument",
That is *not* the wording for "isprint" and friends. There the argument is
an int with a value that is representable as unsigned char, or is EOF.
IS_ISO_8859_15(EOF) most likely will yield true.
in which case a caller giving an argument of 288 should /expect/ undefined results in the situation you've described.
Note that "isascii" is a common extension which expects an arbitrary
integer. Your macro more resembles isprint. And wouldn't it be easier
to just use "setlocale"?
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
In <m3************@localhost.localdomain> Micah Cowan <mi***@cowan.name> writes: Da*****@cern.ch (Dan Pop) writes:
In <bp*************@news.t-online.com> Martin Dickopp <ex****************@zero-based.org> writes:
>"Ian Chard" <ia*@tanagra.demon.co.uk> writes: > >> I need to be able to tell if a character in the ISO-8859-15 codeset >> (i.e. 8-bit ASCII, incorporating things like accented 'a' or euro currency >> symbol) is printable. > >#define IS_ISO_8859_15(c) \ > (((unsigned char)(c) >= 0x20 && (unsigned char)(c) < 0x7F) \ > || ((unsigned char)(c) >= 0xA0 && (unsigned char)(c) <= 0xFF))
The casts to unsigned char are wrong, drop them. They make IS_ISO_8859_15(288) return true on any implementation with UCHAR_MAX == 256.
Why does that make them wrong? I would expect the above macro to be documented similar to "expects a char [or unsigned char] as argument", in which case a caller giving an argument of 288 should /expect/ undefined results in the situation you've described.
Since I haven't seen the documentation of IS_ISO_8859_15, I would expect
it to do the job advertised by its name.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
"Dik T. Winter" <Di********@cwi.nl> writes: In article <m3************@localhost.localdomain> Micah Cowan <mi***@cowan.name> writes: > Da*****@cern.ch (Dan Pop) writes: ... > > >#define IS_ISO_8859_15(c) \ > > > (((unsigned char)(c) >= 0x20 && (unsigned char)(c) < 0x7F) \ > > > || ((unsigned char)(c) >= 0xA0 && (unsigned char)(c) <= 0xFF)) > > > > The casts to unsigned char are wrong, drop them. They make > > IS_ISO_8859_15(288) return true on any implementation with > > UCHAR_MAX == 256. > > Why does that make them wrong? I would expect the above macro to > be documented similar to "expects a char [or unsigned char] as > argument",
That is *not* the wording for "isprint" and friends. There the argument is an int with a value that is representable as unsigned char, or is EOF. IS_ISO_8859_15(EOF) most likely will yield true.
I didn't say it was. The above is not isprint(). I do agree that
it should probably act the same way as isprint()--but it wouldn't
have to. Handling 288 correctly, though (assuming it's out of
range for an unsigned char) is not something one should expect of
isprint(), either. > in which case a caller giving an argument of 288 > should /expect/ undefined results in the situation you've > described.
Note that "isascii" is a common extension which expects an arbitrary integer. Your macro more resembles isprint. And wouldn't it be easier to just use "setlocale"?
Not my macro. And I agree about setlocale().
--
Micah J. Cowan mi***@cowan.name Da*****@cern.ch (Dan Pop) writes: In <m3************@localhost.localdomain> Micah Cowan <mi***@cowan.name> writes:
Why does that make them wrong? I would expect the above macro to be documented similar to "expects a char [or unsigned char] as argument", in which case a caller giving an argument of 288 should /expect/ undefined results in the situation you've described.
Since I haven't seen the documentation of IS_ISO_8859_15, I would expect it to do the job advertised by its name.
Fair enough: perhaps this should serve as a reminder to all that,
no matter how small their example, they should always specify
exactly *how* it is meant be used, even if you think it should be
obvious from reading.
--
Micah J. Cowan mi***@cowan.name
in comp.lang.c i read: I need to be able to tell if a character in the ISO-8859-15 codeset (i.e. 8-bit ASCII, incorporating things like accented 'a' or euro currency symbol) is printable. Ordinarily I'd use isprint(), but obviously this is only going to work for 7-bit "true ASCII" characters.
isprint will work fine if the locale is set appropriately.
I've thought of running the program in a different locale, but I want to catch *all* printable characters, not only those used by a specific locale.
on most systems a uni/single-byte character sequence cannot compose all
possible printable characters, char having a range well below that
necessary for even the small number of unique characters in the iso-8859-x
repertoires. for this to be possible you need multi-byte character
sequences.
yet if your stream contains mbcs then isprint is totally inappropriate, you
need to convert to a wchar_t or wint_t and use iswprint, and the conversion
demands that the locale be set appropriately.
--
a signature This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John |
last post by:
Is there an equivalent of COM on Linux that I can get through Python.
My need is to have some sort of language independent component
framework. I can think of CORBA but I have to have a server...
|
by: Michael Foord |
last post by:
Please pardon my ignorance on this one - but I'm not certain how the
sign bt is treated in python bitwise operators. I've trying to convert
a javascript DES encryption routine into python.
...
|
by: Robert Dodier |
last post by:
Hello,
Here's a thought that I'm sure has already occurred to
someone else, I just can't find any record of it yet.
An XML document is just a more verbose and clumsy representation
of an...
|
by: SunRise |
last post by:
Hi
I am creating a C Program , to extract
only-Printable-characters from a file ( any type of file) and display
them.
OS: Windows-XP
Ple help me to fix the Errors & Warnings and explain...
|
by: Tim Conner |
last post by:
Hi,
I am an ex-delphi programmer, and I having a real hard time with the
following simple code (example ):
Which is the equivalent to the following code ?
var
chars : PChar;
sBack, s :...
| |
by: Jaga |
last post by:
1.)
I am using C#. Is there any similar function to isprint in C?
2.)
If I trap the event OnKeyDown in a Control, I become a
System.Windows.Forms.KeyEventArgs.
How can I determine whether...
|
by: karch |
last post by:
How would this C# contruct be represented in C++/CLI? Or is it even
possible?
PolicyLevel level = (enumerator->Current) as PolicyLevel;
Thanks,
Karch
|
by: Alan Silver |
last post by:
Hello,
I'm converting some old VB6 code to use with ASP.NET and have come
unstuck with the Asc() function. This was used in the old VB6 code to
convert a character to its ASCII numeric...
|
by: grid |
last post by:
Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |