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.de mon.co.uk>
"Resting" Unix systems administrator and RHCE
near Linlithgow, central Scotland 9 4445
"Ian Chard" <ia*@tanagra.de mon.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.de mon.co.uk> wrote in message
news:pa******** *************** *****@tanagra.d emon.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.de mon.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.de mon.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.nam e
In article <m3************ @localhost.loca ldomain> Micah Cowan <mi***@cowan.na me> 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.loca ldomain> Micah Cowan <mi***@cowan.na me> writes: Da*****@cern.c h (Dan Pop) writes:
In <bp************ *@news.t-online.com> Martin Dickopp <ex************ ****@zero-based.org> writes:
>"Ian Chard" <ia*@tanagra.de mon.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.loca ldomain> Micah Cowan <mi***@cowan.na me> 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.nam e Da*****@cern.ch (Dan Pop) writes: In <m3************ @localhost.loca ldomain> Micah Cowan <mi***@cowan.na me> 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.nam e
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 running. I
prefer not to. I just need Python components for local consumption in
other languages. I remember Gnome libs having some thing like this....
|
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.
Javascritp has >>> and >>. >>> is a zero fill bit shift whereas >> is
a sign propagating bit shift. My understanding is that the python >>
is equivalent...
|
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 ordinary Lisp S-expression. So it's easy enough to translate
some XML into equivalent Lisp. Now I turn it over to the Lisp
parser, which creates the...
|
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 how to use
Command-Line Arguments inside C program.
|
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 : String;
| |
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 the key in the KeyEventArgs a printable char is?
Thanks in advance
|
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 equivalent.
Is there such a function available in C#? I can see that VB.NET has one,
but I couldn't see how to get at it in C#.
For example, if I have...
|
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 both statements are
similar :
*((char **)v)++ == *((char **)v++)
Where v is a pointer to an array of characters,defined as
char *v;
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |