selectiveencode.c revision 04bdb234571448ed6194e1d4048e6512f2446f1c
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updaterstatic char *rcsid = "$Id: selectiveencode.c,v 1.7 2000/09/20 02:47:32 ishisone Exp $";
0b062f4990db5cc6db2fe3398926f71b92a67407Brian Wellington * Copyright (c) 2000 Japan Network Information Center. All rights reserved.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * By using this file, you agree to the terms and conditions set forth bellow.
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews * LICENSE TERMS AND CONDITIONS
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews * The following License Terms and Conditions apply, unless a different
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews * license is obtained from Japan Network Information Center ("JPNIC"),
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews * a Japanese association, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews * Tokyo, Japan.
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater * 1. Use, Modification and Redistribution (including distribution of any
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * modified or derived work) in source and/or binary forms is permitted
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * under this License Terms and Conditions.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 2. Redistribution of source code must retain the copyright notices as they
ca67ebfe9eef0b8f04179f7e511a19e0337a5422Automatic Updater * appear in each source code file, this License Terms and Conditions.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 3. Redistribution in binary form must reproduce the Copyright Notice,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * this License Terms and Conditions, in the documentation and/or other
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * materials provided with the distribution. For the purposes of binary
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * distribution the "Copyright Notice" refers to the following language:
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * "Copyright (c) Japan Network Information Center. All rights reserved."
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 4. Neither the name of JPNIC may be used to endorse or promote products
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * derived from this Software without specific prior written approval of
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
ad671240d635376dd8681550eebee799d2e3d1fdAutomatic Updater * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
ad671240d635376dd8681550eebee799d2e3d1fdAutomatic Updater * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ad671240d635376dd8681550eebee799d2e3d1fdAutomatic Updater * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
ad671240d635376dd8681550eebee799d2e3d1fdAutomatic Updater * 6. Indemnification by Licensee
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Any person or entities using and/or redistributing this Software under
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * this License Terms and Conditions shall defend indemnify and hold
3acf5eb97cebc2ba868e6ac4a4e01e6d1be0c892Automatic Updater * harmless JPNIC from and against any and all judgements damages,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * expenses, settlement liabilities, cost and other liabilities of any
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * kind as a result of use and redistribution of this Software or any
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * claim, suite, action, litigation or proceeding by any third party
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * arising out of or relates to this License Terms and Conditions.
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater * 7. Governing Law, Jurisdiction and Venue
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater * This License Terms and Conditions shall be governed by and and
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater * construed in accordance with the law of Japan. Any person or entities
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater * using and/or redistributing this Software under this License Terms and
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater * Conditions hereby agrees and consent to the personal and exclusive
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater * jurisdiction and venue of Tokyo District Court of Japan.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinstatic int is_domain_delimiter(char c);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinstatic char *find_nonascii(const char *s);
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater assert(s != NULL && startp != NULL && endp != NULL);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein TRACE(("mdn_selectiveencode_findregion(s=\"%s\")\n",
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater * Scan the specified string looking for non-ascii character.
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if ((non_ascii = find_nonascii(s)) == NULL)
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater * Non-ascii character found.
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater * Determine the region to encode.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * First, we scan backwards to find the beginning of the region
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * that should be converted.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein while (start > s) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein char *prev = mdn_utf8_findfirstbyte(start - 1, s);
2f8d63983c297c62630044d28a6f66676b4d339dMark Andrews break; /* Found */
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater * Next we scan forwards looking for the end of the region.
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater end = non_ascii + mdn_utf8_mblen(non_ascii);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater return ((unsigned char)c < 0x80 &&
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater while (*s != '\0' && (unsigned char)*s < 0x80)
64affc54f96a2c71cbd10ed71e246ce0746259aaAutomatic Updater if (*s == '\0')
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return ((char *)s);