473,614 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it OK to include an ANSI file into a UTF-8 file?

aa
Is it OK to include an ANSI file into a UTF-8 file?
Jul 17 '05 #1
3 3376
aa <aa@virgin.ne t> wrote:
Is it OK to include an ANSI file into a UTF-8 file?


What is an ANSI file?

But the answer is obviuos, as long as the ANSI file is to the utf8
conventions the inclusion results in valid utf8.

So is it valid utf8? man utf-8:
<q>
PROPERTIES
The UTF-8 encoding has the following nice properties:

* UCS characters 0x00000000 to 0x0000007f (the classic US-ASCII charac-
ters) are encoded simply as bytes 0x00 to 0x7f (ASCII compatibility).
This means that files and strings which contain only 7-bit ASCII
characters have the same encoding under both ASCII and UTF-8.

* All UCS characters > 0x7f are encoded as a multi-byte sequence con-
sisting only of bytes in the range 0x80 to 0xfd, so no ASCII byte can
appear as part of another character and there are no problems with
e.g. '\0' or '/'.
[...]
* The bytes 0xfe and 0xff are never used in the UTF-8 encoding.

* The first byte of a multi-byte sequence which represents a single
non-ASCII UCS character is always in the range 0xc0 to 0xfd and indi-
cates how long this multi-byte sequence is. All further bytes in a
multi-byte sequence are in the range 0x80 to 0xbf. This allows easy
resynchronizati on and makes the encoding stateless and robust against
missing bytes.
[...]

ENCODING
The following byte sequences are used to represent a character. The
sequence to be used depends on the UCS code number of the character:

0x00000000 - 0x0000007F:
0xxxxxxx

0x00000080 - 0x000007FF:
110xxxxx 10xxxxxx

0x00000800 - 0x0000FFFF:
1110xxxx 10xxxxxx 10xxxxxx

0x00010000 - 0x001FFFFF:
11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

0x00200000 - 0x03FFFFFF:
111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx

0x04000000 - 0x7FFFFFFF:
1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx

The xxx bit positions are filled with the bits of the character code
number in binary representation. Only the shortest possible multi-byte
sequence which can represent the code number of the character can be
used.

The UCS code values 0xd800-0xdfff (UTF-16 surrogates) as well as 0xfffe
and 0xffff (UCS non-characters) should not appear in conforming UTF-8
streams.
</q>

But why simply include so it might go wrong (now or in the future), when
you can use the mbstring/iconv functions to correctly convert whatever
is in the the include file to valid utf-8!

--

Daniel Tryba

Jul 17 '05 #2
aa
Thanks, Daniel, for the most comprehensive answer.
Just to check if I understand you correctly:
As ASCII characters have the same encoding under both ASCII and UTF-8 and
no ASCII byte can
appear as part of another character of UTF-8, then an ASCII included
into a UTF-8 file will be interpreted correctly.

Regarding ANSI - this is not my field and if I am wrong, please correct me.
I believe that ANSI it is 8 bit code i.e. 256 combinatons
The first 128 ( bytes 0x00 to 0x7f ) are ASCII. The remaining 128 bytes
(0x80 to 0xff ) can be interpreted as anything depending on the code table
applied. The code table applied depends on the OS system code page. If, for
example it is set to 850 then these are Western European characters like
French apostrophe or German double dot over letters etc.
If the system code page is set to 866, the last half is interpreted as
Cyrillics.
Also the system code page interpretation can be overruled by setting of
charset attribute in an HTML file or by encoding settings in the browser.

If my guesses above are correct, then what will happen to an ANSI file if
it is included into a UTF-8 file?
Using your terminology, how bytes 0x80 to 0xff will be interpreted?

"Daniel Tryba" <ne************ ****@canopus.nl > wrote in message
news:ck******** **@news.tue.nl. ..
aa <aa@virgin.ne t> wrote:
Is it OK to include an ANSI file into a UTF-8 file?
What is an ANSI file?

But the answer is obviuos, as long as the ANSI file is to the utf8
conventions the inclusion results in valid utf8.

So is it valid utf8? man utf-8:
<q>
PROPERTIES
The UTF-8 encoding has the following nice properties:

* UCS characters 0x00000000 to 0x0000007f (the classic US-ASCII

charac- ters) are encoded simply as bytes 0x00 to 0x7f (ASCII compatibility). This means that files and strings which contain only 7-bit ASCII characters have the same encoding under both ASCII and UTF-8.

* All UCS characters > 0x7f are encoded as a multi-byte sequence con- sisting only of bytes in the range 0x80 to 0xfd, so no ASCII byte can appear as part of another character and there are no problems with e.g. '\0' or '/'.
[...]
* The bytes 0xfe and 0xff are never used in the UTF-8 encoding.

* The first byte of a multi-byte sequence which represents a single non-ASCII UCS character is always in the range 0xc0 to 0xfd and indi- cates how long this multi-byte sequence is. All further bytes in a multi-byte sequence are in the range 0x80 to 0xbf. This allows easy resynchronizati on and makes the encoding stateless and robust against missing bytes.
[...]

ENCODING
The following byte sequences are used to represent a character. The sequence to be used depends on the UCS code number of the character:
0x00000000 - 0x0000007F:
0xxxxxxx

0x00000080 - 0x000007FF:
110xxxxx 10xxxxxx

0x00000800 - 0x0000FFFF:
1110xxxx 10xxxxxx 10xxxxxx

0x00010000 - 0x001FFFFF:
11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

0x00200000 - 0x03FFFFFF:
111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx

0x04000000 - 0x7FFFFFFF:
1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx

The xxx bit positions are filled with the bits of the character code number in binary representation. Only the shortest possible multi-byte sequence which can represent the code number of the character can be used.

The UCS code values 0xd800-0xdfff (UTF-16 surrogates) as well as 0xfffe and 0xffff (UCS non-characters) should not appear in conforming UTF-8 streams.
</q>

But why simply include so it might go wrong (now or in the future), when
you can use the mbstring/iconv functions to correctly convert whatever
is in the the include file to valid utf-8!

--

Daniel Tryba

Jul 17 '05 #3
aa <aa@virgin.ne t> wrote:
If my guesses above are correct, then what will happen to an ANSI file if
it is included into a UTF-8 file?
Using your terminology, how bytes 0x80 to 0xff will be interpreted?


That is undefined, it might result in a legal utf8 sequence, propably
will not.

I guess it could result in parse errrors in php code.

If this should happen in a string the was send to the browsers, the
illegal sequence will probably be displayed as an '?' or the unicode
char for an illegal char: http://www.unicode.org/charts/img/UFFFD.gif

[snipping 97 useless lines]

--

Daniel Tryba

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
9927
by: Michael L. | last post by:
Hi there, How can I convert an ANSI string to utf-8 ? Thanks!
4
2284
by: bibsoconner | last post by:
Hi, I hope someone can please help me. I'm having a lot of trouble with schema files in .NET. I have produced a very simple example that uses "include" to include other schema files. It all works with SPY, but when I pick "Validate Schema" from the .NET 2003 menu, it fails with message: "Type XType is not declared." As I hinted at in my subject line, I suspect that it has to do with including another schema multiple times.
0
1519
by: Eric Giguere | last post by:
Back in August of 1990 I posted to the comp.std.c newsgroup a document I had written entitled "The ANSI Standard: A Summary for the C Programmer". I have converted it to HTML and reposted it as a historical curiosity on my website at this URL: http://www.ericgiguere.com/articles/ansi-c-summary.html The original posting is still available via Google if you prefer that:
9
6404
by: zolli | last post by:
Hi, I've been banging my head against this for a while now. Hoping someone here can shed some light on what's going on. On including stdlib.h in a file, I'm seeing the following errors: ----BEGIN ERRORS---- gcc -g3 -DUSE_LIBC -Wall -c -I../mm -I../include -I/usr/include -I/usr/include/linux -o mm_tree_test.o mm_tree_test.c
0
1740
by: JJayaprakash | last post by:
Hi, help me to convert characters from Ansi to UTF-8. I have been trying by using System.Text.Encoding.Convert to change the bytes from Ansi to UTF-8. The characters get converted into something which is not expected. I mean the chinese characters showing up after the byte convertion and desired are different. They are having symbolic characters along with the chinese characters. Hoping some one has a clue or code, which can help me.
1
23446
by: JJayaprakash | last post by:
Hi, help me to convert characters from Ansi to UTF-8. I have been trying by using System.Text.Encoding.Convert to change the bytes from Ansi to UTF-8. It is getting converted to different chinese along with the unicode symbols.
1
7901
by: Markus | last post by:
Hello I try to write RTF files using text in UTF-8 encoding. Converting the text with utf8_decode() already fails on characters such as an apostrophe or an endash. Of course non-Latin-1 characters would go lost. Trying to understand the RTF spec I found that ISO-8859-1 is not available in RTF, but only the Windows 1252 codepage which differs from Latin-1 in some characters. So I set the codepage to 1252 and learned that characters not...
1
4319
by: Tejas | last post by:
Hi, I am using ldap_get_values() call to get the user attributes from LDAP. This call is returning the user attributes in UTF-8 encoding and its a PCHAR*. For normal English characters this is working well. When Multibyte characters are involved like Japanese, Chinese or Korean, I need to convert UTF8 to ANSI encoding to get the correct values.
1
6242
by: Gandalf | last post by:
I used sqliteadmin to manage my sqlite database and I copy past queries translated from mysql phpmyadmin output it worked (little slowly but worked...), the only problem now is that sqliteadmin stored my hebrew char as ANSI instead of UTF-8 and now I don't know how to search data from this table. How can I convert my database string from ANSI to UTF-8 Thanks!
10
1621
by: silverbob | last post by:
I am replacing my Javascript-called files with SSI, and I'm getting an unexpected result with my page footer. I can really use some help with this. The footer contains a copyright (left justified), and page links (right justfied) all on the same line. After changing to SSI, the right side links are correct, but the left side copyright looks to be wrapping to the next line. I can fix this in IE by moving it back up in line with the...
0
8179
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8124
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8621
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8272
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7050
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6087
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4049
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4119
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1712
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.