- upgrade libidn
This commit is contained in:
1 parent
2b8d4ff66b
commit
9ef9394bd0
1015 files changed
+44748
-132401
No files matched your search
Generated
+395
@@ -0,0 +1,395 @@
|
||||
/* Character handling in C locale.
|
||||
|
||||
Copyright 2000-2003, 2006, 2009-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#define NO_C_CTYPE_MACROS
|
||||
#include "c-ctype.h"
|
||||
|
||||
/* The function isascii is not locale dependent. Its use in EBCDIC is
|
||||
questionable. */
|
||||
bool
|
||||
c_isascii (int c)
|
||||
{
|
||||
return (c >= 0x00 && c <= 0x7f);
|
||||
}
|
||||
|
||||
bool
|
||||
c_isalnum (int c)
|
||||
{
|
||||
#if C_CTYPE_CONSECUTIVE_DIGITS \
|
||||
&& C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
#if C_CTYPE_ASCII
|
||||
return ((c >= '0' && c <= '9')
|
||||
|| ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z'));
|
||||
#else
|
||||
return ((c >= '0' && c <= '9')
|
||||
|| (c >= 'A' && c <= 'Z')
|
||||
|| (c >= 'a' && c <= 'z'));
|
||||
#endif
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case '0': case '1': case '2': case '3': case '4': case '5':
|
||||
case '6': case '7': case '8': case '9':
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
|
||||
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
|
||||
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
|
||||
case 'Y': case 'Z':
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
|
||||
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
|
||||
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
|
||||
case 'y': case 'z':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
c_isalpha (int c)
|
||||
{
|
||||
#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
#if C_CTYPE_ASCII
|
||||
return ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z');
|
||||
#else
|
||||
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
|
||||
#endif
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
|
||||
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
|
||||
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
|
||||
case 'Y': case 'Z':
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
|
||||
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
|
||||
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
|
||||
case 'y': case 'z':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
c_isblank (int c)
|
||||
{
|
||||
return (c == ' ' || c == '\t');
|
||||
}
|
||||
|
||||
bool
|
||||
c_iscntrl (int c)
|
||||
{
|
||||
#if C_CTYPE_ASCII
|
||||
return ((c & ~0x1f) == 0 || c == 0x7f);
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case ' ': case '!': case '"': case '#': case '$': case '%':
|
||||
case '&': case '\'': case '(': case ')': case '*': case '+':
|
||||
case ',': case '-': case '.': case '/':
|
||||
case '0': case '1': case '2': case '3': case '4': case '5':
|
||||
case '6': case '7': case '8': case '9':
|
||||
case ':': case ';': case '<': case '=': case '>': case '?':
|
||||
case '@':
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
|
||||
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
|
||||
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
|
||||
case 'Y': case 'Z':
|
||||
case '[': case '\\': case ']': case '^': case '_': case '`':
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
|
||||
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
|
||||
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
|
||||
case 'y': case 'z':
|
||||
case '{': case '|': case '}': case '~':
|
||||
return 0;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
c_isdigit (int c)
|
||||
{
|
||||
#if C_CTYPE_CONSECUTIVE_DIGITS
|
||||
return (c >= '0' && c <= '9');
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case '0': case '1': case '2': case '3': case '4': case '5':
|
||||
case '6': case '7': case '8': case '9':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
c_islower (int c)
|
||||
{
|
||||
#if C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
return (c >= 'a' && c <= 'z');
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
|
||||
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
|
||||
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
|
||||
case 'y': case 'z':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
c_isgraph (int c)
|
||||
{
|
||||
#if C_CTYPE_ASCII
|
||||
return (c >= '!' && c <= '~');
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case '!': case '"': case '#': case '$': case '%': case '&':
|
||||
case '\'': case '(': case ')': case '*': case '+': case ',':
|
||||
case '-': case '.': case '/':
|
||||
case '0': case '1': case '2': case '3': case '4': case '5':
|
||||
case '6': case '7': case '8': case '9':
|
||||
case ':': case ';': case '<': case '=': case '>': case '?':
|
||||
case '@':
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
|
||||
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
|
||||
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
|
||||
case 'Y': case 'Z':
|
||||
case '[': case '\\': case ']': case '^': case '_': case '`':
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
|
||||
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
|
||||
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
|
||||
case 'y': case 'z':
|
||||
case '{': case '|': case '}': case '~':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
c_isprint (int c)
|
||||
{
|
||||
#if C_CTYPE_ASCII
|
||||
return (c >= ' ' && c <= '~');
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case ' ': case '!': case '"': case '#': case '$': case '%':
|
||||
case '&': case '\'': case '(': case ')': case '*': case '+':
|
||||
case ',': case '-': case '.': case '/':
|
||||
case '0': case '1': case '2': case '3': case '4': case '5':
|
||||
case '6': case '7': case '8': case '9':
|
||||
case ':': case ';': case '<': case '=': case '>': case '?':
|
||||
case '@':
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
|
||||
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
|
||||
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
|
||||
case 'Y': case 'Z':
|
||||
case '[': case '\\': case ']': case '^': case '_': case '`':
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
|
||||
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
|
||||
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
|
||||
case 'y': case 'z':
|
||||
case '{': case '|': case '}': case '~':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
c_ispunct (int c)
|
||||
{
|
||||
#if C_CTYPE_ASCII
|
||||
return ((c >= '!' && c <= '~')
|
||||
&& !((c >= '0' && c <= '9')
|
||||
|| ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z')));
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case '!': case '"': case '#': case '$': case '%': case '&':
|
||||
case '\'': case '(': case ')': case '*': case '+': case ',':
|
||||
case '-': case '.': case '/':
|
||||
case ':': case ';': case '<': case '=': case '>': case '?':
|
||||
case '@':
|
||||
case '[': case '\\': case ']': case '^': case '_': case '`':
|
||||
case '{': case '|': case '}': case '~':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
c_isspace (int c)
|
||||
{
|
||||
return (c == ' ' || c == '\t'
|
||||
|| c == '\n' || c == '\v' || c == '\f' || c == '\r');
|
||||
}
|
||||
|
||||
bool
|
||||
c_isupper (int c)
|
||||
{
|
||||
#if C_CTYPE_CONSECUTIVE_UPPERCASE
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
|
||||
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
|
||||
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
|
||||
case 'Y': case 'Z':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
c_isxdigit (int c)
|
||||
{
|
||||
#if C_CTYPE_CONSECUTIVE_DIGITS \
|
||||
&& C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
#if C_CTYPE_ASCII
|
||||
return ((c >= '0' && c <= '9')
|
||||
|| ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F'));
|
||||
#else
|
||||
return ((c >= '0' && c <= '9')
|
||||
|| (c >= 'A' && c <= 'F')
|
||||
|| (c >= 'a' && c <= 'f'));
|
||||
#endif
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case '0': case '1': case '2': case '3': case '4': case '5':
|
||||
case '6': case '7': case '8': case '9':
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
c_tolower (int c)
|
||||
{
|
||||
#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
return (c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c);
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case 'A': return 'a';
|
||||
case 'B': return 'b';
|
||||
case 'C': return 'c';
|
||||
case 'D': return 'd';
|
||||
case 'E': return 'e';
|
||||
case 'F': return 'f';
|
||||
case 'G': return 'g';
|
||||
case 'H': return 'h';
|
||||
case 'I': return 'i';
|
||||
case 'J': return 'j';
|
||||
case 'K': return 'k';
|
||||
case 'L': return 'l';
|
||||
case 'M': return 'm';
|
||||
case 'N': return 'n';
|
||||
case 'O': return 'o';
|
||||
case 'P': return 'p';
|
||||
case 'Q': return 'q';
|
||||
case 'R': return 'r';
|
||||
case 'S': return 's';
|
||||
case 'T': return 't';
|
||||
case 'U': return 'u';
|
||||
case 'V': return 'v';
|
||||
case 'W': return 'w';
|
||||
case 'X': return 'x';
|
||||
case 'Y': return 'y';
|
||||
case 'Z': return 'z';
|
||||
default: return c;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
c_toupper (int c)
|
||||
{
|
||||
#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
return (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c);
|
||||
#else
|
||||
switch (c)
|
||||
{
|
||||
case 'a': return 'A';
|
||||
case 'b': return 'B';
|
||||
case 'c': return 'C';
|
||||
case 'd': return 'D';
|
||||
case 'e': return 'E';
|
||||
case 'f': return 'F';
|
||||
case 'g': return 'G';
|
||||
case 'h': return 'H';
|
||||
case 'i': return 'I';
|
||||
case 'j': return 'J';
|
||||
case 'k': return 'K';
|
||||
case 'l': return 'L';
|
||||
case 'm': return 'M';
|
||||
case 'n': return 'N';
|
||||
case 'o': return 'O';
|
||||
case 'p': return 'P';
|
||||
case 'q': return 'Q';
|
||||
case 'r': return 'R';
|
||||
case 's': return 'S';
|
||||
case 't': return 'T';
|
||||
case 'u': return 'U';
|
||||
case 'v': return 'V';
|
||||
case 'w': return 'W';
|
||||
case 'x': return 'X';
|
||||
case 'y': return 'Y';
|
||||
case 'z': return 'Z';
|
||||
default: return c;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Generated
+295
@@ -0,0 +1,295 @@
|
||||
/* Character handling in C locale.
|
||||
|
||||
These functions work like the corresponding functions in <ctype.h>,
|
||||
except that they have the C (POSIX) locale hardwired, whereas the
|
||||
<ctype.h> functions' behaviour depends on the current locale set via
|
||||
setlocale.
|
||||
|
||||
Copyright (C) 2000-2003, 2006, 2008-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef C_CTYPE_H
|
||||
#define C_CTYPE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* The functions defined in this file assume the "C" locale and a character
|
||||
set without diacritics (ASCII-US or EBCDIC-US or something like that).
|
||||
Even if the "C" locale on a particular system is an extension of the ASCII
|
||||
character set (like on BeOS, where it is UTF-8, or on AmigaOS, where it
|
||||
is ISO-8859-1), the functions in this file recognize only the ASCII
|
||||
characters. */
|
||||
|
||||
|
||||
/* Check whether the ASCII optimizations apply. */
|
||||
|
||||
/* ANSI C89 (and ISO C99 5.2.1.3 too) already guarantees that
|
||||
'0', '1', ..., '9' have consecutive integer values. */
|
||||
#define C_CTYPE_CONSECUTIVE_DIGITS 1
|
||||
|
||||
#if ('A' <= 'Z') \
|
||||
&& ('A' + 1 == 'B') && ('B' + 1 == 'C') && ('C' + 1 == 'D') \
|
||||
&& ('D' + 1 == 'E') && ('E' + 1 == 'F') && ('F' + 1 == 'G') \
|
||||
&& ('G' + 1 == 'H') && ('H' + 1 == 'I') && ('I' + 1 == 'J') \
|
||||
&& ('J' + 1 == 'K') && ('K' + 1 == 'L') && ('L' + 1 == 'M') \
|
||||
&& ('M' + 1 == 'N') && ('N' + 1 == 'O') && ('O' + 1 == 'P') \
|
||||
&& ('P' + 1 == 'Q') && ('Q' + 1 == 'R') && ('R' + 1 == 'S') \
|
||||
&& ('S' + 1 == 'T') && ('T' + 1 == 'U') && ('U' + 1 == 'V') \
|
||||
&& ('V' + 1 == 'W') && ('W' + 1 == 'X') && ('X' + 1 == 'Y') \
|
||||
&& ('Y' + 1 == 'Z')
|
||||
#define C_CTYPE_CONSECUTIVE_UPPERCASE 1
|
||||
#endif
|
||||
|
||||
#if ('a' <= 'z') \
|
||||
&& ('a' + 1 == 'b') && ('b' + 1 == 'c') && ('c' + 1 == 'd') \
|
||||
&& ('d' + 1 == 'e') && ('e' + 1 == 'f') && ('f' + 1 == 'g') \
|
||||
&& ('g' + 1 == 'h') && ('h' + 1 == 'i') && ('i' + 1 == 'j') \
|
||||
&& ('j' + 1 == 'k') && ('k' + 1 == 'l') && ('l' + 1 == 'm') \
|
||||
&& ('m' + 1 == 'n') && ('n' + 1 == 'o') && ('o' + 1 == 'p') \
|
||||
&& ('p' + 1 == 'q') && ('q' + 1 == 'r') && ('r' + 1 == 's') \
|
||||
&& ('s' + 1 == 't') && ('t' + 1 == 'u') && ('u' + 1 == 'v') \
|
||||
&& ('v' + 1 == 'w') && ('w' + 1 == 'x') && ('x' + 1 == 'y') \
|
||||
&& ('y' + 1 == 'z')
|
||||
#define C_CTYPE_CONSECUTIVE_LOWERCASE 1
|
||||
#endif
|
||||
|
||||
#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
|
||||
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
|
||||
&& (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
|
||||
&& ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
|
||||
&& ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
|
||||
&& ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
|
||||
&& ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
|
||||
&& ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
|
||||
&& ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
|
||||
&& ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
|
||||
&& ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
|
||||
&& ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
|
||||
&& ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
|
||||
&& ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
|
||||
&& ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
|
||||
&& ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
|
||||
&& ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
|
||||
&& ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
|
||||
&& ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
|
||||
&& ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
|
||||
&& ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
|
||||
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
|
||||
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)
|
||||
/* The character set is ASCII or one of its variants or extensions, not EBCDIC.
|
||||
Testing the value of '\n' and '\r' is not relevant. */
|
||||
#define C_CTYPE_ASCII 1
|
||||
#endif
|
||||
|
||||
|
||||
/* Function declarations. */
|
||||
|
||||
/* Unlike the functions in <ctype.h>, which require an argument in the range
|
||||
of the 'unsigned char' type, the functions here operate on values that are
|
||||
in the 'unsigned char' range or in the 'char' range. In other words,
|
||||
when you have a 'char' value, you need to cast it before using it as
|
||||
argument to a <ctype.h> function:
|
||||
|
||||
const char *s = ...;
|
||||
if (isalpha ((unsigned char) *s)) ...
|
||||
|
||||
but you don't need to cast it for the functions defined in this file:
|
||||
|
||||
const char *s = ...;
|
||||
if (c_isalpha (*s)) ...
|
||||
*/
|
||||
|
||||
extern bool c_isascii (int c) _GL_ATTRIBUTE_CONST; /* not locale dependent */
|
||||
|
||||
extern bool c_isalnum (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_isalpha (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_isblank (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_iscntrl (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_isdigit (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_islower (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_isgraph (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_isprint (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_ispunct (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_isspace (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_isupper (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern bool c_isxdigit (int c) _GL_ATTRIBUTE_CONST;
|
||||
|
||||
extern int c_tolower (int c) _GL_ATTRIBUTE_CONST;
|
||||
extern int c_toupper (int c) _GL_ATTRIBUTE_CONST;
|
||||
|
||||
|
||||
#if (defined __GNUC__ && !defined __STRICT_ANSI__ && defined __OPTIMIZE__ \
|
||||
&& !defined __OPTIMIZE_SIZE__ && !defined NO_C_CTYPE_MACROS)
|
||||
|
||||
/* ASCII optimizations. */
|
||||
|
||||
#undef c_isascii
|
||||
#define c_isascii(c) \
|
||||
({ int __c = (c); \
|
||||
(__c >= 0x00 && __c <= 0x7f); \
|
||||
})
|
||||
|
||||
#if C_CTYPE_CONSECUTIVE_DIGITS \
|
||||
&& C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
#if C_CTYPE_ASCII
|
||||
#undef c_isalnum
|
||||
#define c_isalnum(c) \
|
||||
({ int __c = (c); \
|
||||
((__c >= '0' && __c <= '9') \
|
||||
|| ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'Z')); \
|
||||
})
|
||||
#else
|
||||
#undef c_isalnum
|
||||
#define c_isalnum(c) \
|
||||
({ int __c = (c); \
|
||||
((__c >= '0' && __c <= '9') \
|
||||
|| (__c >= 'A' && __c <= 'Z') \
|
||||
|| (__c >= 'a' && __c <= 'z')); \
|
||||
})
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
#if C_CTYPE_ASCII
|
||||
#undef c_isalpha
|
||||
#define c_isalpha(c) \
|
||||
({ int __c = (c); \
|
||||
((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'Z'); \
|
||||
})
|
||||
#else
|
||||
#undef c_isalpha
|
||||
#define c_isalpha(c) \
|
||||
({ int __c = (c); \
|
||||
((__c >= 'A' && __c <= 'Z') || (__c >= 'a' && __c <= 'z')); \
|
||||
})
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#undef c_isblank
|
||||
#define c_isblank(c) \
|
||||
({ int __c = (c); \
|
||||
(__c == ' ' || __c == '\t'); \
|
||||
})
|
||||
|
||||
#if C_CTYPE_ASCII
|
||||
#undef c_iscntrl
|
||||
#define c_iscntrl(c) \
|
||||
({ int __c = (c); \
|
||||
((__c & ~0x1f) == 0 || __c == 0x7f); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#if C_CTYPE_CONSECUTIVE_DIGITS
|
||||
#undef c_isdigit
|
||||
#define c_isdigit(c) \
|
||||
({ int __c = (c); \
|
||||
(__c >= '0' && __c <= '9'); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#if C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
#undef c_islower
|
||||
#define c_islower(c) \
|
||||
({ int __c = (c); \
|
||||
(__c >= 'a' && __c <= 'z'); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#if C_CTYPE_ASCII
|
||||
#undef c_isgraph
|
||||
#define c_isgraph(c) \
|
||||
({ int __c = (c); \
|
||||
(__c >= '!' && __c <= '~'); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#if C_CTYPE_ASCII
|
||||
#undef c_isprint
|
||||
#define c_isprint(c) \
|
||||
({ int __c = (c); \
|
||||
(__c >= ' ' && __c <= '~'); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#if C_CTYPE_ASCII
|
||||
#undef c_ispunct
|
||||
#define c_ispunct(c) \
|
||||
({ int _c = (c); \
|
||||
(c_isgraph (_c) && ! c_isalnum (_c)); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#undef c_isspace
|
||||
#define c_isspace(c) \
|
||||
({ int __c = (c); \
|
||||
(__c == ' ' || __c == '\t' \
|
||||
|| __c == '\n' || __c == '\v' || __c == '\f' || __c == '\r'); \
|
||||
})
|
||||
|
||||
#if C_CTYPE_CONSECUTIVE_UPPERCASE
|
||||
#undef c_isupper
|
||||
#define c_isupper(c) \
|
||||
({ int __c = (c); \
|
||||
(__c >= 'A' && __c <= 'Z'); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#if C_CTYPE_CONSECUTIVE_DIGITS \
|
||||
&& C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
#if C_CTYPE_ASCII
|
||||
#undef c_isxdigit
|
||||
#define c_isxdigit(c) \
|
||||
({ int __c = (c); \
|
||||
((__c >= '0' && __c <= '9') \
|
||||
|| ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'F')); \
|
||||
})
|
||||
#else
|
||||
#undef c_isxdigit
|
||||
#define c_isxdigit(c) \
|
||||
({ int __c = (c); \
|
||||
((__c >= '0' && __c <= '9') \
|
||||
|| (__c >= 'A' && __c <= 'F') \
|
||||
|| (__c >= 'a' && __c <= 'f')); \
|
||||
})
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
|
||||
#undef c_tolower
|
||||
#define c_tolower(c) \
|
||||
({ int __c = (c); \
|
||||
(__c >= 'A' && __c <= 'Z' ? __c - 'A' + 'a' : __c); \
|
||||
})
|
||||
#undef c_toupper
|
||||
#define c_toupper(c) \
|
||||
({ int __c = (c); \
|
||||
(__c >= 'a' && __c <= 'z' ? __c - 'a' + 'A' : __c); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#endif /* optimizing for speed */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* C_CTYPE_H */
|
||||
Generated
+56
@@ -0,0 +1,56 @@
|
||||
/* Case-insensitive string comparison functions in C locale.
|
||||
Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef C_STRCASE_H
|
||||
#define C_STRCASE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
/* The functions defined in this file assume the "C" locale and a character
|
||||
set without diacritics (ASCII-US or EBCDIC-US or something like that).
|
||||
Even if the "C" locale on a particular system is an extension of the ASCII
|
||||
character set (like on BeOS, where it is UTF-8, or on AmigaOS, where it
|
||||
is ISO-8859-1), the functions in this file recognize only the ASCII
|
||||
characters. More precisely, one of the string arguments must be an ASCII
|
||||
string; the other one can also contain non-ASCII characters (but then
|
||||
the comparison result will be nonzero). */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
|
||||
greater than zero if S1 is lexicographically less than, equal to or greater
|
||||
than S2. */
|
||||
extern int c_strcasecmp (const char *s1, const char *s2) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* Compare no more than N characters of strings S1 and S2, ignoring case,
|
||||
returning less than, equal to or greater than zero if S1 is
|
||||
lexicographically less than, equal to or greater than S2. */
|
||||
extern int c_strncasecmp (const char *s1, const char *s2, size_t n)
|
||||
_GL_ATTRIBUTE_PURE;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* C_STRCASE_H */
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/* c-strcasecmp.c -- case insensitive string comparator in C locale
|
||||
Copyright (C) 1998-1999, 2005-2006, 2009-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "c-strcase.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "c-ctype.h"
|
||||
|
||||
int
|
||||
c_strcasecmp (const char *s1, const char *s2)
|
||||
{
|
||||
register const unsigned char *p1 = (const unsigned char *) s1;
|
||||
register const unsigned char *p2 = (const unsigned char *) s2;
|
||||
unsigned char c1, c2;
|
||||
|
||||
if (p1 == p2)
|
||||
return 0;
|
||||
|
||||
do
|
||||
{
|
||||
c1 = c_tolower (*p1);
|
||||
c2 = c_tolower (*p2);
|
||||
|
||||
if (c1 == '\0')
|
||||
break;
|
||||
|
||||
++p1;
|
||||
++p2;
|
||||
}
|
||||
while (c1 == c2);
|
||||
|
||||
if (UCHAR_MAX <= INT_MAX)
|
||||
return c1 - c2;
|
||||
else
|
||||
/* On machines where 'char' and 'int' are types of the same size, the
|
||||
difference of two 'unsigned char' values - including the sign bit -
|
||||
doesn't fit in an 'int'. */
|
||||
return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/* c-strncasecmp.c -- case insensitive string comparator in C locale
|
||||
Copyright (C) 1998-1999, 2005-2006, 2009-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "c-strcase.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "c-ctype.h"
|
||||
|
||||
int
|
||||
c_strncasecmp (const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
register const unsigned char *p1 = (const unsigned char *) s1;
|
||||
register const unsigned char *p2 = (const unsigned char *) s2;
|
||||
unsigned char c1, c2;
|
||||
|
||||
if (p1 == p2 || n == 0)
|
||||
return 0;
|
||||
|
||||
do
|
||||
{
|
||||
c1 = c_tolower (*p1);
|
||||
c2 = c_tolower (*p2);
|
||||
|
||||
if (--n == 0 || c1 == '\0')
|
||||
break;
|
||||
|
||||
++p1;
|
||||
++p2;
|
||||
}
|
||||
while (c1 == c2);
|
||||
|
||||
if (UCHAR_MAX <= INT_MAX)
|
||||
return c1 - c2;
|
||||
else
|
||||
/* On machines where 'char' and 'int' are types of the same size, the
|
||||
difference of two 'unsigned char' values - including the sign bit -
|
||||
doesn't fit in an 'int'. */
|
||||
return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
|
||||
}
|
||||
Generated
+110
@@ -0,0 +1,110 @@
|
||||
/* Convenience header for conditional use of GNU <libintl.h>.
|
||||
Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _LIBGETTEXT_H
|
||||
#define _LIBGETTEXT_H 1
|
||||
|
||||
/* NLS can be disabled through the configure --disable-nls option. */
|
||||
#if ENABLE_NLS
|
||||
|
||||
/* Get declarations of GNU message catalog functions. */
|
||||
# include <libintl.h>
|
||||
|
||||
/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
|
||||
the gettext() and ngettext() macros. This is an alternative to calling
|
||||
textdomain(), and is useful for libraries. */
|
||||
# ifdef DEFAULT_TEXT_DOMAIN
|
||||
# undef gettext
|
||||
# define gettext(Msgid) \
|
||||
dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
|
||||
# undef ngettext
|
||||
# define ngettext(Msgid1, Msgid2, N) \
|
||||
dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
|
||||
chokes if dcgettext is defined as a macro. So include it now, to make
|
||||
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
|
||||
as well because people using "gettext.h" will not include <libintl.h>,
|
||||
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
|
||||
is OK. */
|
||||
#if defined(__sun)
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
|
||||
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
|
||||
it now, to make later inclusions of <libintl.h> a NOP. */
|
||||
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
|
||||
# include <cstdlib>
|
||||
# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H
|
||||
# include <libintl.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Disabled NLS.
|
||||
The casts to 'const char *' serve the purpose of producing warnings
|
||||
for invalid uses of the value returned from these functions.
|
||||
On pre-ANSI systems without 'const', the config.h file is supposed to
|
||||
contain "#define const". */
|
||||
# undef gettext
|
||||
# define gettext(Msgid) ((const char *) (Msgid))
|
||||
# undef dgettext
|
||||
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
|
||||
# undef dcgettext
|
||||
# define dcgettext(Domainname, Msgid, Category) \
|
||||
((void) (Category), dgettext (Domainname, Msgid))
|
||||
# undef ngettext
|
||||
# define ngettext(Msgid1, Msgid2, N) \
|
||||
((N) == 1 \
|
||||
? ((void) (Msgid2), (const char *) (Msgid1)) \
|
||||
: ((void) (Msgid1), (const char *) (Msgid2)))
|
||||
# undef dngettext
|
||||
# define dngettext(Domainname, Msgid1, Msgid2, N) \
|
||||
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
|
||||
# undef dcngettext
|
||||
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
|
||||
((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
|
||||
# undef textdomain
|
||||
# define textdomain(Domainname) ((const char *) (Domainname))
|
||||
# undef bindtextdomain
|
||||
# define bindtextdomain(Domainname, Dirname) \
|
||||
((void) (Domainname), (const char *) (Dirname))
|
||||
# undef bind_textdomain_codeset
|
||||
# define bind_textdomain_codeset(Domainname, Codeset) \
|
||||
((void) (Domainname), (const char *) (Codeset))
|
||||
|
||||
#endif
|
||||
|
||||
/* Prefer gnulib's setlocale override over libintl's setlocale override. */
|
||||
#ifdef GNULIB_defined_setlocale
|
||||
# undef setlocale
|
||||
# define setlocale rpl_setlocale
|
||||
#endif
|
||||
|
||||
/* A pseudo function call that serves as a marker for the automated
|
||||
extraction of messages, but does not call gettext(). The run-time
|
||||
translation is done at a different place in the code.
|
||||
The argument, String, should be a literal string. Concatenated strings
|
||||
and other string expressions won't work.
|
||||
The macro's expansion is not parenthesized, so that it is suitable as
|
||||
initializer for static 'char[]' or 'const char[]' variables. */
|
||||
#define gettext_noop(String) String
|
||||
|
||||
#endif /* _LIBGETTEXT_H */
|
||||
Generated
+449
@@ -0,0 +1,449 @@
|
||||
/* Character set conversion.
|
||||
Copyright (C) 1999-2001, 2007, 2009-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <iconv.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#if REPLACE_ICONV_UTF
|
||||
# include <errno.h>
|
||||
# include <stdint.h>
|
||||
# include <stdlib.h>
|
||||
# include "unistr.h"
|
||||
# ifndef uintptr_t
|
||||
# define uintptr_t unsigned long
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if REPLACE_ICONV_UTF
|
||||
|
||||
/* UTF-{16,32}{BE,LE} converters taken from GNU libiconv 1.11. */
|
||||
|
||||
/* Return code if invalid. (xxx_mbtowc) */
|
||||
# define RET_ILSEQ -1
|
||||
/* Return code if no bytes were read. (xxx_mbtowc) */
|
||||
# define RET_TOOFEW -2
|
||||
|
||||
/* Return code if invalid. (xxx_wctomb) */
|
||||
# define RET_ILUNI -1
|
||||
/* Return code if output buffer is too small. (xxx_wctomb, xxx_reset) */
|
||||
# define RET_TOOSMALL -2
|
||||
|
||||
/*
|
||||
* UTF-16BE
|
||||
*/
|
||||
|
||||
/* Specification: RFC 2781 */
|
||||
|
||||
static int
|
||||
utf16be_mbtowc (ucs4_t *pwc, const unsigned char *s, size_t n)
|
||||
{
|
||||
if (n >= 2)
|
||||
{
|
||||
ucs4_t wc = (s[0] << 8) + s[1];
|
||||
if (wc >= 0xd800 && wc < 0xdc00)
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
ucs4_t wc2 = (s[2] << 8) + s[3];
|
||||
if (!(wc2 >= 0xdc00 && wc2 < 0xe000))
|
||||
return RET_ILSEQ;
|
||||
*pwc = 0x10000 + ((wc - 0xd800) << 10) + (wc2 - 0xdc00);
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
else if (wc >= 0xdc00 && wc < 0xe000)
|
||||
{
|
||||
return RET_ILSEQ;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pwc = wc;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return RET_TOOFEW;
|
||||
}
|
||||
|
||||
static int
|
||||
utf16be_wctomb (unsigned char *r, ucs4_t wc, size_t n)
|
||||
{
|
||||
if (!(wc >= 0xd800 && wc < 0xe000))
|
||||
{
|
||||
if (wc < 0x10000)
|
||||
{
|
||||
if (n >= 2)
|
||||
{
|
||||
r[0] = (unsigned char) (wc >> 8);
|
||||
r[1] = (unsigned char) wc;
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
return RET_TOOSMALL;
|
||||
}
|
||||
else if (wc < 0x110000)
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
ucs4_t wc1 = 0xd800 + ((wc - 0x10000) >> 10);
|
||||
ucs4_t wc2 = 0xdc00 + ((wc - 0x10000) & 0x3ff);
|
||||
r[0] = (unsigned char) (wc1 >> 8);
|
||||
r[1] = (unsigned char) wc1;
|
||||
r[2] = (unsigned char) (wc2 >> 8);
|
||||
r[3] = (unsigned char) wc2;
|
||||
return 4;
|
||||
}
|
||||
else
|
||||
return RET_TOOSMALL;
|
||||
}
|
||||
}
|
||||
return RET_ILUNI;
|
||||
}
|
||||
|
||||
/*
|
||||
* UTF-16LE
|
||||
*/
|
||||
|
||||
/* Specification: RFC 2781 */
|
||||
|
||||
static int
|
||||
utf16le_mbtowc (ucs4_t *pwc, const unsigned char *s, size_t n)
|
||||
{
|
||||
if (n >= 2)
|
||||
{
|
||||
ucs4_t wc = s[0] + (s[1] << 8);
|
||||
if (wc >= 0xd800 && wc < 0xdc00)
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
ucs4_t wc2 = s[2] + (s[3] << 8);
|
||||
if (!(wc2 >= 0xdc00 && wc2 < 0xe000))
|
||||
return RET_ILSEQ;
|
||||
*pwc = 0x10000 + ((wc - 0xd800) << 10) + (wc2 - 0xdc00);
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
else if (wc >= 0xdc00 && wc < 0xe000)
|
||||
{
|
||||
return RET_ILSEQ;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pwc = wc;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return RET_TOOFEW;
|
||||
}
|
||||
|
||||
static int
|
||||
utf16le_wctomb (unsigned char *r, ucs4_t wc, size_t n)
|
||||
{
|
||||
if (!(wc >= 0xd800 && wc < 0xe000))
|
||||
{
|
||||
if (wc < 0x10000)
|
||||
{
|
||||
if (n >= 2)
|
||||
{
|
||||
r[0] = (unsigned char) wc;
|
||||
r[1] = (unsigned char) (wc >> 8);
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
return RET_TOOSMALL;
|
||||
}
|
||||
else if (wc < 0x110000)
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
ucs4_t wc1 = 0xd800 + ((wc - 0x10000) >> 10);
|
||||
ucs4_t wc2 = 0xdc00 + ((wc - 0x10000) & 0x3ff);
|
||||
r[0] = (unsigned char) wc1;
|
||||
r[1] = (unsigned char) (wc1 >> 8);
|
||||
r[2] = (unsigned char) wc2;
|
||||
r[3] = (unsigned char) (wc2 >> 8);
|
||||
return 4;
|
||||
}
|
||||
else
|
||||
return RET_TOOSMALL;
|
||||
}
|
||||
}
|
||||
return RET_ILUNI;
|
||||
}
|
||||
|
||||
/*
|
||||
* UTF-32BE
|
||||
*/
|
||||
|
||||
/* Specification: Unicode 3.1 Standard Annex #19 */
|
||||
|
||||
static int
|
||||
utf32be_mbtowc (ucs4_t *pwc, const unsigned char *s, size_t n)
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
ucs4_t wc = (s[0] << 24) + (s[1] << 16) + (s[2] << 8) + s[3];
|
||||
if (wc < 0x110000 && !(wc >= 0xd800 && wc < 0xe000))
|
||||
{
|
||||
*pwc = wc;
|
||||
return 4;
|
||||
}
|
||||
else
|
||||
return RET_ILSEQ;
|
||||
}
|
||||
return RET_TOOFEW;
|
||||
}
|
||||
|
||||
static int
|
||||
utf32be_wctomb (unsigned char *r, ucs4_t wc, size_t n)
|
||||
{
|
||||
if (wc < 0x110000 && !(wc >= 0xd800 && wc < 0xe000))
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
r[0] = 0;
|
||||
r[1] = (unsigned char) (wc >> 16);
|
||||
r[2] = (unsigned char) (wc >> 8);
|
||||
r[3] = (unsigned char) wc;
|
||||
return 4;
|
||||
}
|
||||
else
|
||||
return RET_TOOSMALL;
|
||||
}
|
||||
return RET_ILUNI;
|
||||
}
|
||||
|
||||
/*
|
||||
* UTF-32LE
|
||||
*/
|
||||
|
||||
/* Specification: Unicode 3.1 Standard Annex #19 */
|
||||
|
||||
static int
|
||||
utf32le_mbtowc (ucs4_t *pwc, const unsigned char *s, size_t n)
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
ucs4_t wc = s[0] + (s[1] << 8) + (s[2] << 16) + (s[3] << 24);
|
||||
if (wc < 0x110000 && !(wc >= 0xd800 && wc < 0xe000))
|
||||
{
|
||||
*pwc = wc;
|
||||
return 4;
|
||||
}
|
||||
else
|
||||
return RET_ILSEQ;
|
||||
}
|
||||
return RET_TOOFEW;
|
||||
}
|
||||
|
||||
static int
|
||||
utf32le_wctomb (unsigned char *r, ucs4_t wc, size_t n)
|
||||
{
|
||||
if (wc < 0x110000 && !(wc >= 0xd800 && wc < 0xe000))
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
r[0] = (unsigned char) wc;
|
||||
r[1] = (unsigned char) (wc >> 8);
|
||||
r[2] = (unsigned char) (wc >> 16);
|
||||
r[3] = 0;
|
||||
return 4;
|
||||
}
|
||||
else
|
||||
return RET_TOOSMALL;
|
||||
}
|
||||
return RET_ILUNI;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
size_t
|
||||
rpl_iconv (iconv_t cd,
|
||||
ICONV_CONST char **inbuf, size_t *inbytesleft,
|
||||
char **outbuf, size_t *outbytesleft)
|
||||
#undef iconv
|
||||
{
|
||||
#if REPLACE_ICONV_UTF
|
||||
switch ((uintptr_t) cd)
|
||||
{
|
||||
{
|
||||
int (*xxx_wctomb) (unsigned char *, ucs4_t, size_t);
|
||||
|
||||
case (uintptr_t) _ICONV_UTF8_UTF16BE:
|
||||
xxx_wctomb = utf16be_wctomb;
|
||||
goto loop_from_utf8;
|
||||
case (uintptr_t) _ICONV_UTF8_UTF16LE:
|
||||
xxx_wctomb = utf16le_wctomb;
|
||||
goto loop_from_utf8;
|
||||
case (uintptr_t) _ICONV_UTF8_UTF32BE:
|
||||
xxx_wctomb = utf32be_wctomb;
|
||||
goto loop_from_utf8;
|
||||
case (uintptr_t) _ICONV_UTF8_UTF32LE:
|
||||
xxx_wctomb = utf32le_wctomb;
|
||||
goto loop_from_utf8;
|
||||
|
||||
loop_from_utf8:
|
||||
if (inbuf == NULL || *inbuf == NULL)
|
||||
return 0;
|
||||
{
|
||||
ICONV_CONST char *inptr = *inbuf;
|
||||
size_t inleft = *inbytesleft;
|
||||
char *outptr = *outbuf;
|
||||
size_t outleft = *outbytesleft;
|
||||
size_t res = 0;
|
||||
while (inleft > 0)
|
||||
{
|
||||
ucs4_t uc;
|
||||
int m = u8_mbtoucr (&uc, (const uint8_t *) inptr, inleft);
|
||||
if (m <= 0)
|
||||
{
|
||||
if (m == -1)
|
||||
{
|
||||
errno = EILSEQ;
|
||||
res = (size_t)(-1);
|
||||
break;
|
||||
}
|
||||
if (m == -2)
|
||||
{
|
||||
errno = EINVAL;
|
||||
res = (size_t)(-1);
|
||||
break;
|
||||
}
|
||||
abort ();
|
||||
}
|
||||
else
|
||||
{
|
||||
int n = xxx_wctomb ((uint8_t *) outptr, uc, outleft);
|
||||
if (n < 0)
|
||||
{
|
||||
if (n == RET_ILUNI)
|
||||
{
|
||||
errno = EILSEQ;
|
||||
res = (size_t)(-1);
|
||||
break;
|
||||
}
|
||||
if (n == RET_TOOSMALL)
|
||||
{
|
||||
errno = E2BIG;
|
||||
res = (size_t)(-1);
|
||||
break;
|
||||
}
|
||||
abort ();
|
||||
}
|
||||
else
|
||||
{
|
||||
inptr += m;
|
||||
inleft -= m;
|
||||
outptr += n;
|
||||
outleft -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
*inbuf = inptr;
|
||||
*inbytesleft = inleft;
|
||||
*outbuf = outptr;
|
||||
*outbytesleft = outleft;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int (*xxx_mbtowc) (ucs4_t *, const unsigned char *, size_t);
|
||||
|
||||
case (uintptr_t) _ICONV_UTF16BE_UTF8:
|
||||
xxx_mbtowc = utf16be_mbtowc;
|
||||
goto loop_to_utf8;
|
||||
case (uintptr_t) _ICONV_UTF16LE_UTF8:
|
||||
xxx_mbtowc = utf16le_mbtowc;
|
||||
goto loop_to_utf8;
|
||||
case (uintptr_t) _ICONV_UTF32BE_UTF8:
|
||||
xxx_mbtowc = utf32be_mbtowc;
|
||||
goto loop_to_utf8;
|
||||
case (uintptr_t) _ICONV_UTF32LE_UTF8:
|
||||
xxx_mbtowc = utf32le_mbtowc;
|
||||
goto loop_to_utf8;
|
||||
|
||||
loop_to_utf8:
|
||||
if (inbuf == NULL || *inbuf == NULL)
|
||||
return 0;
|
||||
{
|
||||
ICONV_CONST char *inptr = *inbuf;
|
||||
size_t inleft = *inbytesleft;
|
||||
char *outptr = *outbuf;
|
||||
size_t outleft = *outbytesleft;
|
||||
size_t res = 0;
|
||||
while (inleft > 0)
|
||||
{
|
||||
ucs4_t uc;
|
||||
int m = xxx_mbtowc (&uc, (const uint8_t *) inptr, inleft);
|
||||
if (m <= 0)
|
||||
{
|
||||
if (m == RET_ILSEQ)
|
||||
{
|
||||
errno = EILSEQ;
|
||||
res = (size_t)(-1);
|
||||
break;
|
||||
}
|
||||
if (m == RET_TOOFEW)
|
||||
{
|
||||
errno = EINVAL;
|
||||
res = (size_t)(-1);
|
||||
break;
|
||||
}
|
||||
abort ();
|
||||
}
|
||||
else
|
||||
{
|
||||
int n = u8_uctomb ((uint8_t *) outptr, uc, outleft);
|
||||
if (n < 0)
|
||||
{
|
||||
if (n == -1)
|
||||
{
|
||||
errno = EILSEQ;
|
||||
res = (size_t)(-1);
|
||||
break;
|
||||
}
|
||||
if (n == -2)
|
||||
{
|
||||
errno = E2BIG;
|
||||
res = (size_t)(-1);
|
||||
break;
|
||||
}
|
||||
abort ();
|
||||
}
|
||||
else
|
||||
{
|
||||
inptr += m;
|
||||
inleft -= m;
|
||||
outptr += n;
|
||||
outleft -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
*inbuf = inptr;
|
||||
*inbytesleft = inleft;
|
||||
*outbuf = outptr;
|
||||
*outbytesleft = outleft;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return iconv (cd, inbuf, inbytesleft, outbuf, outbytesleft);
|
||||
}
|
||||
Generated
+110
@@ -0,0 +1,110 @@
|
||||
/* A GNU-like <iconv.h>.
|
||||
|
||||
Copyright (C) 2007-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_ICONV_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_ICONV_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_ICONV_H
|
||||
#define _@GUARD_PREFIX@_ICONV_H
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
|
||||
#if @GNULIB_ICONV@
|
||||
# if @REPLACE_ICONV_OPEN@
|
||||
/* An iconv_open wrapper that supports the IANA standardized encoding names
|
||||
("ISO-8859-1" etc.) as far as possible. */
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define iconv_open rpl_iconv_open
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (iconv_open, iconv_t,
|
||||
(const char *tocode, const char *fromcode)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
_GL_CXXALIAS_RPL (iconv_open, iconv_t,
|
||||
(const char *tocode, const char *fromcode));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (iconv_open, iconv_t,
|
||||
(const char *tocode, const char *fromcode));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (iconv_open);
|
||||
#endif
|
||||
|
||||
#if @REPLACE_ICONV_UTF@
|
||||
/* Special constants for supporting UTF-{16,32}{BE,LE} encodings.
|
||||
Not public. */
|
||||
# define _ICONV_UTF8_UTF16BE (iconv_t)(-161)
|
||||
# define _ICONV_UTF8_UTF16LE (iconv_t)(-162)
|
||||
# define _ICONV_UTF8_UTF32BE (iconv_t)(-163)
|
||||
# define _ICONV_UTF8_UTF32LE (iconv_t)(-164)
|
||||
# define _ICONV_UTF16BE_UTF8 (iconv_t)(-165)
|
||||
# define _ICONV_UTF16LE_UTF8 (iconv_t)(-166)
|
||||
# define _ICONV_UTF32BE_UTF8 (iconv_t)(-167)
|
||||
# define _ICONV_UTF32LE_UTF8 (iconv_t)(-168)
|
||||
#endif
|
||||
|
||||
#if @GNULIB_ICONV@
|
||||
# if @REPLACE_ICONV@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define iconv rpl_iconv
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (iconv, size_t,
|
||||
(iconv_t cd,
|
||||
@ICONV_CONST@ char **inbuf, size_t *inbytesleft,
|
||||
char **outbuf, size_t *outbytesleft));
|
||||
_GL_CXXALIAS_RPL (iconv, size_t,
|
||||
(iconv_t cd,
|
||||
@ICONV_CONST@ char **inbuf, size_t *inbytesleft,
|
||||
char **outbuf, size_t *outbytesleft));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (iconv, size_t,
|
||||
(iconv_t cd,
|
||||
@ICONV_CONST@ char **inbuf, size_t *inbytesleft,
|
||||
char **outbuf, size_t *outbytesleft));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (iconv);
|
||||
# ifndef ICONV_CONST
|
||||
# define ICONV_CONST @ICONV_CONST@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_ICONV@
|
||||
# if @REPLACE_ICONV@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define iconv_close rpl_iconv_close
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (iconv_close, int, (iconv_t cd));
|
||||
_GL_CXXALIAS_RPL (iconv_close, int, (iconv_t cd));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (iconv_close, int, (iconv_t cd));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (iconv_close);
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_ICONV_H */
|
||||
#endif /* _@GUARD_PREFIX@_ICONV_H */
|
||||
Generated
+46
@@ -0,0 +1,46 @@
|
||||
/* Character set conversion.
|
||||
Copyright (C) 2007, 2009-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <iconv.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#ifndef uintptr_t
|
||||
# define uintptr_t unsigned long
|
||||
#endif
|
||||
|
||||
int
|
||||
rpl_iconv_close (iconv_t cd)
|
||||
#undef iconv_close
|
||||
{
|
||||
#if REPLACE_ICONV_UTF
|
||||
switch ((uintptr_t) cd)
|
||||
{
|
||||
case (uintptr_t) _ICONV_UTF8_UTF16BE:
|
||||
case (uintptr_t) _ICONV_UTF8_UTF16LE:
|
||||
case (uintptr_t) _ICONV_UTF8_UTF32BE:
|
||||
case (uintptr_t) _ICONV_UTF8_UTF32LE:
|
||||
case (uintptr_t) _ICONV_UTF16BE_UTF8:
|
||||
case (uintptr_t) _ICONV_UTF16LE_UTF8:
|
||||
case (uintptr_t) _ICONV_UTF32BE_UTF8:
|
||||
case (uintptr_t) _ICONV_UTF32LE_UTF8:
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return iconv_close (cd);
|
||||
}
|
||||
Generated
+172
@@ -0,0 +1,172 @@
|
||||
/* Character set conversion.
|
||||
Copyright (C) 2007, 2009-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <iconv.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include "c-ctype.h"
|
||||
#include "c-strcase.h"
|
||||
|
||||
#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
/* Namespace cleanliness. */
|
||||
#define mapping_lookup rpl_iconv_open_mapping_lookup
|
||||
|
||||
/* The macro ICONV_FLAVOR is defined to one of these or undefined. */
|
||||
|
||||
#define ICONV_FLAVOR_AIX "iconv_open-aix.h"
|
||||
#define ICONV_FLAVOR_HPUX "iconv_open-hpux.h"
|
||||
#define ICONV_FLAVOR_IRIX "iconv_open-irix.h"
|
||||
#define ICONV_FLAVOR_OSF "iconv_open-osf.h"
|
||||
#define ICONV_FLAVOR_SOLARIS "iconv_open-solaris.h"
|
||||
|
||||
#ifdef ICONV_FLAVOR
|
||||
# include ICONV_FLAVOR
|
||||
#endif
|
||||
|
||||
iconv_t
|
||||
rpl_iconv_open (const char *tocode, const char *fromcode)
|
||||
#undef iconv_open
|
||||
{
|
||||
char fromcode_upper[32];
|
||||
char tocode_upper[32];
|
||||
char *fromcode_upper_end;
|
||||
char *tocode_upper_end;
|
||||
|
||||
#if REPLACE_ICONV_UTF
|
||||
/* Special handling of conversion between UTF-8 and UTF-{16,32}{BE,LE}.
|
||||
Do this here, before calling the real iconv_open(), because OSF/1 5.1
|
||||
iconv() to these encoding inserts a BOM, which is wrong.
|
||||
We do not need to handle conversion between arbitrary encodings and
|
||||
UTF-{16,32}{BE,LE}, because the 'striconveh' module implements two-step
|
||||
conversion through UTF-8.
|
||||
The _ICONV_* constants are chosen to be disjoint from any iconv_t
|
||||
returned by the system's iconv_open() functions. Recall that iconv_t
|
||||
is a scalar type. */
|
||||
if (c_toupper (fromcode[0]) == 'U'
|
||||
&& c_toupper (fromcode[1]) == 'T'
|
||||
&& c_toupper (fromcode[2]) == 'F'
|
||||
&& fromcode[3] == '-')
|
||||
{
|
||||
if (c_toupper (tocode[0]) == 'U'
|
||||
&& c_toupper (tocode[1]) == 'T'
|
||||
&& c_toupper (tocode[2]) == 'F'
|
||||
&& tocode[3] == '-')
|
||||
{
|
||||
if (strcmp (fromcode + 4, "8") == 0)
|
||||
{
|
||||
if (c_strcasecmp (tocode + 4, "16BE") == 0)
|
||||
return _ICONV_UTF8_UTF16BE;
|
||||
if (c_strcasecmp (tocode + 4, "16LE") == 0)
|
||||
return _ICONV_UTF8_UTF16LE;
|
||||
if (c_strcasecmp (tocode + 4, "32BE") == 0)
|
||||
return _ICONV_UTF8_UTF32BE;
|
||||
if (c_strcasecmp (tocode + 4, "32LE") == 0)
|
||||
return _ICONV_UTF8_UTF32LE;
|
||||
}
|
||||
else if (strcmp (tocode + 4, "8") == 0)
|
||||
{
|
||||
if (c_strcasecmp (fromcode + 4, "16BE") == 0)
|
||||
return _ICONV_UTF16BE_UTF8;
|
||||
if (c_strcasecmp (fromcode + 4, "16LE") == 0)
|
||||
return _ICONV_UTF16LE_UTF8;
|
||||
if (c_strcasecmp (fromcode + 4, "32BE") == 0)
|
||||
return _ICONV_UTF32BE_UTF8;
|
||||
if (c_strcasecmp (fromcode + 4, "32LE") == 0)
|
||||
return _ICONV_UTF32LE_UTF8;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Do *not* add special support for 8-bit encodings like ASCII or ISO-8859-1
|
||||
here. This would lead to programs that work in some locales (such as the
|
||||
"C" or "en_US" locales) but do not work in East Asian locales. It is
|
||||
better if programmers make their programs depend on GNU libiconv (except
|
||||
on glibc systems), e.g. by using the AM_ICONV macro and documenting the
|
||||
dependency in an INSTALL or DEPENDENCIES file. */
|
||||
|
||||
/* Try with the original names first.
|
||||
This covers the case when fromcode or tocode is a lowercase encoding name
|
||||
that is understood by the system's iconv_open but not listed in our
|
||||
mappings table. */
|
||||
{
|
||||
iconv_t cd = iconv_open (tocode, fromcode);
|
||||
if (cd != (iconv_t)(-1))
|
||||
return cd;
|
||||
}
|
||||
|
||||
/* Convert the encodings to upper case, because
|
||||
1. in the arguments of iconv_open() on AIX, HP-UX, and OSF/1 the case
|
||||
matters,
|
||||
2. it makes searching in the table faster. */
|
||||
{
|
||||
const char *p = fromcode;
|
||||
char *q = fromcode_upper;
|
||||
while ((*q = c_toupper (*p)) != '\0')
|
||||
{
|
||||
p++;
|
||||
q++;
|
||||
if (q == &fromcode_upper[SIZEOF (fromcode_upper)])
|
||||
{
|
||||
errno = EINVAL;
|
||||
return (iconv_t)(-1);
|
||||
}
|
||||
}
|
||||
fromcode_upper_end = q;
|
||||
}
|
||||
|
||||
{
|
||||
const char *p = tocode;
|
||||
char *q = tocode_upper;
|
||||
while ((*q = c_toupper (*p)) != '\0')
|
||||
{
|
||||
p++;
|
||||
q++;
|
||||
if (q == &tocode_upper[SIZEOF (tocode_upper)])
|
||||
{
|
||||
errno = EINVAL;
|
||||
return (iconv_t)(-1);
|
||||
}
|
||||
}
|
||||
tocode_upper_end = q;
|
||||
}
|
||||
|
||||
#ifdef ICONV_FLAVOR
|
||||
/* Apply the mappings. */
|
||||
{
|
||||
const struct mapping *m =
|
||||
mapping_lookup (fromcode_upper, fromcode_upper_end - fromcode_upper);
|
||||
|
||||
fromcode = (m != NULL ? m->vendor_name : fromcode_upper);
|
||||
}
|
||||
{
|
||||
const struct mapping *m =
|
||||
mapping_lookup (tocode_upper, tocode_upper_end - tocode_upper);
|
||||
|
||||
tocode = (m != NULL ? m->vendor_name : tocode_upper);
|
||||
}
|
||||
#else
|
||||
fromcode = fromcode_upper;
|
||||
tocode = tocode_upper;
|
||||
#endif
|
||||
|
||||
return iconv_open (tocode, fromcode);
|
||||
}
|
||||
Generated
+132
@@ -0,0 +1,132 @@
|
||||
/* Copyright (C) 2001-2003, 2006-2015 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GL_STDBOOL_H
|
||||
#define _GL_STDBOOL_H
|
||||
|
||||
/* ISO C 99 <stdbool.h> for platforms that lack it. */
|
||||
|
||||
/* Usage suggestions:
|
||||
|
||||
Programs that use <stdbool.h> should be aware of some limitations
|
||||
and standards compliance issues.
|
||||
|
||||
Standards compliance:
|
||||
|
||||
- <stdbool.h> must be #included before 'bool', 'false', 'true'
|
||||
can be used.
|
||||
|
||||
- You cannot assume that sizeof (bool) == 1.
|
||||
|
||||
- Programs should not undefine the macros bool, true, and false,
|
||||
as C99 lists that as an "obsolescent feature".
|
||||
|
||||
Limitations of this substitute, when used in a C89 environment:
|
||||
|
||||
- <stdbool.h> must be #included before the '_Bool' type can be used.
|
||||
|
||||
- You cannot assume that _Bool is a typedef; it might be a macro.
|
||||
|
||||
- Bit-fields of type 'bool' are not supported. Portable code
|
||||
should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
|
||||
|
||||
- In C99, casts and automatic conversions to '_Bool' or 'bool' are
|
||||
performed in such a way that every nonzero value gets converted
|
||||
to 'true', and zero gets converted to 'false'. This doesn't work
|
||||
with this substitute. With this substitute, only the values 0 and 1
|
||||
give the expected result when converted to _Bool' or 'bool'.
|
||||
|
||||
- C99 allows the use of (_Bool)0.0 in constant expressions, but
|
||||
this substitute cannot always provide this property.
|
||||
|
||||
Also, it is suggested that programs use 'bool' rather than '_Bool';
|
||||
this isn't required, but 'bool' is more common. */
|
||||
|
||||
|
||||
/* 7.16. Boolean type and values */
|
||||
|
||||
/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
|
||||
definitions below, but temporarily we have to #undef them. */
|
||||
#if defined __BEOS__ && !defined __HAIKU__
|
||||
# include <OS.h> /* defines bool but not _Bool */
|
||||
# undef false
|
||||
# undef true
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define _Bool bool
|
||||
# define bool bool
|
||||
#else
|
||||
# if defined __BEOS__ && !defined __HAIKU__
|
||||
/* A compiler known to have 'bool'. */
|
||||
/* If the compiler already has both 'bool' and '_Bool', we can assume they
|
||||
are the same types. */
|
||||
# if !@HAVE__BOOL@
|
||||
typedef bool _Bool;
|
||||
# endif
|
||||
# else
|
||||
# if !defined __GNUC__
|
||||
/* If @HAVE__BOOL@:
|
||||
Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
|
||||
the built-in _Bool type is used. See
|
||||
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
|
||||
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
|
||||
http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
|
||||
Similar bugs are likely with other compilers as well; this file
|
||||
wouldn't be used if <stdbool.h> was working.
|
||||
So we override the _Bool type.
|
||||
If !@HAVE__BOOL@:
|
||||
Need to define _Bool ourselves. As 'signed char' or as an enum type?
|
||||
Use of a typedef, with SunPRO C, leads to a stupid
|
||||
"warning: _Bool is a keyword in ISO C99".
|
||||
Use of an enum type, with IRIX cc, leads to a stupid
|
||||
"warning(1185): enumerated type mixed with another type".
|
||||
Even the existence of an enum type, without a typedef,
|
||||
"Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
|
||||
The only benefit of the enum, debuggability, is not important
|
||||
with these compilers. So use 'signed char' and no enum. */
|
||||
# define _Bool signed char
|
||||
# else
|
||||
/* With this compiler, trust the _Bool type if the compiler has it. */
|
||||
# if !@HAVE__BOOL@
|
||||
/* For the sake of symbolic names in gdb, define true and false as
|
||||
enum constants, not only as macros.
|
||||
It is tempting to write
|
||||
typedef enum { false = 0, true = 1 } _Bool;
|
||||
so that gdb prints values of type 'bool' symbolically. But then
|
||||
values of type '_Bool' might promote to 'int' or 'unsigned int'
|
||||
(see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
|
||||
(see ISO C 99 6.3.1.1.(2)). So add a negative value to the
|
||||
enum; this ensures that '_Bool' promotes to 'int'. */
|
||||
typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# define bool _Bool
|
||||
#endif
|
||||
|
||||
/* The other macros must be usable in preprocessor directives. */
|
||||
#ifdef __cplusplus
|
||||
# define false false
|
||||
# define true true
|
||||
#else
|
||||
# define false 0
|
||||
# define true 1
|
||||
#endif
|
||||
|
||||
#define __bool_true_false_are_defined 1
|
||||
|
||||
#endif /* _GL_STDBOOL_H */
|
||||
Generated
+108
@@ -0,0 +1,108 @@
|
||||
/* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues.
|
||||
|
||||
Copyright (C) 2009-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Eric Blake. */
|
||||
|
||||
/*
|
||||
* POSIX 2008 <stddef.h> for platforms that have issues.
|
||||
* <http://www.opengroup.org/susv3xbd/stddef.h.html>
|
||||
*/
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
#if defined __need_wchar_t || defined __need_size_t \
|
||||
|| defined __need_ptrdiff_t || defined __need_NULL \
|
||||
|| defined __need_wint_t
|
||||
/* Special invocation convention inside gcc header files. In
|
||||
particular, gcc provides a version of <stddef.h> that blindly
|
||||
redefines NULL even when __need_wint_t was defined, even though
|
||||
wint_t is not normally provided by <stddef.h>. Hence, we must
|
||||
remember if special invocation has ever been used to obtain wint_t,
|
||||
in which case we need to clean up NULL yet again. */
|
||||
|
||||
# if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T)
|
||||
# ifdef __need_wint_t
|
||||
# define _GL_STDDEF_WINT_T
|
||||
# endif
|
||||
# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
|
||||
# endif
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
# ifndef _@GUARD_PREFIX@_STDDEF_H
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
|
||||
# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
|
||||
|
||||
/* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */
|
||||
# if (@REPLACE_NULL@ \
|
||||
&& (!defined _@GUARD_PREFIX@_STDDEF_H || defined _GL_STDDEF_WINT_T))
|
||||
# undef NULL
|
||||
# ifdef __cplusplus
|
||||
/* ISO C++ says that the macro NULL must expand to an integer constant
|
||||
expression, hence '((void *) 0)' is not allowed in C++. */
|
||||
# if __GNUG__ >= 3
|
||||
/* GNU C++ has a __null macro that behaves like an integer ('int' or
|
||||
'long') but has the same size as a pointer. Use that, to avoid
|
||||
warnings. */
|
||||
# define NULL __null
|
||||
# else
|
||||
# define NULL 0L
|
||||
# endif
|
||||
# else
|
||||
# define NULL ((void *) 0)
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef _@GUARD_PREFIX@_STDDEF_H
|
||||
# define _@GUARD_PREFIX@_STDDEF_H
|
||||
|
||||
/* Some platforms lack wchar_t. */
|
||||
#if !@HAVE_WCHAR_T@
|
||||
# define wchar_t int
|
||||
#endif
|
||||
|
||||
/* Some platforms lack max_align_t. */
|
||||
#if !@HAVE_MAX_ALIGN_T@
|
||||
/* On the x86, the maximum storage alignment of double, long, etc. is 4,
|
||||
but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8,
|
||||
and the C11 standard allows this. Work around this problem by
|
||||
using __alignof__ (which returns 8 for double) rather than _Alignof
|
||||
(which returns 4), and align each union member accordingly. */
|
||||
# ifdef __GNUC__
|
||||
# define _GL_STDDEF_ALIGNAS(type) \
|
||||
__attribute__ ((__aligned__ (__alignof__ (type))))
|
||||
# else
|
||||
# define _GL_STDDEF_ALIGNAS(type) /* */
|
||||
# endif
|
||||
typedef union
|
||||
{
|
||||
char *__p _GL_STDDEF_ALIGNAS (char *);
|
||||
double __d _GL_STDDEF_ALIGNAS (double);
|
||||
long double __ld _GL_STDDEF_ALIGNAS (long double);
|
||||
long int __i _GL_STDDEF_ALIGNAS (long int);
|
||||
} max_align_t;
|
||||
#endif
|
||||
|
||||
# endif /* _@GUARD_PREFIX@_STDDEF_H */
|
||||
# endif /* _@GUARD_PREFIX@_STDDEF_H */
|
||||
#endif /* __need_XXX */
|
||||
Generated
+636
@@ -0,0 +1,636 @@
|
||||
/* Copyright (C) 2001-2002, 2004-2015 Free Software Foundation, Inc.
|
||||
Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood.
|
||||
This file is part of gnulib.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/*
|
||||
* ISO C 99 <stdint.h> for platforms that lack it.
|
||||
* <http://www.opengroup.org/susv3xbd/stdint.h.html>
|
||||
*/
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_STDINT_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* When including a system file that in turn includes <inttypes.h>,
|
||||
use the system <inttypes.h>, not our substitute. This avoids
|
||||
problems with (for example) VMS, whose <sys/bitypes.h> includes
|
||||
<inttypes.h>. */
|
||||
#define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
|
||||
|
||||
/* On Android (Bionic libc), <sys/types.h> includes this file before
|
||||
having defined 'time_t'. Therefore in this case avoid including
|
||||
other system header files; just include the system's <stdint.h>.
|
||||
Ideally we should test __BIONIC__ here, but it is only defined after
|
||||
<sys/cdefs.h> has been included; hence test __ANDROID__ instead. */
|
||||
#if defined __ANDROID__ && defined _GL_INCLUDING_SYS_TYPES_H
|
||||
# @INCLUDE_NEXT@ @NEXT_STDINT_H@
|
||||
#else
|
||||
|
||||
/* Get those types that are already defined in other system include
|
||||
files, so that we can "#define int8_t signed char" below without
|
||||
worrying about a later system include file containing a "typedef
|
||||
signed char int8_t;" that will get messed up by our macro. Our
|
||||
macros should all be consistent with the system versions, except
|
||||
for the "fast" types and macros, which we recommend against using
|
||||
in public interfaces due to compiler differences. */
|
||||
|
||||
#if @HAVE_STDINT_H@
|
||||
# if defined __sgi && ! defined __c99
|
||||
/* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users
|
||||
with "This header file is to be used only for c99 mode compilations"
|
||||
diagnostics. */
|
||||
# define __STDINT_H__
|
||||
# endif
|
||||
|
||||
/* Some pre-C++11 <stdint.h> implementations need this. */
|
||||
# ifdef __cplusplus
|
||||
# ifndef __STDC_CONSTANT_MACROS
|
||||
# define __STDC_CONSTANT_MACROS 1
|
||||
# endif
|
||||
# ifndef __STDC_LIMIT_MACROS
|
||||
# define __STDC_LIMIT_MACROS 1
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Other systems may have an incomplete or buggy <stdint.h>.
|
||||
Include it before <inttypes.h>, since any "#include <stdint.h>"
|
||||
in <inttypes.h> would reinclude us, skipping our contents because
|
||||
_@GUARD_PREFIX@_STDINT_H is defined.
|
||||
The include_next requires a split double-inclusion guard. */
|
||||
# @INCLUDE_NEXT@ @NEXT_STDINT_H@
|
||||
#endif
|
||||
|
||||
#if ! defined _@GUARD_PREFIX@_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
|
||||
#define _@GUARD_PREFIX@_STDINT_H
|
||||
|
||||
/* <sys/types.h> defines some of the stdint.h types as well, on glibc,
|
||||
IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
|
||||
AIX 5.2 <sys/types.h> isn't needed and causes troubles.
|
||||
Mac OS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
|
||||
relies on the system <stdint.h> definitions, so include
|
||||
<sys/types.h> after @NEXT_STDINT_H@. */
|
||||
#if @HAVE_SYS_TYPES_H@ && ! defined _AIX
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/* Get SCHAR_MIN, SCHAR_MAX, UCHAR_MAX, INT_MIN, INT_MAX,
|
||||
LONG_MIN, LONG_MAX, ULONG_MAX. */
|
||||
#include <limits.h>
|
||||
|
||||
#if @HAVE_INTTYPES_H@
|
||||
/* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
|
||||
int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
|
||||
<inttypes.h> also defines intptr_t and uintptr_t. */
|
||||
# include <inttypes.h>
|
||||
#elif @HAVE_SYS_INTTYPES_H@
|
||||
/* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
|
||||
the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
|
||||
# include <sys/inttypes.h>
|
||||
#endif
|
||||
|
||||
#if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__
|
||||
/* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
|
||||
int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is
|
||||
included by <sys/types.h>. */
|
||||
# include <sys/bitypes.h>
|
||||
#endif
|
||||
|
||||
#undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
|
||||
|
||||
/* Minimum and maximum values for an integer type under the usual assumption.
|
||||
Return an unspecified value if BITS == 0, adding a check to pacify
|
||||
picky compilers. */
|
||||
|
||||
#define _STDINT_MIN(signed, bits, zero) \
|
||||
((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero))
|
||||
|
||||
#define _STDINT_MAX(signed, bits, zero) \
|
||||
((signed) \
|
||||
? ~ _STDINT_MIN (signed, bits, zero) \
|
||||
: /* The expression for the unsigned case. The subtraction of (signed) \
|
||||
is a nop in the unsigned case and avoids "signed integer overflow" \
|
||||
warnings in the signed case. */ \
|
||||
((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
|
||||
|
||||
#if !GNULIB_defined_stdint_types
|
||||
|
||||
/* 7.18.1.1. Exact-width integer types */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. */
|
||||
|
||||
#undef int8_t
|
||||
#undef uint8_t
|
||||
typedef signed char gl_int8_t;
|
||||
typedef unsigned char gl_uint8_t;
|
||||
#define int8_t gl_int8_t
|
||||
#define uint8_t gl_uint8_t
|
||||
|
||||
#undef int16_t
|
||||
#undef uint16_t
|
||||
typedef short int gl_int16_t;
|
||||
typedef unsigned short int gl_uint16_t;
|
||||
#define int16_t gl_int16_t
|
||||
#define uint16_t gl_uint16_t
|
||||
|
||||
#undef int32_t
|
||||
#undef uint32_t
|
||||
typedef int gl_int32_t;
|
||||
typedef unsigned int gl_uint32_t;
|
||||
#define int32_t gl_int32_t
|
||||
#define uint32_t gl_uint32_t
|
||||
|
||||
/* If the system defines INT64_MAX, assume int64_t works. That way,
|
||||
if the underlying platform defines int64_t to be a 64-bit long long
|
||||
int, the code below won't mistakenly define it to be a 64-bit long
|
||||
int, which would mess up C++ name mangling. We must use #ifdef
|
||||
rather than #if, to avoid an error with HP-UX 10.20 cc. */
|
||||
|
||||
#ifdef INT64_MAX
|
||||
# define GL_INT64_T
|
||||
#else
|
||||
/* Do not undefine int64_t if gnulib is not being used with 64-bit
|
||||
types, since otherwise it breaks platforms like Tandem/NSK. */
|
||||
# if LONG_MAX >> 31 >> 31 == 1
|
||||
# undef int64_t
|
||||
typedef long int gl_int64_t;
|
||||
# define int64_t gl_int64_t
|
||||
# define GL_INT64_T
|
||||
# elif defined _MSC_VER
|
||||
# undef int64_t
|
||||
typedef __int64 gl_int64_t;
|
||||
# define int64_t gl_int64_t
|
||||
# define GL_INT64_T
|
||||
# elif @HAVE_LONG_LONG_INT@
|
||||
# undef int64_t
|
||||
typedef long long int gl_int64_t;
|
||||
# define int64_t gl_int64_t
|
||||
# define GL_INT64_T
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef UINT64_MAX
|
||||
# define GL_UINT64_T
|
||||
#else
|
||||
# if ULONG_MAX >> 31 >> 31 >> 1 == 1
|
||||
# undef uint64_t
|
||||
typedef unsigned long int gl_uint64_t;
|
||||
# define uint64_t gl_uint64_t
|
||||
# define GL_UINT64_T
|
||||
# elif defined _MSC_VER
|
||||
# undef uint64_t
|
||||
typedef unsigned __int64 gl_uint64_t;
|
||||
# define uint64_t gl_uint64_t
|
||||
# define GL_UINT64_T
|
||||
# elif @HAVE_UNSIGNED_LONG_LONG_INT@
|
||||
# undef uint64_t
|
||||
typedef unsigned long long int gl_uint64_t;
|
||||
# define uint64_t gl_uint64_t
|
||||
# define GL_UINT64_T
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */
|
||||
#define _UINT8_T
|
||||
#define _UINT32_T
|
||||
#define _UINT64_T
|
||||
|
||||
|
||||
/* 7.18.1.2. Minimum-width integer types */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
|
||||
are the same as the corresponding N_t types. */
|
||||
|
||||
#undef int_least8_t
|
||||
#undef uint_least8_t
|
||||
#undef int_least16_t
|
||||
#undef uint_least16_t
|
||||
#undef int_least32_t
|
||||
#undef uint_least32_t
|
||||
#undef int_least64_t
|
||||
#undef uint_least64_t
|
||||
#define int_least8_t int8_t
|
||||
#define uint_least8_t uint8_t
|
||||
#define int_least16_t int16_t
|
||||
#define uint_least16_t uint16_t
|
||||
#define int_least32_t int32_t
|
||||
#define uint_least32_t uint32_t
|
||||
#ifdef GL_INT64_T
|
||||
# define int_least64_t int64_t
|
||||
#endif
|
||||
#ifdef GL_UINT64_T
|
||||
# define uint_least64_t uint64_t
|
||||
#endif
|
||||
|
||||
/* 7.18.1.3. Fastest minimum-width integer types */
|
||||
|
||||
/* Note: Other <stdint.h> substitutes may define these types differently.
|
||||
It is not recommended to use these types in public header files. */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
|
||||
are taken from the same list of types. The following code normally
|
||||
uses types consistent with glibc, as that lessens the chance of
|
||||
incompatibility with older GNU hosts. */
|
||||
|
||||
#undef int_fast8_t
|
||||
#undef uint_fast8_t
|
||||
#undef int_fast16_t
|
||||
#undef uint_fast16_t
|
||||
#undef int_fast32_t
|
||||
#undef uint_fast32_t
|
||||
#undef int_fast64_t
|
||||
#undef uint_fast64_t
|
||||
typedef signed char gl_int_fast8_t;
|
||||
typedef unsigned char gl_uint_fast8_t;
|
||||
|
||||
#ifdef __sun
|
||||
/* Define types compatible with SunOS 5.10, so that code compiled under
|
||||
earlier SunOS versions works with code compiled under SunOS 5.10. */
|
||||
typedef int gl_int_fast32_t;
|
||||
typedef unsigned int gl_uint_fast32_t;
|
||||
#else
|
||||
typedef long int gl_int_fast32_t;
|
||||
typedef unsigned long int gl_uint_fast32_t;
|
||||
#endif
|
||||
typedef gl_int_fast32_t gl_int_fast16_t;
|
||||
typedef gl_uint_fast32_t gl_uint_fast16_t;
|
||||
|
||||
#define int_fast8_t gl_int_fast8_t
|
||||
#define uint_fast8_t gl_uint_fast8_t
|
||||
#define int_fast16_t gl_int_fast16_t
|
||||
#define uint_fast16_t gl_uint_fast16_t
|
||||
#define int_fast32_t gl_int_fast32_t
|
||||
#define uint_fast32_t gl_uint_fast32_t
|
||||
#ifdef GL_INT64_T
|
||||
# define int_fast64_t int64_t
|
||||
#endif
|
||||
#ifdef GL_UINT64_T
|
||||
# define uint_fast64_t uint64_t
|
||||
#endif
|
||||
|
||||
/* 7.18.1.4. Integer types capable of holding object pointers */
|
||||
|
||||
#undef intptr_t
|
||||
#undef uintptr_t
|
||||
typedef long int gl_intptr_t;
|
||||
typedef unsigned long int gl_uintptr_t;
|
||||
#define intptr_t gl_intptr_t
|
||||
#define uintptr_t gl_uintptr_t
|
||||
|
||||
/* 7.18.1.5. Greatest-width integer types */
|
||||
|
||||
/* Note: These types are compiler dependent. It may be unwise to use them in
|
||||
public header files. */
|
||||
|
||||
/* If the system defines INTMAX_MAX, assume that intmax_t works, and
|
||||
similarly for UINTMAX_MAX and uintmax_t. This avoids problems with
|
||||
assuming one type where another is used by the system. */
|
||||
|
||||
#ifndef INTMAX_MAX
|
||||
# undef INTMAX_C
|
||||
# undef intmax_t
|
||||
# if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
|
||||
typedef long long int gl_intmax_t;
|
||||
# define intmax_t gl_intmax_t
|
||||
# elif defined GL_INT64_T
|
||||
# define intmax_t int64_t
|
||||
# else
|
||||
typedef long int gl_intmax_t;
|
||||
# define intmax_t gl_intmax_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef UINTMAX_MAX
|
||||
# undef UINTMAX_C
|
||||
# undef uintmax_t
|
||||
# if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
|
||||
typedef unsigned long long int gl_uintmax_t;
|
||||
# define uintmax_t gl_uintmax_t
|
||||
# elif defined GL_UINT64_T
|
||||
# define uintmax_t uint64_t
|
||||
# else
|
||||
typedef unsigned long int gl_uintmax_t;
|
||||
# define uintmax_t gl_uintmax_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Verify that intmax_t and uintmax_t have the same size. Too much code
|
||||
breaks if this is not the case. If this check fails, the reason is likely
|
||||
to be found in the autoconf macros. */
|
||||
typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
|
||||
? 1 : -1];
|
||||
|
||||
#define GNULIB_defined_stdint_types 1
|
||||
#endif /* !GNULIB_defined_stdint_types */
|
||||
|
||||
/* 7.18.2. Limits of specified-width integer types */
|
||||
|
||||
/* 7.18.2.1. Limits of exact-width integer types */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. */
|
||||
|
||||
#undef INT8_MIN
|
||||
#undef INT8_MAX
|
||||
#undef UINT8_MAX
|
||||
#define INT8_MIN (~ INT8_MAX)
|
||||
#define INT8_MAX 127
|
||||
#define UINT8_MAX 255
|
||||
|
||||
#undef INT16_MIN
|
||||
#undef INT16_MAX
|
||||
#undef UINT16_MAX
|
||||
#define INT16_MIN (~ INT16_MAX)
|
||||
#define INT16_MAX 32767
|
||||
#define UINT16_MAX 65535
|
||||
|
||||
#undef INT32_MIN
|
||||
#undef INT32_MAX
|
||||
#undef UINT32_MAX
|
||||
#define INT32_MIN (~ INT32_MAX)
|
||||
#define INT32_MAX 2147483647
|
||||
#define UINT32_MAX 4294967295U
|
||||
|
||||
#if defined GL_INT64_T && ! defined INT64_MAX
|
||||
/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0
|
||||
evaluates the latter incorrectly in preprocessor expressions. */
|
||||
# define INT64_MIN (- INTMAX_C (1) << 63)
|
||||
# define INT64_MAX INTMAX_C (9223372036854775807)
|
||||
#endif
|
||||
|
||||
#if defined GL_UINT64_T && ! defined UINT64_MAX
|
||||
# define UINT64_MAX UINTMAX_C (18446744073709551615)
|
||||
#endif
|
||||
|
||||
/* 7.18.2.2. Limits of minimum-width integer types */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
|
||||
are the same as the corresponding N_t types. */
|
||||
|
||||
#undef INT_LEAST8_MIN
|
||||
#undef INT_LEAST8_MAX
|
||||
#undef UINT_LEAST8_MAX
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
|
||||
#undef INT_LEAST16_MIN
|
||||
#undef INT_LEAST16_MAX
|
||||
#undef UINT_LEAST16_MAX
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
|
||||
#undef INT_LEAST32_MIN
|
||||
#undef INT_LEAST32_MAX
|
||||
#undef UINT_LEAST32_MAX
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
|
||||
#undef INT_LEAST64_MIN
|
||||
#undef INT_LEAST64_MAX
|
||||
#ifdef GL_INT64_T
|
||||
# define INT_LEAST64_MIN INT64_MIN
|
||||
# define INT_LEAST64_MAX INT64_MAX
|
||||
#endif
|
||||
|
||||
#undef UINT_LEAST64_MAX
|
||||
#ifdef GL_UINT64_T
|
||||
# define UINT_LEAST64_MAX UINT64_MAX
|
||||
#endif
|
||||
|
||||
/* 7.18.2.3. Limits of fastest minimum-width integer types */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
|
||||
are taken from the same list of types. */
|
||||
|
||||
#undef INT_FAST8_MIN
|
||||
#undef INT_FAST8_MAX
|
||||
#undef UINT_FAST8_MAX
|
||||
#define INT_FAST8_MIN SCHAR_MIN
|
||||
#define INT_FAST8_MAX SCHAR_MAX
|
||||
#define UINT_FAST8_MAX UCHAR_MAX
|
||||
|
||||
#undef INT_FAST16_MIN
|
||||
#undef INT_FAST16_MAX
|
||||
#undef UINT_FAST16_MAX
|
||||
#define INT_FAST16_MIN INT_FAST32_MIN
|
||||
#define INT_FAST16_MAX INT_FAST32_MAX
|
||||
#define UINT_FAST16_MAX UINT_FAST32_MAX
|
||||
|
||||
#undef INT_FAST32_MIN
|
||||
#undef INT_FAST32_MAX
|
||||
#undef UINT_FAST32_MAX
|
||||
#ifdef __sun
|
||||
# define INT_FAST32_MIN INT_MIN
|
||||
# define INT_FAST32_MAX INT_MAX
|
||||
# define UINT_FAST32_MAX UINT_MAX
|
||||
#else
|
||||
# define INT_FAST32_MIN LONG_MIN
|
||||
# define INT_FAST32_MAX LONG_MAX
|
||||
# define UINT_FAST32_MAX ULONG_MAX
|
||||
#endif
|
||||
|
||||
#undef INT_FAST64_MIN
|
||||
#undef INT_FAST64_MAX
|
||||
#ifdef GL_INT64_T
|
||||
# define INT_FAST64_MIN INT64_MIN
|
||||
# define INT_FAST64_MAX INT64_MAX
|
||||
#endif
|
||||
|
||||
#undef UINT_FAST64_MAX
|
||||
#ifdef GL_UINT64_T
|
||||
# define UINT_FAST64_MAX UINT64_MAX
|
||||
#endif
|
||||
|
||||
/* 7.18.2.4. Limits of integer types capable of holding object pointers */
|
||||
|
||||
#undef INTPTR_MIN
|
||||
#undef INTPTR_MAX
|
||||
#undef UINTPTR_MAX
|
||||
#define INTPTR_MIN LONG_MIN
|
||||
#define INTPTR_MAX LONG_MAX
|
||||
#define UINTPTR_MAX ULONG_MAX
|
||||
|
||||
/* 7.18.2.5. Limits of greatest-width integer types */
|
||||
|
||||
#ifndef INTMAX_MAX
|
||||
# undef INTMAX_MIN
|
||||
# ifdef INT64_MAX
|
||||
# define INTMAX_MIN INT64_MIN
|
||||
# define INTMAX_MAX INT64_MAX
|
||||
# else
|
||||
# define INTMAX_MIN INT32_MIN
|
||||
# define INTMAX_MAX INT32_MAX
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef UINTMAX_MAX
|
||||
# ifdef UINT64_MAX
|
||||
# define UINTMAX_MAX UINT64_MAX
|
||||
# else
|
||||
# define UINTMAX_MAX UINT32_MAX
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* 7.18.3. Limits of other integer types */
|
||||
|
||||
/* ptrdiff_t limits */
|
||||
#undef PTRDIFF_MIN
|
||||
#undef PTRDIFF_MAX
|
||||
#if @APPLE_UNIVERSAL_BUILD@
|
||||
# ifdef _LP64
|
||||
# define PTRDIFF_MIN _STDINT_MIN (1, 64, 0l)
|
||||
# define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l)
|
||||
# else
|
||||
# define PTRDIFF_MIN _STDINT_MIN (1, 32, 0)
|
||||
# define PTRDIFF_MAX _STDINT_MAX (1, 32, 0)
|
||||
# endif
|
||||
#else
|
||||
# define PTRDIFF_MIN \
|
||||
_STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
|
||||
# define PTRDIFF_MAX \
|
||||
_STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
|
||||
#endif
|
||||
|
||||
/* sig_atomic_t limits */
|
||||
#undef SIG_ATOMIC_MIN
|
||||
#undef SIG_ATOMIC_MAX
|
||||
#define SIG_ATOMIC_MIN \
|
||||
_STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
|
||||
0@SIG_ATOMIC_T_SUFFIX@)
|
||||
#define SIG_ATOMIC_MAX \
|
||||
_STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
|
||||
0@SIG_ATOMIC_T_SUFFIX@)
|
||||
|
||||
|
||||
/* size_t limit */
|
||||
#undef SIZE_MAX
|
||||
#if @APPLE_UNIVERSAL_BUILD@
|
||||
# ifdef _LP64
|
||||
# define SIZE_MAX _STDINT_MAX (0, 64, 0ul)
|
||||
# else
|
||||
# define SIZE_MAX _STDINT_MAX (0, 32, 0ul)
|
||||
# endif
|
||||
#else
|
||||
# define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@)
|
||||
#endif
|
||||
|
||||
/* wchar_t limits */
|
||||
/* Get WCHAR_MIN, WCHAR_MAX.
|
||||
This include is not on the top, above, because on OSF/1 4.0 we have a
|
||||
sequence of nested includes
|
||||
<wchar.h> -> <stdio.h> -> <getopt.h> -> <stdlib.h>, and the latter includes
|
||||
<stdint.h> and assumes its types are already defined. */
|
||||
#if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX)
|
||||
/* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
|
||||
included before <wchar.h>. */
|
||||
# include <stddef.h>
|
||||
# include <stdio.h>
|
||||
# include <time.h>
|
||||
# define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
|
||||
/* We don't need WCHAR_* in libidn, so to avoid problems with
|
||||
missing wchar.h, don't include wchar.h here. */
|
||||
# undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
|
||||
#endif
|
||||
#undef WCHAR_MIN
|
||||
#undef WCHAR_MAX
|
||||
#define WCHAR_MIN \
|
||||
_STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
|
||||
#define WCHAR_MAX \
|
||||
_STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
|
||||
|
||||
/* wint_t limits */
|
||||
#undef WINT_MIN
|
||||
#undef WINT_MAX
|
||||
#define WINT_MIN \
|
||||
_STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
|
||||
#define WINT_MAX \
|
||||
_STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
|
||||
|
||||
/* 7.18.4. Macros for integer constants */
|
||||
|
||||
/* 7.18.4.1. Macros for minimum-width integer constants */
|
||||
/* According to ISO C 99 Technical Corrigendum 1 */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */
|
||||
|
||||
#undef INT8_C
|
||||
#undef UINT8_C
|
||||
#define INT8_C(x) x
|
||||
#define UINT8_C(x) x
|
||||
|
||||
#undef INT16_C
|
||||
#undef UINT16_C
|
||||
#define INT16_C(x) x
|
||||
#define UINT16_C(x) x
|
||||
|
||||
#undef INT32_C
|
||||
#undef UINT32_C
|
||||
#define INT32_C(x) x
|
||||
#define UINT32_C(x) x ## U
|
||||
|
||||
#undef INT64_C
|
||||
#undef UINT64_C
|
||||
#if LONG_MAX >> 31 >> 31 == 1
|
||||
# define INT64_C(x) x##L
|
||||
#elif defined _MSC_VER
|
||||
# define INT64_C(x) x##i64
|
||||
#elif @HAVE_LONG_LONG_INT@
|
||||
# define INT64_C(x) x##LL
|
||||
#endif
|
||||
#if ULONG_MAX >> 31 >> 31 >> 1 == 1
|
||||
# define UINT64_C(x) x##UL
|
||||
#elif defined _MSC_VER
|
||||
# define UINT64_C(x) x##ui64
|
||||
#elif @HAVE_UNSIGNED_LONG_LONG_INT@
|
||||
# define UINT64_C(x) x##ULL
|
||||
#endif
|
||||
|
||||
/* 7.18.4.2. Macros for greatest-width integer constants */
|
||||
|
||||
#ifndef INTMAX_C
|
||||
# if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
|
||||
# define INTMAX_C(x) x##LL
|
||||
# elif defined GL_INT64_T
|
||||
# define INTMAX_C(x) INT64_C(x)
|
||||
# else
|
||||
# define INTMAX_C(x) x##L
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef UINTMAX_C
|
||||
# if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
|
||||
# define UINTMAX_C(x) x##ULL
|
||||
# elif defined GL_UINT64_T
|
||||
# define UINTMAX_C(x) UINT64_C(x)
|
||||
# else
|
||||
# define UINTMAX_C(x) x##UL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_STDINT_H */
|
||||
#endif /* !(defined __ANDROID__ && ...) */
|
||||
#endif /* !defined _@GUARD_PREFIX@_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */
|
||||
Generated
+463
@@ -0,0 +1,463 @@
|
||||
/* Charset conversion.
|
||||
Copyright (C) 2001-2007, 2010-2015 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible and Simon Josefsson.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "striconv.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_ICONV
|
||||
# include <iconv.h>
|
||||
/* Get MB_LEN_MAX, CHAR_BIT. */
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#include "c-strcase.h"
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
|
||||
|
||||
#if HAVE_ICONV
|
||||
|
||||
int
|
||||
mem_cd_iconv (const char *src, size_t srclen, iconv_t cd,
|
||||
char **resultp, size_t *lengthp)
|
||||
{
|
||||
# define tmpbufsize 4096
|
||||
size_t length;
|
||||
char *result;
|
||||
|
||||
/* Avoid glibc-2.1 bug and Solaris 2.7-2.9 bug. */
|
||||
# if defined _LIBICONV_VERSION \
|
||||
|| !(((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) && !defined __UCLIBC__) \
|
||||
|| defined __sun)
|
||||
/* Set to the initial state. */
|
||||
iconv (cd, NULL, NULL, NULL, NULL);
|
||||
# endif
|
||||
|
||||
/* Determine the length we need. */
|
||||
{
|
||||
size_t count = 0;
|
||||
/* The alignment is needed when converting e.g. to glibc's WCHAR_T or
|
||||
libiconv's UCS-4-INTERNAL encoding. */
|
||||
union { unsigned int align; char buf[tmpbufsize]; } tmp;
|
||||
# define tmpbuf tmp.buf
|
||||
const char *inptr = src;
|
||||
size_t insize = srclen;
|
||||
|
||||
while (insize > 0)
|
||||
{
|
||||
char *outptr = tmpbuf;
|
||||
size_t outsize = tmpbufsize;
|
||||
size_t res = iconv (cd,
|
||||
(ICONV_CONST char **) &inptr, &insize,
|
||||
&outptr, &outsize);
|
||||
|
||||
if (res == (size_t)(-1))
|
||||
{
|
||||
if (errno == E2BIG)
|
||||
;
|
||||
else if (errno == EINVAL)
|
||||
break;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
# if !defined _LIBICONV_VERSION && !(defined __GLIBC__ && !defined __UCLIBC__)
|
||||
/* Irix iconv() inserts a NUL byte if it cannot convert.
|
||||
NetBSD iconv() inserts a question mark if it cannot convert.
|
||||
Only GNU libiconv and GNU libc are known to prefer to fail rather
|
||||
than doing a lossy conversion. */
|
||||
else if (res > 0)
|
||||
{
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
}
|
||||
# endif
|
||||
count += outptr - tmpbuf;
|
||||
}
|
||||
/* Avoid glibc-2.1 bug and Solaris 2.7 bug. */
|
||||
# if defined _LIBICONV_VERSION \
|
||||
|| !(((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) && !defined __UCLIBC__) \
|
||||
|| defined __sun)
|
||||
{
|
||||
char *outptr = tmpbuf;
|
||||
size_t outsize = tmpbufsize;
|
||||
size_t res = iconv (cd, NULL, NULL, &outptr, &outsize);
|
||||
|
||||
if (res == (size_t)(-1))
|
||||
return -1;
|
||||
count += outptr - tmpbuf;
|
||||
}
|
||||
# endif
|
||||
length = count;
|
||||
# undef tmpbuf
|
||||
}
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
*lengthp = 0;
|
||||
return 0;
|
||||
}
|
||||
if (*resultp != NULL && *lengthp >= length)
|
||||
result = *resultp;
|
||||
else
|
||||
{
|
||||
result = (char *) malloc (length);
|
||||
if (result == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Avoid glibc-2.1 bug and Solaris 2.7-2.9 bug. */
|
||||
# if defined _LIBICONV_VERSION \
|
||||
|| !(((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) && !defined __UCLIBC__) \
|
||||
|| defined __sun)
|
||||
/* Return to the initial state. */
|
||||
iconv (cd, NULL, NULL, NULL, NULL);
|
||||
# endif
|
||||
|
||||
/* Do the conversion for real. */
|
||||
{
|
||||
const char *inptr = src;
|
||||
size_t insize = srclen;
|
||||
char *outptr = result;
|
||||
size_t outsize = length;
|
||||
|
||||
while (insize > 0)
|
||||
{
|
||||
size_t res = iconv (cd,
|
||||
(ICONV_CONST char **) &inptr, &insize,
|
||||
&outptr, &outsize);
|
||||
|
||||
if (res == (size_t)(-1))
|
||||
{
|
||||
if (errno == EINVAL)
|
||||
break;
|
||||
else
|
||||
goto fail;
|
||||
}
|
||||
# if !defined _LIBICONV_VERSION && !(defined __GLIBC__ && !defined __UCLIBC__)
|
||||
/* Irix iconv() inserts a NUL byte if it cannot convert.
|
||||
NetBSD iconv() inserts a question mark if it cannot convert.
|
||||
Only GNU libiconv and GNU libc are known to prefer to fail rather
|
||||
than doing a lossy conversion. */
|
||||
else if (res > 0)
|
||||
{
|
||||
errno = EILSEQ;
|
||||
goto fail;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
/* Avoid glibc-2.1 bug and Solaris 2.7 bug. */
|
||||
# if defined _LIBICONV_VERSION \
|
||||
|| !(((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) && !defined __UCLIBC__) \
|
||||
|| defined __sun)
|
||||
{
|
||||
size_t res = iconv (cd, NULL, NULL, &outptr, &outsize);
|
||||
|
||||
if (res == (size_t)(-1))
|
||||
goto fail;
|
||||
}
|
||||
# endif
|
||||
if (outsize != 0)
|
||||
abort ();
|
||||
}
|
||||
|
||||
*resultp = result;
|
||||
*lengthp = length;
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
{
|
||||
if (result != *resultp)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
free (result);
|
||||
errno = saved_errno;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
# undef tmpbufsize
|
||||
}
|
||||
|
||||
char *
|
||||
str_cd_iconv (const char *src, iconv_t cd)
|
||||
{
|
||||
/* For most encodings, a trailing NUL byte in the input will be converted
|
||||
to a trailing NUL byte in the output. But not for UTF-7. So that this
|
||||
function is usable for UTF-7, we have to exclude the NUL byte from the
|
||||
conversion and add it by hand afterwards. */
|
||||
# if !defined _LIBICONV_VERSION && !(defined __GLIBC__ && !defined __UCLIBC__)
|
||||
/* Irix iconv() inserts a NUL byte if it cannot convert.
|
||||
NetBSD iconv() inserts a question mark if it cannot convert.
|
||||
Only GNU libiconv and GNU libc are known to prefer to fail rather
|
||||
than doing a lossy conversion. For other iconv() implementations,
|
||||
we have to look at the number of irreversible conversions returned;
|
||||
but this information is lost when iconv() returns for an E2BIG reason.
|
||||
Therefore we cannot use the second, faster algorithm. */
|
||||
|
||||
char *result = NULL;
|
||||
size_t length = 0;
|
||||
int retval = mem_cd_iconv (src, strlen (src), cd, &result, &length);
|
||||
char *final_result;
|
||||
|
||||
if (retval < 0)
|
||||
{
|
||||
if (result != NULL)
|
||||
abort ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Add the terminating NUL byte. */
|
||||
final_result =
|
||||
(result != NULL ? realloc (result, length + 1) : malloc (length + 1));
|
||||
if (final_result == NULL)
|
||||
{
|
||||
free (result);
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
final_result[length] = '\0';
|
||||
|
||||
return final_result;
|
||||
|
||||
# else
|
||||
/* This algorithm is likely faster than the one above. But it may produce
|
||||
iconv() returns for an E2BIG reason, when the output size guess is too
|
||||
small. Therefore it can only be used when we don't need the number of
|
||||
irreversible conversions performed. */
|
||||
char *result;
|
||||
size_t result_size;
|
||||
size_t length;
|
||||
const char *inptr = src;
|
||||
size_t inbytes_remaining = strlen (src);
|
||||
|
||||
/* Make a guess for the worst-case output size, in order to avoid a
|
||||
realloc. It's OK if the guess is wrong as long as it is not zero and
|
||||
doesn't lead to an integer overflow. */
|
||||
result_size = inbytes_remaining;
|
||||
{
|
||||
size_t approx_sqrt_SIZE_MAX = SIZE_MAX >> (sizeof (size_t) * CHAR_BIT / 2);
|
||||
if (result_size <= approx_sqrt_SIZE_MAX / MB_LEN_MAX)
|
||||
result_size *= MB_LEN_MAX;
|
||||
}
|
||||
result_size += 1; /* for the terminating NUL */
|
||||
|
||||
result = (char *) malloc (result_size);
|
||||
if (result == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Avoid glibc-2.1 bug and Solaris 2.7-2.9 bug. */
|
||||
# if defined _LIBICONV_VERSION \
|
||||
|| !(((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) && !defined __UCLIBC__) \
|
||||
|| defined __sun)
|
||||
/* Set to the initial state. */
|
||||
iconv (cd, NULL, NULL, NULL, NULL);
|
||||
# endif
|
||||
|
||||
/* Do the conversion. */
|
||||
{
|
||||
char *outptr = result;
|
||||
size_t outbytes_remaining = result_size - 1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Here inptr + inbytes_remaining = src + strlen (src),
|
||||
outptr + outbytes_remaining = result + result_size - 1. */
|
||||
size_t res = iconv (cd,
|
||||
(ICONV_CONST char **) &inptr, &inbytes_remaining,
|
||||
&outptr, &outbytes_remaining);
|
||||
|
||||
if (res == (size_t)(-1))
|
||||
{
|
||||
if (errno == EINVAL)
|
||||
break;
|
||||
else if (errno == E2BIG)
|
||||
{
|
||||
size_t used = outptr - result;
|
||||
size_t newsize = result_size * 2;
|
||||
char *newresult;
|
||||
|
||||
if (!(newsize > result_size))
|
||||
{
|
||||
errno = ENOMEM;
|
||||
goto failed;
|
||||
}
|
||||
newresult = (char *) realloc (result, newsize);
|
||||
if (newresult == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
goto failed;
|
||||
}
|
||||
result = newresult;
|
||||
result_size = newsize;
|
||||
outptr = result + used;
|
||||
outbytes_remaining = result_size - 1 - used;
|
||||
}
|
||||
else
|
||||
goto failed;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
/* Avoid glibc-2.1 bug and Solaris 2.7 bug. */
|
||||
# if defined _LIBICONV_VERSION \
|
||||
|| !(((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) && !defined __UCLIBC__) \
|
||||
|| defined __sun)
|
||||
for (;;)
|
||||
{
|
||||
/* Here outptr + outbytes_remaining = result + result_size - 1. */
|
||||
size_t res = iconv (cd, NULL, NULL, &outptr, &outbytes_remaining);
|
||||
|
||||
if (res == (size_t)(-1))
|
||||
{
|
||||
if (errno == E2BIG)
|
||||
{
|
||||
size_t used = outptr - result;
|
||||
size_t newsize = result_size * 2;
|
||||
char *newresult;
|
||||
|
||||
if (!(newsize > result_size))
|
||||
{
|
||||
errno = ENOMEM;
|
||||
goto failed;
|
||||
}
|
||||
newresult = (char *) realloc (result, newsize);
|
||||
if (newresult == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
goto failed;
|
||||
}
|
||||
result = newresult;
|
||||
result_size = newsize;
|
||||
outptr = result + used;
|
||||
outbytes_remaining = result_size - 1 - used;
|
||||
}
|
||||
else
|
||||
goto failed;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Add the terminating NUL byte. */
|
||||
*outptr++ = '\0';
|
||||
|
||||
length = outptr - result;
|
||||
}
|
||||
|
||||
/* Give away unused memory. */
|
||||
if (length < result_size)
|
||||
{
|
||||
char *smaller_result = (char *) realloc (result, length);
|
||||
|
||||
if (smaller_result != NULL)
|
||||
result = smaller_result;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
failed:
|
||||
{
|
||||
int saved_errno = errno;
|
||||
free (result);
|
||||
errno = saved_errno;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
char *
|
||||
str_iconv (const char *src, const char *from_codeset, const char *to_codeset)
|
||||
{
|
||||
if (*src == '\0' || c_strcasecmp (from_codeset, to_codeset) == 0)
|
||||
{
|
||||
char *result = strdup (src);
|
||||
|
||||
if (result == NULL)
|
||||
errno = ENOMEM;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if HAVE_ICONV
|
||||
iconv_t cd;
|
||||
char *result;
|
||||
|
||||
/* Avoid glibc-2.1 bug with EUC-KR. */
|
||||
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) && !defined __UCLIBC__) \
|
||||
&& !defined _LIBICONV_VERSION
|
||||
if (c_strcasecmp (from_codeset, "EUC-KR") == 0
|
||||
|| c_strcasecmp (to_codeset, "EUC-KR") == 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
# endif
|
||||
cd = iconv_open (to_codeset, from_codeset);
|
||||
if (cd == (iconv_t) -1)
|
||||
return NULL;
|
||||
|
||||
result = str_cd_iconv (src, cd);
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
/* Close cd, but preserve the errno from str_cd_iconv. */
|
||||
int saved_errno = errno;
|
||||
iconv_close (cd);
|
||||
errno = saved_errno;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iconv_close (cd) < 0)
|
||||
{
|
||||
/* Return NULL, but free the allocated memory, and while doing
|
||||
that, preserve the errno from iconv_close. */
|
||||
int saved_errno = errno;
|
||||
free (result);
|
||||
errno = saved_errno;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
#else
|
||||
/* This is a different error code than if iconv_open existed but didn't
|
||||
support from_codeset and to_codeset, so that the caller can emit
|
||||
an error message such as
|
||||
"iconv() is not supported. Installing GNU libiconv and
|
||||
then reinstalling this package would fix this." */
|
||||
errno = ENOSYS;
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Generated
+75
@@ -0,0 +1,75 @@
|
||||
/* Charset conversion.
|
||||
Copyright (C) 2001-2004, 2006-2007, 2009-2015 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible and Simon Josefsson.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _STRICONV_H
|
||||
#define _STRICONV_H
|
||||
|
||||
#include <stddef.h>
|
||||
#if HAVE_ICONV
|
||||
#include <iconv.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if HAVE_ICONV
|
||||
|
||||
/* Convert an entire string from one encoding to another, using iconv.
|
||||
The original string is at [SRC,...,SRC+SRCLEN-1].
|
||||
The conversion descriptor is passed as CD.
|
||||
*RESULTP and *LENGTH should initially be a scratch buffer and its size,
|
||||
or *RESULTP can initially be NULL.
|
||||
May erase the contents of the memory at *RESULTP.
|
||||
Return value: 0 if successful, otherwise -1 and errno set.
|
||||
If successful: The resulting string is stored in *RESULTP and its length
|
||||
in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
|
||||
unchanged if no dynamic memory allocation was necessary. */
|
||||
extern int mem_cd_iconv (const char *src, size_t srclen, iconv_t cd,
|
||||
char **resultp, size_t *lengthp);
|
||||
|
||||
/* Convert an entire string from one encoding to another, using iconv.
|
||||
The original string is the NUL-terminated string starting at SRC.
|
||||
The conversion descriptor is passed as CD. Both the "from" and the "to"
|
||||
encoding must use a single NUL byte at the end of the string (i.e. not
|
||||
UCS-2, UCS-4, UTF-16, UTF-32).
|
||||
Allocate a malloced memory block for the result.
|
||||
Return value: the freshly allocated resulting NUL-terminated string if
|
||||
successful, otherwise NULL and errno set. */
|
||||
extern char * str_cd_iconv (const char *src, iconv_t cd);
|
||||
|
||||
#endif
|
||||
|
||||
/* Convert an entire string from one encoding to another, using iconv.
|
||||
The original string is the NUL-terminated string starting at SRC.
|
||||
Both the "from" and the "to" encoding must use a single NUL byte at the
|
||||
end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
|
||||
Allocate a malloced memory block for the result.
|
||||
Return value: the freshly allocated resulting NUL-terminated string if
|
||||
successful, otherwise NULL and errno set. */
|
||||
extern char * str_iconv (const char *src,
|
||||
const char *from_codeset, const char *to_codeset);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _STRICONV_H */
|
||||
Generated
+2
@@ -0,0 +1,2 @@
|
||||
int strverscmp (const char *s1, const char *s2);
|
||||
#include_next <string.h>
|
||||
Generated
+1046
File diff suppressed because it is too large.
Load diff
Generated
+131
@@ -0,0 +1,131 @@
|
||||
/* Compare strings while treating digits characters numerically.
|
||||
Copyright (C) 1997, 2000, 2002, 2004, 2006, 2009-2015 Free Software
|
||||
Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Jean-François Bignolles <bignolle@ecoledoc.ibp.fr>, 1997.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#if !_LIBC
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* states: S_N: normal, S_I: comparing integral part, S_F: comparing
|
||||
fractional parts, S_Z: idem but with leading Zeroes only */
|
||||
#define S_N 0x0
|
||||
#define S_I 0x4
|
||||
#define S_F 0x8
|
||||
#define S_Z 0xC
|
||||
|
||||
/* result_type: CMP: return diff; LEN: compare using len_diff/diff */
|
||||
#define CMP 2
|
||||
#define LEN 3
|
||||
|
||||
|
||||
/* ISDIGIT differs from isdigit, as follows:
|
||||
- Its arg may be any int or unsigned int; it need not be an unsigned char
|
||||
or EOF.
|
||||
- It's typically faster.
|
||||
POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
|
||||
isdigit unless it's important to use the locale's definition
|
||||
of "digit" even when the host does not conform to POSIX. */
|
||||
#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
|
||||
|
||||
#undef __strverscmp
|
||||
#undef strverscmp
|
||||
|
||||
#ifndef weak_alias
|
||||
# define __strverscmp strverscmp
|
||||
#endif
|
||||
|
||||
/* Compare S1 and S2 as strings holding indices/version numbers,
|
||||
returning less than, equal to or greater than zero if S1 is less than,
|
||||
equal to or greater than S2 (for more info, see the texinfo doc).
|
||||
*/
|
||||
|
||||
int
|
||||
__strverscmp (const char *s1, const char *s2)
|
||||
{
|
||||
const unsigned char *p1 = (const unsigned char *) s1;
|
||||
const unsigned char *p2 = (const unsigned char *) s2;
|
||||
unsigned char c1, c2;
|
||||
int state;
|
||||
int diff;
|
||||
|
||||
/* Symbol(s) 0 [1-9] others (padding)
|
||||
Transition (10) 0 (01) d (00) x (11) - */
|
||||
static const unsigned int next_state[] =
|
||||
{
|
||||
/* state x d 0 - */
|
||||
/* S_N */ S_N, S_I, S_Z, S_N,
|
||||
/* S_I */ S_N, S_I, S_I, S_I,
|
||||
/* S_F */ S_N, S_F, S_F, S_F,
|
||||
/* S_Z */ S_N, S_F, S_Z, S_Z
|
||||
};
|
||||
|
||||
static const int result_type[] =
|
||||
{
|
||||
/* state x/x x/d x/0 x/- d/x d/d d/0 d/-
|
||||
0/x 0/d 0/0 0/- -/x -/d -/0 -/- */
|
||||
|
||||
/* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
|
||||
CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
|
||||
/* S_I */ CMP, -1, -1, CMP, 1, LEN, LEN, CMP,
|
||||
1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
|
||||
/* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
|
||||
CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
|
||||
/* S_Z */ CMP, 1, 1, CMP, -1, CMP, CMP, CMP,
|
||||
-1, CMP, CMP, CMP
|
||||
};
|
||||
|
||||
if (p1 == p2)
|
||||
return 0;
|
||||
|
||||
c1 = *p1++;
|
||||
c2 = *p2++;
|
||||
/* Hint: '0' is a digit too. */
|
||||
state = S_N | ((c1 == '0') + (ISDIGIT (c1) != 0));
|
||||
|
||||
while ((diff = c1 - c2) == 0 && c1 != '\0')
|
||||
{
|
||||
state = next_state[state];
|
||||
c1 = *p1++;
|
||||
c2 = *p2++;
|
||||
state |= (c1 == '0') + (ISDIGIT (c1) != 0);
|
||||
}
|
||||
|
||||
state = result_type[state << 2 | ((c2 == '0') + (ISDIGIT (c2) != 0))];
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case CMP:
|
||||
return diff;
|
||||
|
||||
case LEN:
|
||||
while (ISDIGIT (*p1++))
|
||||
if (!ISDIGIT (*p2++))
|
||||
return 1;
|
||||
|
||||
return ISDIGIT (*p2) ? -1 : diff;
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
#ifdef weak_alias
|
||||
weak_alias (__strverscmp, strverscmp)
|
||||
#endif
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/* Provide a more complete sys/types.h.
|
||||
|
||||
Copyright (C) 2011-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_SYS_TYPES_H
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
# define _GL_INCLUDING_SYS_TYPES_H
|
||||
#@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@
|
||||
# undef _GL_INCLUDING_SYS_TYPES_H
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_SYS_TYPES_H
|
||||
#define _@GUARD_PREFIX@_SYS_TYPES_H
|
||||
|
||||
/* Override off_t if Large File Support is requested on native Windows. */
|
||||
#if @WINDOWS_64_BIT_OFF_T@
|
||||
/* Same as int64_t in <stdint.h>. */
|
||||
# if defined _MSC_VER
|
||||
# define off_t __int64
|
||||
# else
|
||||
# define off_t long long int
|
||||
# endif
|
||||
/* Indicator, for gnulib internal purposes. */
|
||||
# define _GL_WINDOWS_64_BIT_OFF_T 1
|
||||
#endif
|
||||
|
||||
/* MSVC 9 defines size_t in <stddef.h>, not in <sys/types.h>. */
|
||||
/* But avoid namespace pollution on glibc systems. */
|
||||
#if ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) \
|
||||
&& ! defined __GLIBC__
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */
|
||||
#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */
|
||||
Generated
+750
@@ -0,0 +1,750 @@
|
||||
/* Elementary Unicode string functions.
|
||||
Copyright (C) 2001-2002, 2005-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _UNISTR_H
|
||||
#define _UNISTR_H
|
||||
|
||||
#include "unitypes.h"
|
||||
|
||||
/* Get common macros for C. */
|
||||
#include "unused-parameter.h"
|
||||
|
||||
/* Get bool. */
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Get size_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Conventions:
|
||||
|
||||
All functions prefixed with u8_ operate on UTF-8 encoded strings.
|
||||
Their unit is an uint8_t (1 byte).
|
||||
|
||||
All functions prefixed with u16_ operate on UTF-16 encoded strings.
|
||||
Their unit is an uint16_t (a 2-byte word).
|
||||
|
||||
All functions prefixed with u32_ operate on UCS-4 encoded strings.
|
||||
Their unit is an uint32_t (a 4-byte word).
|
||||
|
||||
All argument pairs (s, n) denote a Unicode string s[0..n-1] with exactly
|
||||
n units.
|
||||
|
||||
All arguments starting with "str" and the arguments of functions starting
|
||||
with u8_str/u16_str/u32_str denote a NUL terminated string, i.e. a string
|
||||
which terminates at the first NUL unit. This termination unit is
|
||||
considered part of the string for all memory allocation purposes, but
|
||||
is not considered part of the string for all other logical purposes.
|
||||
|
||||
Functions returning a string result take a (resultbuf, lengthp) argument
|
||||
pair. If resultbuf is not NULL and the result fits into *lengthp units,
|
||||
it is put in resultbuf, and resultbuf is returned. Otherwise, a freshly
|
||||
allocated string is returned. In both cases, *lengthp is set to the
|
||||
length (number of units) of the returned string. In case of error,
|
||||
NULL is returned and errno is set. */
|
||||
|
||||
|
||||
/* Elementary string checks. */
|
||||
|
||||
/* Check whether an UTF-8 string is well-formed.
|
||||
Return NULL if valid, or a pointer to the first invalid unit otherwise. */
|
||||
extern const uint8_t *
|
||||
u8_check (const uint8_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Check whether an UTF-16 string is well-formed.
|
||||
Return NULL if valid, or a pointer to the first invalid unit otherwise. */
|
||||
extern const uint16_t *
|
||||
u16_check (const uint16_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Check whether an UCS-4 string is well-formed.
|
||||
Return NULL if valid, or a pointer to the first invalid unit otherwise. */
|
||||
extern const uint32_t *
|
||||
u32_check (const uint32_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
|
||||
/* Elementary string conversions. */
|
||||
|
||||
/* Convert an UTF-8 string to an UTF-16 string. */
|
||||
extern uint16_t *
|
||||
u8_to_u16 (const uint8_t *s, size_t n, uint16_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
/* Convert an UTF-8 string to an UCS-4 string. */
|
||||
extern uint32_t *
|
||||
u8_to_u32 (const uint8_t *s, size_t n, uint32_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
/* Convert an UTF-16 string to an UTF-8 string. */
|
||||
extern uint8_t *
|
||||
u16_to_u8 (const uint16_t *s, size_t n, uint8_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
/* Convert an UTF-16 string to an UCS-4 string. */
|
||||
extern uint32_t *
|
||||
u16_to_u32 (const uint16_t *s, size_t n, uint32_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
/* Convert an UCS-4 string to an UTF-8 string. */
|
||||
extern uint8_t *
|
||||
u32_to_u8 (const uint32_t *s, size_t n, uint8_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
/* Convert an UCS-4 string to an UTF-16 string. */
|
||||
extern uint16_t *
|
||||
u32_to_u16 (const uint32_t *s, size_t n, uint16_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
|
||||
/* Elementary string functions. */
|
||||
|
||||
/* Return the length (number of units) of the first character in S, which is
|
||||
no longer than N. Return 0 if it is the NUL character. Return -1 upon
|
||||
failure. */
|
||||
/* Similar to mblen(), except that s must not be NULL. */
|
||||
extern int
|
||||
u8_mblen (const uint8_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_mblen (const uint16_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_mblen (const uint32_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the length (number of units) of the first character in S, putting
|
||||
its 'ucs4_t' representation in *PUC. Upon failure, *PUC is set to 0xfffd,
|
||||
and an appropriate number of units is returned.
|
||||
The number of available units, N, must be > 0. */
|
||||
/* Similar to mbtowc(), except that puc and s must not be NULL, n must be > 0,
|
||||
and the NUL character is not treated specially. */
|
||||
/* The variants with _safe suffix are safe, even if the library is compiled
|
||||
without --enable-safety. */
|
||||
|
||||
#if GNULIB_UNISTR_U8_MBTOUC_UNSAFE || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n);
|
||||
# else
|
||||
extern int
|
||||
u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n);
|
||||
static inline int
|
||||
u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n)
|
||||
{
|
||||
uint8_t c = *s;
|
||||
|
||||
if (c < 0x80)
|
||||
{
|
||||
*puc = c;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u8_mbtouc_unsafe_aux (puc, s, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U16_MBTOUC_UNSAFE || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n);
|
||||
# else
|
||||
extern int
|
||||
u16_mbtouc_unsafe_aux (ucs4_t *puc, const uint16_t *s, size_t n);
|
||||
static inline int
|
||||
u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n)
|
||||
{
|
||||
uint16_t c = *s;
|
||||
|
||||
if (c < 0xd800 || c >= 0xe000)
|
||||
{
|
||||
*puc = c;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u16_mbtouc_unsafe_aux (puc, s, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U32_MBTOUC_UNSAFE || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u32_mbtouc_unsafe (ucs4_t *puc, const uint32_t *s, size_t n);
|
||||
# else
|
||||
static inline int
|
||||
u32_mbtouc_unsafe (ucs4_t *puc,
|
||||
const uint32_t *s, size_t n _GL_UNUSED_PARAMETER)
|
||||
{
|
||||
uint32_t c = *s;
|
||||
|
||||
# if CONFIG_UNICODE_SAFETY
|
||||
if (c < 0xd800 || (c >= 0xe000 && c < 0x110000))
|
||||
# endif
|
||||
*puc = c;
|
||||
# if CONFIG_UNICODE_SAFETY
|
||||
else
|
||||
/* invalid multibyte character */
|
||||
*puc = 0xfffd;
|
||||
# endif
|
||||
return 1;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U8_MBTOUC || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n);
|
||||
# else
|
||||
extern int
|
||||
u8_mbtouc_aux (ucs4_t *puc, const uint8_t *s, size_t n);
|
||||
static inline int
|
||||
u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n)
|
||||
{
|
||||
uint8_t c = *s;
|
||||
|
||||
if (c < 0x80)
|
||||
{
|
||||
*puc = c;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u8_mbtouc_aux (puc, s, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U16_MBTOUC || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u16_mbtouc (ucs4_t *puc, const uint16_t *s, size_t n);
|
||||
# else
|
||||
extern int
|
||||
u16_mbtouc_aux (ucs4_t *puc, const uint16_t *s, size_t n);
|
||||
static inline int
|
||||
u16_mbtouc (ucs4_t *puc, const uint16_t *s, size_t n)
|
||||
{
|
||||
uint16_t c = *s;
|
||||
|
||||
if (c < 0xd800 || c >= 0xe000)
|
||||
{
|
||||
*puc = c;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u16_mbtouc_aux (puc, s, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U32_MBTOUC || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n);
|
||||
# else
|
||||
static inline int
|
||||
u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n _GL_UNUSED_PARAMETER)
|
||||
{
|
||||
uint32_t c = *s;
|
||||
|
||||
if (c < 0xd800 || (c >= 0xe000 && c < 0x110000))
|
||||
*puc = c;
|
||||
else
|
||||
/* invalid multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return 1;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Return the length (number of units) of the first character in S, putting
|
||||
its 'ucs4_t' representation in *PUC. Upon failure, *PUC is set to 0xfffd,
|
||||
and -1 is returned for an invalid sequence of units, -2 is returned for an
|
||||
incomplete sequence of units.
|
||||
The number of available units, N, must be > 0. */
|
||||
/* Similar to u*_mbtouc(), except that the return value gives more details
|
||||
about the failure, similar to mbrtowc(). */
|
||||
|
||||
#if GNULIB_UNISTR_U8_MBTOUCR || HAVE_LIBUNISTRING
|
||||
extern int
|
||||
u8_mbtoucr (ucs4_t *puc, const uint8_t *s, size_t n);
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U16_MBTOUCR || HAVE_LIBUNISTRING
|
||||
extern int
|
||||
u16_mbtoucr (ucs4_t *puc, const uint16_t *s, size_t n);
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U32_MBTOUCR || HAVE_LIBUNISTRING
|
||||
extern int
|
||||
u32_mbtoucr (ucs4_t *puc, const uint32_t *s, size_t n);
|
||||
#endif
|
||||
|
||||
/* Put the multibyte character represented by UC in S, returning its
|
||||
length. Return -1 upon failure, -2 if the number of available units, N,
|
||||
is too small. The latter case cannot occur if N >= 6/2/1, respectively. */
|
||||
/* Similar to wctomb(), except that s must not be NULL, and the argument n
|
||||
must be specified. */
|
||||
|
||||
#if GNULIB_UNISTR_U8_UCTOMB || HAVE_LIBUNISTRING
|
||||
/* Auxiliary function, also used by u8_chr, u8_strchr, u8_strrchr. */
|
||||
extern int
|
||||
u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n);
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u8_uctomb (uint8_t *s, ucs4_t uc, int n);
|
||||
# else
|
||||
static inline int
|
||||
u8_uctomb (uint8_t *s, ucs4_t uc, int n)
|
||||
{
|
||||
if (uc < 0x80 && n > 0)
|
||||
{
|
||||
s[0] = uc;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u8_uctomb_aux (s, uc, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U16_UCTOMB || HAVE_LIBUNISTRING
|
||||
/* Auxiliary function, also used by u16_chr, u16_strchr, u16_strrchr. */
|
||||
extern int
|
||||
u16_uctomb_aux (uint16_t *s, ucs4_t uc, int n);
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u16_uctomb (uint16_t *s, ucs4_t uc, int n);
|
||||
# else
|
||||
static inline int
|
||||
u16_uctomb (uint16_t *s, ucs4_t uc, int n)
|
||||
{
|
||||
if (uc < 0xd800 && n > 0)
|
||||
{
|
||||
s[0] = uc;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u16_uctomb_aux (s, uc, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U32_UCTOMB || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u32_uctomb (uint32_t *s, ucs4_t uc, int n);
|
||||
# else
|
||||
static inline int
|
||||
u32_uctomb (uint32_t *s, ucs4_t uc, int n)
|
||||
{
|
||||
if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000))
|
||||
{
|
||||
if (n > 0)
|
||||
{
|
||||
*s = uc;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Copy N units from SRC to DEST. */
|
||||
/* Similar to memcpy(). */
|
||||
extern uint8_t *
|
||||
u8_cpy (uint8_t *dest, const uint8_t *src, size_t n);
|
||||
extern uint16_t *
|
||||
u16_cpy (uint16_t *dest, const uint16_t *src, size_t n);
|
||||
extern uint32_t *
|
||||
u32_cpy (uint32_t *dest, const uint32_t *src, size_t n);
|
||||
|
||||
/* Copy N units from SRC to DEST, guaranteeing correct behavior for
|
||||
overlapping memory areas. */
|
||||
/* Similar to memmove(). */
|
||||
extern uint8_t *
|
||||
u8_move (uint8_t *dest, const uint8_t *src, size_t n);
|
||||
extern uint16_t *
|
||||
u16_move (uint16_t *dest, const uint16_t *src, size_t n);
|
||||
extern uint32_t *
|
||||
u32_move (uint32_t *dest, const uint32_t *src, size_t n);
|
||||
|
||||
/* Set the first N characters of S to UC. UC should be a character that
|
||||
occupies only 1 unit. */
|
||||
/* Similar to memset(). */
|
||||
extern uint8_t *
|
||||
u8_set (uint8_t *s, ucs4_t uc, size_t n);
|
||||
extern uint16_t *
|
||||
u16_set (uint16_t *s, ucs4_t uc, size_t n);
|
||||
extern uint32_t *
|
||||
u32_set (uint32_t *s, ucs4_t uc, size_t n);
|
||||
|
||||
/* Compare S1 and S2, each of length N. */
|
||||
/* Similar to memcmp(). */
|
||||
extern int
|
||||
u8_cmp (const uint8_t *s1, const uint8_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_cmp (const uint16_t *s1, const uint16_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Compare S1 and S2. */
|
||||
/* Similar to the gnulib function memcmp2(). */
|
||||
extern int
|
||||
u8_cmp2 (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_cmp2 (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_cmp2 (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Search the string at S for UC. */
|
||||
/* Similar to memchr(). */
|
||||
extern uint8_t *
|
||||
u8_chr (const uint8_t *s, size_t n, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint16_t *
|
||||
u16_chr (const uint16_t *s, size_t n, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint32_t *
|
||||
u32_chr (const uint32_t *s, size_t n, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Count the number of Unicode characters in the N units from S. */
|
||||
/* Similar to mbsnlen(). */
|
||||
extern size_t
|
||||
u8_mbsnlen (const uint8_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u16_mbsnlen (const uint16_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u32_mbsnlen (const uint32_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Elementary string functions with memory allocation. */
|
||||
|
||||
/* Make a freshly allocated copy of S, of length N. */
|
||||
extern uint8_t *
|
||||
u8_cpy_alloc (const uint8_t *s, size_t n);
|
||||
extern uint16_t *
|
||||
u16_cpy_alloc (const uint16_t *s, size_t n);
|
||||
extern uint32_t *
|
||||
u32_cpy_alloc (const uint32_t *s, size_t n);
|
||||
|
||||
/* Elementary string functions on NUL terminated strings. */
|
||||
|
||||
/* Return the length (number of units) of the first character in S.
|
||||
Return 0 if it is the NUL character. Return -1 upon failure. */
|
||||
extern int
|
||||
u8_strmblen (const uint8_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_strmblen (const uint16_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_strmblen (const uint32_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the length (number of units) of the first character in S, putting
|
||||
its 'ucs4_t' representation in *PUC. Return 0 if it is the NUL
|
||||
character. Return -1 upon failure. */
|
||||
extern int
|
||||
u8_strmbtouc (ucs4_t *puc, const uint8_t *s);
|
||||
extern int
|
||||
u16_strmbtouc (ucs4_t *puc, const uint16_t *s);
|
||||
extern int
|
||||
u32_strmbtouc (ucs4_t *puc, const uint32_t *s);
|
||||
|
||||
/* Forward iteration step. Advances the pointer past the next character,
|
||||
or returns NULL if the end of the string has been reached. Puts the
|
||||
character's 'ucs4_t' representation in *PUC. */
|
||||
extern const uint8_t *
|
||||
u8_next (ucs4_t *puc, const uint8_t *s);
|
||||
extern const uint16_t *
|
||||
u16_next (ucs4_t *puc, const uint16_t *s);
|
||||
extern const uint32_t *
|
||||
u32_next (ucs4_t *puc, const uint32_t *s);
|
||||
|
||||
/* Backward iteration step. Advances the pointer to point to the previous
|
||||
character, or returns NULL if the beginning of the string had been reached.
|
||||
Puts the character's 'ucs4_t' representation in *PUC. */
|
||||
extern const uint8_t *
|
||||
u8_prev (ucs4_t *puc, const uint8_t *s, const uint8_t *start);
|
||||
extern const uint16_t *
|
||||
u16_prev (ucs4_t *puc, const uint16_t *s, const uint16_t *start);
|
||||
extern const uint32_t *
|
||||
u32_prev (ucs4_t *puc, const uint32_t *s, const uint32_t *start);
|
||||
|
||||
/* Return the number of units in S. */
|
||||
/* Similar to strlen(), wcslen(). */
|
||||
extern size_t
|
||||
u8_strlen (const uint8_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u16_strlen (const uint16_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u32_strlen (const uint32_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the number of units in S, but at most MAXLEN. */
|
||||
/* Similar to strnlen(), wcsnlen(). */
|
||||
extern size_t
|
||||
u8_strnlen (const uint8_t *s, size_t maxlen)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u16_strnlen (const uint16_t *s, size_t maxlen)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u32_strnlen (const uint32_t *s, size_t maxlen)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Copy SRC to DEST. */
|
||||
/* Similar to strcpy(), wcscpy(). */
|
||||
extern uint8_t *
|
||||
u8_strcpy (uint8_t *dest, const uint8_t *src);
|
||||
extern uint16_t *
|
||||
u16_strcpy (uint16_t *dest, const uint16_t *src);
|
||||
extern uint32_t *
|
||||
u32_strcpy (uint32_t *dest, const uint32_t *src);
|
||||
|
||||
/* Copy SRC to DEST, returning the address of the terminating NUL in DEST. */
|
||||
/* Similar to stpcpy(). */
|
||||
extern uint8_t *
|
||||
u8_stpcpy (uint8_t *dest, const uint8_t *src);
|
||||
extern uint16_t *
|
||||
u16_stpcpy (uint16_t *dest, const uint16_t *src);
|
||||
extern uint32_t *
|
||||
u32_stpcpy (uint32_t *dest, const uint32_t *src);
|
||||
|
||||
/* Copy no more than N units of SRC to DEST. */
|
||||
/* Similar to strncpy(), wcsncpy(). */
|
||||
extern uint8_t *
|
||||
u8_strncpy (uint8_t *dest, const uint8_t *src, size_t n);
|
||||
extern uint16_t *
|
||||
u16_strncpy (uint16_t *dest, const uint16_t *src, size_t n);
|
||||
extern uint32_t *
|
||||
u32_strncpy (uint32_t *dest, const uint32_t *src, size_t n);
|
||||
|
||||
/* Copy no more than N units of SRC to DEST. Return a pointer past the last
|
||||
non-NUL unit written into DEST. */
|
||||
/* Similar to stpncpy(). */
|
||||
extern uint8_t *
|
||||
u8_stpncpy (uint8_t *dest, const uint8_t *src, size_t n);
|
||||
extern uint16_t *
|
||||
u16_stpncpy (uint16_t *dest, const uint16_t *src, size_t n);
|
||||
extern uint32_t *
|
||||
u32_stpncpy (uint32_t *dest, const uint32_t *src, size_t n);
|
||||
|
||||
/* Append SRC onto DEST. */
|
||||
/* Similar to strcat(), wcscat(). */
|
||||
extern uint8_t *
|
||||
u8_strcat (uint8_t *dest, const uint8_t *src);
|
||||
extern uint16_t *
|
||||
u16_strcat (uint16_t *dest, const uint16_t *src);
|
||||
extern uint32_t *
|
||||
u32_strcat (uint32_t *dest, const uint32_t *src);
|
||||
|
||||
/* Append no more than N units of SRC onto DEST. */
|
||||
/* Similar to strncat(), wcsncat(). */
|
||||
extern uint8_t *
|
||||
u8_strncat (uint8_t *dest, const uint8_t *src, size_t n);
|
||||
extern uint16_t *
|
||||
u16_strncat (uint16_t *dest, const uint16_t *src, size_t n);
|
||||
extern uint32_t *
|
||||
u32_strncat (uint32_t *dest, const uint32_t *src, size_t n);
|
||||
|
||||
/* Compare S1 and S2. */
|
||||
/* Similar to strcmp(), wcscmp(). */
|
||||
#ifdef __sun
|
||||
/* Avoid a collision with the u8_strcmp() function in Solaris 11 libc. */
|
||||
extern int
|
||||
u8_strcmp_gnu (const uint8_t *s1, const uint8_t *s2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
# define u8_strcmp u8_strcmp_gnu
|
||||
#else
|
||||
extern int
|
||||
u8_strcmp (const uint8_t *s1, const uint8_t *s2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
#endif
|
||||
extern int
|
||||
u16_strcmp (const uint16_t *s1, const uint16_t *s2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_strcmp (const uint32_t *s1, const uint32_t *s2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Compare S1 and S2 using the collation rules of the current locale.
|
||||
Return -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2.
|
||||
Upon failure, set errno and return any value. */
|
||||
/* Similar to strcoll(), wcscoll(). */
|
||||
extern int
|
||||
u8_strcoll (const uint8_t *s1, const uint8_t *s2);
|
||||
extern int
|
||||
u16_strcoll (const uint16_t *s1, const uint16_t *s2);
|
||||
extern int
|
||||
u32_strcoll (const uint32_t *s1, const uint32_t *s2);
|
||||
|
||||
/* Compare no more than N units of S1 and S2. */
|
||||
/* Similar to strncmp(), wcsncmp(). */
|
||||
extern int
|
||||
u8_strncmp (const uint8_t *s1, const uint8_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_strncmp (const uint16_t *s1, const uint16_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_strncmp (const uint32_t *s1, const uint32_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Duplicate S, returning an identical malloc'd string. */
|
||||
/* Similar to strdup(), wcsdup(). */
|
||||
extern uint8_t *
|
||||
u8_strdup (const uint8_t *s);
|
||||
extern uint16_t *
|
||||
u16_strdup (const uint16_t *s);
|
||||
extern uint32_t *
|
||||
u32_strdup (const uint32_t *s);
|
||||
|
||||
/* Find the first occurrence of UC in STR. */
|
||||
/* Similar to strchr(), wcschr(). */
|
||||
extern uint8_t *
|
||||
u8_strchr (const uint8_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint16_t *
|
||||
u16_strchr (const uint16_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint32_t *
|
||||
u32_strchr (const uint32_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Find the last occurrence of UC in STR. */
|
||||
/* Similar to strrchr(), wcsrchr(). */
|
||||
extern uint8_t *
|
||||
u8_strrchr (const uint8_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint16_t *
|
||||
u16_strrchr (const uint16_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint32_t *
|
||||
u32_strrchr (const uint32_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the length of the initial segment of STR which consists entirely
|
||||
of Unicode characters not in REJECT. */
|
||||
/* Similar to strcspn(), wcscspn(). */
|
||||
extern size_t
|
||||
u8_strcspn (const uint8_t *str, const uint8_t *reject)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u16_strcspn (const uint16_t *str, const uint16_t *reject)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u32_strcspn (const uint32_t *str, const uint32_t *reject)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the length of the initial segment of STR which consists entirely
|
||||
of Unicode characters in ACCEPT. */
|
||||
/* Similar to strspn(), wcsspn(). */
|
||||
extern size_t
|
||||
u8_strspn (const uint8_t *str, const uint8_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u16_strspn (const uint16_t *str, const uint16_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u32_strspn (const uint32_t *str, const uint32_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Find the first occurrence in STR of any character in ACCEPT. */
|
||||
/* Similar to strpbrk(), wcspbrk(). */
|
||||
extern uint8_t *
|
||||
u8_strpbrk (const uint8_t *str, const uint8_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint16_t *
|
||||
u16_strpbrk (const uint16_t *str, const uint16_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint32_t *
|
||||
u32_strpbrk (const uint32_t *str, const uint32_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Find the first occurrence of NEEDLE in HAYSTACK. */
|
||||
/* Similar to strstr(), wcsstr(). */
|
||||
extern uint8_t *
|
||||
u8_strstr (const uint8_t *haystack, const uint8_t *needle)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint16_t *
|
||||
u16_strstr (const uint16_t *haystack, const uint16_t *needle)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint32_t *
|
||||
u32_strstr (const uint32_t *haystack, const uint32_t *needle)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Test whether STR starts with PREFIX. */
|
||||
extern bool
|
||||
u8_startswith (const uint8_t *str, const uint8_t *prefix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern bool
|
||||
u16_startswith (const uint16_t *str, const uint16_t *prefix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern bool
|
||||
u32_startswith (const uint32_t *str, const uint32_t *prefix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Test whether STR ends with SUFFIX. */
|
||||
extern bool
|
||||
u8_endswith (const uint8_t *str, const uint8_t *suffix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern bool
|
||||
u16_endswith (const uint16_t *str, const uint16_t *suffix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern bool
|
||||
u32_endswith (const uint32_t *str, const uint32_t *suffix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Divide STR into tokens separated by characters in DELIM.
|
||||
This interface is actually more similar to wcstok than to strtok. */
|
||||
/* Similar to strtok_r(), wcstok(). */
|
||||
extern uint8_t *
|
||||
u8_strtok (uint8_t *str, const uint8_t *delim, uint8_t **ptr);
|
||||
extern uint16_t *
|
||||
u16_strtok (uint16_t *str, const uint16_t *delim, uint16_t **ptr);
|
||||
extern uint32_t *
|
||||
u32_strtok (uint32_t *str, const uint32_t *delim, uint32_t **ptr);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _UNISTR_H */
|
||||
Generated
+750
@@ -0,0 +1,750 @@
|
||||
/* Elementary Unicode string functions.
|
||||
Copyright (C) 2001-2002, 2005-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _UNISTR_H
|
||||
#define _UNISTR_H
|
||||
|
||||
#include "unitypes.h"
|
||||
|
||||
/* Get common macros for C. */
|
||||
#include "unused-parameter.h"
|
||||
|
||||
/* Get bool. */
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Get size_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Conventions:
|
||||
|
||||
All functions prefixed with u8_ operate on UTF-8 encoded strings.
|
||||
Their unit is an uint8_t (1 byte).
|
||||
|
||||
All functions prefixed with u16_ operate on UTF-16 encoded strings.
|
||||
Their unit is an uint16_t (a 2-byte word).
|
||||
|
||||
All functions prefixed with u32_ operate on UCS-4 encoded strings.
|
||||
Their unit is an uint32_t (a 4-byte word).
|
||||
|
||||
All argument pairs (s, n) denote a Unicode string s[0..n-1] with exactly
|
||||
n units.
|
||||
|
||||
All arguments starting with "str" and the arguments of functions starting
|
||||
with u8_str/u16_str/u32_str denote a NUL terminated string, i.e. a string
|
||||
which terminates at the first NUL unit. This termination unit is
|
||||
considered part of the string for all memory allocation purposes, but
|
||||
is not considered part of the string for all other logical purposes.
|
||||
|
||||
Functions returning a string result take a (resultbuf, lengthp) argument
|
||||
pair. If resultbuf is not NULL and the result fits into *lengthp units,
|
||||
it is put in resultbuf, and resultbuf is returned. Otherwise, a freshly
|
||||
allocated string is returned. In both cases, *lengthp is set to the
|
||||
length (number of units) of the returned string. In case of error,
|
||||
NULL is returned and errno is set. */
|
||||
|
||||
|
||||
/* Elementary string checks. */
|
||||
|
||||
/* Check whether an UTF-8 string is well-formed.
|
||||
Return NULL if valid, or a pointer to the first invalid unit otherwise. */
|
||||
extern const uint8_t *
|
||||
u8_check (const uint8_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Check whether an UTF-16 string is well-formed.
|
||||
Return NULL if valid, or a pointer to the first invalid unit otherwise. */
|
||||
extern const uint16_t *
|
||||
u16_check (const uint16_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Check whether an UCS-4 string is well-formed.
|
||||
Return NULL if valid, or a pointer to the first invalid unit otherwise. */
|
||||
extern const uint32_t *
|
||||
u32_check (const uint32_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
|
||||
/* Elementary string conversions. */
|
||||
|
||||
/* Convert an UTF-8 string to an UTF-16 string. */
|
||||
extern uint16_t *
|
||||
u8_to_u16 (const uint8_t *s, size_t n, uint16_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
/* Convert an UTF-8 string to an UCS-4 string. */
|
||||
extern uint32_t *
|
||||
u8_to_u32 (const uint8_t *s, size_t n, uint32_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
/* Convert an UTF-16 string to an UTF-8 string. */
|
||||
extern uint8_t *
|
||||
u16_to_u8 (const uint16_t *s, size_t n, uint8_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
/* Convert an UTF-16 string to an UCS-4 string. */
|
||||
extern uint32_t *
|
||||
u16_to_u32 (const uint16_t *s, size_t n, uint32_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
/* Convert an UCS-4 string to an UTF-8 string. */
|
||||
extern uint8_t *
|
||||
u32_to_u8 (const uint32_t *s, size_t n, uint8_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
/* Convert an UCS-4 string to an UTF-16 string. */
|
||||
extern uint16_t *
|
||||
u32_to_u16 (const uint32_t *s, size_t n, uint16_t *resultbuf,
|
||||
size_t *lengthp);
|
||||
|
||||
|
||||
/* Elementary string functions. */
|
||||
|
||||
/* Return the length (number of units) of the first character in S, which is
|
||||
no longer than N. Return 0 if it is the NUL character. Return -1 upon
|
||||
failure. */
|
||||
/* Similar to mblen(), except that s must not be NULL. */
|
||||
extern int
|
||||
u8_mblen (const uint8_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_mblen (const uint16_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_mblen (const uint32_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the length (number of units) of the first character in S, putting
|
||||
its 'ucs4_t' representation in *PUC. Upon failure, *PUC is set to 0xfffd,
|
||||
and an appropriate number of units is returned.
|
||||
The number of available units, N, must be > 0. */
|
||||
/* Similar to mbtowc(), except that puc and s must not be NULL, n must be > 0,
|
||||
and the NUL character is not treated specially. */
|
||||
/* The variants with _safe suffix are safe, even if the library is compiled
|
||||
without --enable-safety. */
|
||||
|
||||
#if GNULIB_UNISTR_U8_MBTOUC_UNSAFE || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n);
|
||||
# else
|
||||
extern int
|
||||
u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n);
|
||||
static inline int
|
||||
u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n)
|
||||
{
|
||||
uint8_t c = *s;
|
||||
|
||||
if (c < 0x80)
|
||||
{
|
||||
*puc = c;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u8_mbtouc_unsafe_aux (puc, s, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U16_MBTOUC_UNSAFE || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n);
|
||||
# else
|
||||
extern int
|
||||
u16_mbtouc_unsafe_aux (ucs4_t *puc, const uint16_t *s, size_t n);
|
||||
static inline int
|
||||
u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n)
|
||||
{
|
||||
uint16_t c = *s;
|
||||
|
||||
if (c < 0xd800 || c >= 0xe000)
|
||||
{
|
||||
*puc = c;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u16_mbtouc_unsafe_aux (puc, s, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U32_MBTOUC_UNSAFE || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u32_mbtouc_unsafe (ucs4_t *puc, const uint32_t *s, size_t n);
|
||||
# else
|
||||
static inline int
|
||||
u32_mbtouc_unsafe (ucs4_t *puc,
|
||||
const uint32_t *s, size_t n _GL_UNUSED_PARAMETER)
|
||||
{
|
||||
uint32_t c = *s;
|
||||
|
||||
# if CONFIG_UNICODE_SAFETY
|
||||
if (c < 0xd800 || (c >= 0xe000 && c < 0x110000))
|
||||
# endif
|
||||
*puc = c;
|
||||
# if CONFIG_UNICODE_SAFETY
|
||||
else
|
||||
/* invalid multibyte character */
|
||||
*puc = 0xfffd;
|
||||
# endif
|
||||
return 1;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U8_MBTOUC || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n);
|
||||
# else
|
||||
extern int
|
||||
u8_mbtouc_aux (ucs4_t *puc, const uint8_t *s, size_t n);
|
||||
static inline int
|
||||
u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n)
|
||||
{
|
||||
uint8_t c = *s;
|
||||
|
||||
if (c < 0x80)
|
||||
{
|
||||
*puc = c;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u8_mbtouc_aux (puc, s, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U16_MBTOUC || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u16_mbtouc (ucs4_t *puc, const uint16_t *s, size_t n);
|
||||
# else
|
||||
extern int
|
||||
u16_mbtouc_aux (ucs4_t *puc, const uint16_t *s, size_t n);
|
||||
static inline int
|
||||
u16_mbtouc (ucs4_t *puc, const uint16_t *s, size_t n)
|
||||
{
|
||||
uint16_t c = *s;
|
||||
|
||||
if (c < 0xd800 || c >= 0xe000)
|
||||
{
|
||||
*puc = c;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u16_mbtouc_aux (puc, s, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U32_MBTOUC || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n);
|
||||
# else
|
||||
static inline int
|
||||
u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n _GL_UNUSED_PARAMETER)
|
||||
{
|
||||
uint32_t c = *s;
|
||||
|
||||
if (c < 0xd800 || (c >= 0xe000 && c < 0x110000))
|
||||
*puc = c;
|
||||
else
|
||||
/* invalid multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return 1;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Return the length (number of units) of the first character in S, putting
|
||||
its 'ucs4_t' representation in *PUC. Upon failure, *PUC is set to 0xfffd,
|
||||
and -1 is returned for an invalid sequence of units, -2 is returned for an
|
||||
incomplete sequence of units.
|
||||
The number of available units, N, must be > 0. */
|
||||
/* Similar to u*_mbtouc(), except that the return value gives more details
|
||||
about the failure, similar to mbrtowc(). */
|
||||
|
||||
#if GNULIB_UNISTR_U8_MBTOUCR || HAVE_LIBUNISTRING
|
||||
extern int
|
||||
u8_mbtoucr (ucs4_t *puc, const uint8_t *s, size_t n);
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U16_MBTOUCR || HAVE_LIBUNISTRING
|
||||
extern int
|
||||
u16_mbtoucr (ucs4_t *puc, const uint16_t *s, size_t n);
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U32_MBTOUCR || HAVE_LIBUNISTRING
|
||||
extern int
|
||||
u32_mbtoucr (ucs4_t *puc, const uint32_t *s, size_t n);
|
||||
#endif
|
||||
|
||||
/* Put the multibyte character represented by UC in S, returning its
|
||||
length. Return -1 upon failure, -2 if the number of available units, N,
|
||||
is too small. The latter case cannot occur if N >= 6/2/1, respectively. */
|
||||
/* Similar to wctomb(), except that s must not be NULL, and the argument n
|
||||
must be specified. */
|
||||
|
||||
#if GNULIB_UNISTR_U8_UCTOMB || HAVE_LIBUNISTRING
|
||||
/* Auxiliary function, also used by u8_chr, u8_strchr, u8_strrchr. */
|
||||
extern int
|
||||
u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n);
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u8_uctomb (uint8_t *s, ucs4_t uc, int n);
|
||||
# else
|
||||
static inline int
|
||||
u8_uctomb (uint8_t *s, ucs4_t uc, int n)
|
||||
{
|
||||
if (uc < 0x80 && n > 0)
|
||||
{
|
||||
s[0] = uc;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u8_uctomb_aux (s, uc, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U16_UCTOMB || HAVE_LIBUNISTRING
|
||||
/* Auxiliary function, also used by u16_chr, u16_strchr, u16_strrchr. */
|
||||
extern int
|
||||
u16_uctomb_aux (uint16_t *s, ucs4_t uc, int n);
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u16_uctomb (uint16_t *s, ucs4_t uc, int n);
|
||||
# else
|
||||
static inline int
|
||||
u16_uctomb (uint16_t *s, ucs4_t uc, int n)
|
||||
{
|
||||
if (uc < 0xd800 && n > 0)
|
||||
{
|
||||
s[0] = uc;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return u16_uctomb_aux (s, uc, n);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GNULIB_UNISTR_U32_UCTOMB || HAVE_LIBUNISTRING
|
||||
# if !HAVE_INLINE
|
||||
extern int
|
||||
u32_uctomb (uint32_t *s, ucs4_t uc, int n);
|
||||
# else
|
||||
static inline int
|
||||
u32_uctomb (uint32_t *s, ucs4_t uc, int n)
|
||||
{
|
||||
if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000))
|
||||
{
|
||||
if (n > 0)
|
||||
{
|
||||
*s = uc;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Copy N units from SRC to DEST. */
|
||||
/* Similar to memcpy(). */
|
||||
extern uint8_t *
|
||||
u8_cpy (uint8_t *dest, const uint8_t *src, size_t n);
|
||||
extern uint16_t *
|
||||
u16_cpy (uint16_t *dest, const uint16_t *src, size_t n);
|
||||
extern uint32_t *
|
||||
u32_cpy (uint32_t *dest, const uint32_t *src, size_t n);
|
||||
|
||||
/* Copy N units from SRC to DEST, guaranteeing correct behavior for
|
||||
overlapping memory areas. */
|
||||
/* Similar to memmove(). */
|
||||
extern uint8_t *
|
||||
u8_move (uint8_t *dest, const uint8_t *src, size_t n);
|
||||
extern uint16_t *
|
||||
u16_move (uint16_t *dest, const uint16_t *src, size_t n);
|
||||
extern uint32_t *
|
||||
u32_move (uint32_t *dest, const uint32_t *src, size_t n);
|
||||
|
||||
/* Set the first N characters of S to UC. UC should be a character that
|
||||
occupies only 1 unit. */
|
||||
/* Similar to memset(). */
|
||||
extern uint8_t *
|
||||
u8_set (uint8_t *s, ucs4_t uc, size_t n);
|
||||
extern uint16_t *
|
||||
u16_set (uint16_t *s, ucs4_t uc, size_t n);
|
||||
extern uint32_t *
|
||||
u32_set (uint32_t *s, ucs4_t uc, size_t n);
|
||||
|
||||
/* Compare S1 and S2, each of length N. */
|
||||
/* Similar to memcmp(). */
|
||||
extern int
|
||||
u8_cmp (const uint8_t *s1, const uint8_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_cmp (const uint16_t *s1, const uint16_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Compare S1 and S2. */
|
||||
/* Similar to the gnulib function memcmp2(). */
|
||||
extern int
|
||||
u8_cmp2 (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_cmp2 (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_cmp2 (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Search the string at S for UC. */
|
||||
/* Similar to memchr(). */
|
||||
extern uint8_t *
|
||||
u8_chr (const uint8_t *s, size_t n, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint16_t *
|
||||
u16_chr (const uint16_t *s, size_t n, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint32_t *
|
||||
u32_chr (const uint32_t *s, size_t n, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Count the number of Unicode characters in the N units from S. */
|
||||
/* Similar to mbsnlen(). */
|
||||
extern size_t
|
||||
u8_mbsnlen (const uint8_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u16_mbsnlen (const uint16_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u32_mbsnlen (const uint32_t *s, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Elementary string functions with memory allocation. */
|
||||
|
||||
/* Make a freshly allocated copy of S, of length N. */
|
||||
extern uint8_t *
|
||||
u8_cpy_alloc (const uint8_t *s, size_t n);
|
||||
extern uint16_t *
|
||||
u16_cpy_alloc (const uint16_t *s, size_t n);
|
||||
extern uint32_t *
|
||||
u32_cpy_alloc (const uint32_t *s, size_t n);
|
||||
|
||||
/* Elementary string functions on NUL terminated strings. */
|
||||
|
||||
/* Return the length (number of units) of the first character in S.
|
||||
Return 0 if it is the NUL character. Return -1 upon failure. */
|
||||
extern int
|
||||
u8_strmblen (const uint8_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_strmblen (const uint16_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_strmblen (const uint32_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the length (number of units) of the first character in S, putting
|
||||
its 'ucs4_t' representation in *PUC. Return 0 if it is the NUL
|
||||
character. Return -1 upon failure. */
|
||||
extern int
|
||||
u8_strmbtouc (ucs4_t *puc, const uint8_t *s);
|
||||
extern int
|
||||
u16_strmbtouc (ucs4_t *puc, const uint16_t *s);
|
||||
extern int
|
||||
u32_strmbtouc (ucs4_t *puc, const uint32_t *s);
|
||||
|
||||
/* Forward iteration step. Advances the pointer past the next character,
|
||||
or returns NULL if the end of the string has been reached. Puts the
|
||||
character's 'ucs4_t' representation in *PUC. */
|
||||
extern const uint8_t *
|
||||
u8_next (ucs4_t *puc, const uint8_t *s);
|
||||
extern const uint16_t *
|
||||
u16_next (ucs4_t *puc, const uint16_t *s);
|
||||
extern const uint32_t *
|
||||
u32_next (ucs4_t *puc, const uint32_t *s);
|
||||
|
||||
/* Backward iteration step. Advances the pointer to point to the previous
|
||||
character, or returns NULL if the beginning of the string had been reached.
|
||||
Puts the character's 'ucs4_t' representation in *PUC. */
|
||||
extern const uint8_t *
|
||||
u8_prev (ucs4_t *puc, const uint8_t *s, const uint8_t *start);
|
||||
extern const uint16_t *
|
||||
u16_prev (ucs4_t *puc, const uint16_t *s, const uint16_t *start);
|
||||
extern const uint32_t *
|
||||
u32_prev (ucs4_t *puc, const uint32_t *s, const uint32_t *start);
|
||||
|
||||
/* Return the number of units in S. */
|
||||
/* Similar to strlen(), wcslen(). */
|
||||
extern size_t
|
||||
u8_strlen (const uint8_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u16_strlen (const uint16_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u32_strlen (const uint32_t *s)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the number of units in S, but at most MAXLEN. */
|
||||
/* Similar to strnlen(), wcsnlen(). */
|
||||
extern size_t
|
||||
u8_strnlen (const uint8_t *s, size_t maxlen)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u16_strnlen (const uint16_t *s, size_t maxlen)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u32_strnlen (const uint32_t *s, size_t maxlen)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Copy SRC to DEST. */
|
||||
/* Similar to strcpy(), wcscpy(). */
|
||||
extern uint8_t *
|
||||
u8_strcpy (uint8_t *dest, const uint8_t *src);
|
||||
extern uint16_t *
|
||||
u16_strcpy (uint16_t *dest, const uint16_t *src);
|
||||
extern uint32_t *
|
||||
u32_strcpy (uint32_t *dest, const uint32_t *src);
|
||||
|
||||
/* Copy SRC to DEST, returning the address of the terminating NUL in DEST. */
|
||||
/* Similar to stpcpy(). */
|
||||
extern uint8_t *
|
||||
u8_stpcpy (uint8_t *dest, const uint8_t *src);
|
||||
extern uint16_t *
|
||||
u16_stpcpy (uint16_t *dest, const uint16_t *src);
|
||||
extern uint32_t *
|
||||
u32_stpcpy (uint32_t *dest, const uint32_t *src);
|
||||
|
||||
/* Copy no more than N units of SRC to DEST. */
|
||||
/* Similar to strncpy(), wcsncpy(). */
|
||||
extern uint8_t *
|
||||
u8_strncpy (uint8_t *dest, const uint8_t *src, size_t n);
|
||||
extern uint16_t *
|
||||
u16_strncpy (uint16_t *dest, const uint16_t *src, size_t n);
|
||||
extern uint32_t *
|
||||
u32_strncpy (uint32_t *dest, const uint32_t *src, size_t n);
|
||||
|
||||
/* Copy no more than N units of SRC to DEST. Return a pointer past the last
|
||||
non-NUL unit written into DEST. */
|
||||
/* Similar to stpncpy(). */
|
||||
extern uint8_t *
|
||||
u8_stpncpy (uint8_t *dest, const uint8_t *src, size_t n);
|
||||
extern uint16_t *
|
||||
u16_stpncpy (uint16_t *dest, const uint16_t *src, size_t n);
|
||||
extern uint32_t *
|
||||
u32_stpncpy (uint32_t *dest, const uint32_t *src, size_t n);
|
||||
|
||||
/* Append SRC onto DEST. */
|
||||
/* Similar to strcat(), wcscat(). */
|
||||
extern uint8_t *
|
||||
u8_strcat (uint8_t *dest, const uint8_t *src);
|
||||
extern uint16_t *
|
||||
u16_strcat (uint16_t *dest, const uint16_t *src);
|
||||
extern uint32_t *
|
||||
u32_strcat (uint32_t *dest, const uint32_t *src);
|
||||
|
||||
/* Append no more than N units of SRC onto DEST. */
|
||||
/* Similar to strncat(), wcsncat(). */
|
||||
extern uint8_t *
|
||||
u8_strncat (uint8_t *dest, const uint8_t *src, size_t n);
|
||||
extern uint16_t *
|
||||
u16_strncat (uint16_t *dest, const uint16_t *src, size_t n);
|
||||
extern uint32_t *
|
||||
u32_strncat (uint32_t *dest, const uint32_t *src, size_t n);
|
||||
|
||||
/* Compare S1 and S2. */
|
||||
/* Similar to strcmp(), wcscmp(). */
|
||||
#ifdef __sun
|
||||
/* Avoid a collision with the u8_strcmp() function in Solaris 11 libc. */
|
||||
extern int
|
||||
u8_strcmp_gnu (const uint8_t *s1, const uint8_t *s2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
# define u8_strcmp u8_strcmp_gnu
|
||||
#else
|
||||
extern int
|
||||
u8_strcmp (const uint8_t *s1, const uint8_t *s2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
#endif
|
||||
extern int
|
||||
u16_strcmp (const uint16_t *s1, const uint16_t *s2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_strcmp (const uint32_t *s1, const uint32_t *s2)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Compare S1 and S2 using the collation rules of the current locale.
|
||||
Return -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2.
|
||||
Upon failure, set errno and return any value. */
|
||||
/* Similar to strcoll(), wcscoll(). */
|
||||
extern int
|
||||
u8_strcoll (const uint8_t *s1, const uint8_t *s2);
|
||||
extern int
|
||||
u16_strcoll (const uint16_t *s1, const uint16_t *s2);
|
||||
extern int
|
||||
u32_strcoll (const uint32_t *s1, const uint32_t *s2);
|
||||
|
||||
/* Compare no more than N units of S1 and S2. */
|
||||
/* Similar to strncmp(), wcsncmp(). */
|
||||
extern int
|
||||
u8_strncmp (const uint8_t *s1, const uint8_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_strncmp (const uint16_t *s1, const uint16_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_strncmp (const uint32_t *s1, const uint32_t *s2, size_t n)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Duplicate S, returning an identical malloc'd string. */
|
||||
/* Similar to strdup(), wcsdup(). */
|
||||
extern uint8_t *
|
||||
u8_strdup (const uint8_t *s);
|
||||
extern uint16_t *
|
||||
u16_strdup (const uint16_t *s);
|
||||
extern uint32_t *
|
||||
u32_strdup (const uint32_t *s);
|
||||
|
||||
/* Find the first occurrence of UC in STR. */
|
||||
/* Similar to strchr(), wcschr(). */
|
||||
extern uint8_t *
|
||||
u8_strchr (const uint8_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint16_t *
|
||||
u16_strchr (const uint16_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint32_t *
|
||||
u32_strchr (const uint32_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Find the last occurrence of UC in STR. */
|
||||
/* Similar to strrchr(), wcsrchr(). */
|
||||
extern uint8_t *
|
||||
u8_strrchr (const uint8_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint16_t *
|
||||
u16_strrchr (const uint16_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint32_t *
|
||||
u32_strrchr (const uint32_t *str, ucs4_t uc)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the length of the initial segment of STR which consists entirely
|
||||
of Unicode characters not in REJECT. */
|
||||
/* Similar to strcspn(), wcscspn(). */
|
||||
extern size_t
|
||||
u8_strcspn (const uint8_t *str, const uint8_t *reject)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u16_strcspn (const uint16_t *str, const uint16_t *reject)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u32_strcspn (const uint32_t *str, const uint32_t *reject)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the length of the initial segment of STR which consists entirely
|
||||
of Unicode characters in ACCEPT. */
|
||||
/* Similar to strspn(), wcsspn(). */
|
||||
extern size_t
|
||||
u8_strspn (const uint8_t *str, const uint8_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u16_strspn (const uint16_t *str, const uint16_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern size_t
|
||||
u32_strspn (const uint32_t *str, const uint32_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Find the first occurrence in STR of any character in ACCEPT. */
|
||||
/* Similar to strpbrk(), wcspbrk(). */
|
||||
extern uint8_t *
|
||||
u8_strpbrk (const uint8_t *str, const uint8_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint16_t *
|
||||
u16_strpbrk (const uint16_t *str, const uint16_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint32_t *
|
||||
u32_strpbrk (const uint32_t *str, const uint32_t *accept)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Find the first occurrence of NEEDLE in HAYSTACK. */
|
||||
/* Similar to strstr(), wcsstr(). */
|
||||
extern uint8_t *
|
||||
u8_strstr (const uint8_t *haystack, const uint8_t *needle)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint16_t *
|
||||
u16_strstr (const uint16_t *haystack, const uint16_t *needle)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern uint32_t *
|
||||
u32_strstr (const uint32_t *haystack, const uint32_t *needle)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Test whether STR starts with PREFIX. */
|
||||
extern bool
|
||||
u8_startswith (const uint8_t *str, const uint8_t *prefix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern bool
|
||||
u16_startswith (const uint16_t *str, const uint16_t *prefix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern bool
|
||||
u32_startswith (const uint32_t *str, const uint32_t *prefix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Test whether STR ends with SUFFIX. */
|
||||
extern bool
|
||||
u8_endswith (const uint8_t *str, const uint8_t *suffix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern bool
|
||||
u16_endswith (const uint16_t *str, const uint16_t *suffix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern bool
|
||||
u32_endswith (const uint32_t *str, const uint32_t *suffix)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Divide STR into tokens separated by characters in DELIM.
|
||||
This interface is actually more similar to wcstok than to strtok. */
|
||||
/* Similar to strtok_r(), wcstok(). */
|
||||
extern uint8_t *
|
||||
u8_strtok (uint8_t *str, const uint8_t *delim, uint8_t **ptr);
|
||||
extern uint16_t *
|
||||
u16_strtok (uint16_t *str, const uint16_t *delim, uint16_t **ptr);
|
||||
extern uint32_t *
|
||||
u32_strtok (uint32_t *str, const uint32_t *delim, uint32_t **ptr);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _UNISTR_H */
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/* Check UTF-8 string.
|
||||
Copyright (C) 2002, 2006-2007, 2009-2015 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2002.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "unistr.h"
|
||||
|
||||
const uint8_t *
|
||||
u8_check (const uint8_t *s, size_t n)
|
||||
{
|
||||
const uint8_t *s_end = s + n;
|
||||
|
||||
while (s < s_end)
|
||||
{
|
||||
/* Keep in sync with unistr.h and u8-mbtouc-aux.c. */
|
||||
uint8_t c = *s;
|
||||
|
||||
if (c < 0x80)
|
||||
{
|
||||
s++;
|
||||
continue;
|
||||
}
|
||||
if (c >= 0xc2)
|
||||
{
|
||||
if (c < 0xe0)
|
||||
{
|
||||
if (s + 2 <= s_end
|
||||
&& (s[1] ^ 0x80) < 0x40)
|
||||
{
|
||||
s += 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (c < 0xf0)
|
||||
{
|
||||
if (s + 3 <= s_end
|
||||
&& (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
|
||||
&& (c >= 0xe1 || s[1] >= 0xa0)
|
||||
&& (c != 0xed || s[1] < 0xa0))
|
||||
{
|
||||
s += 3;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (c < 0xf8)
|
||||
{
|
||||
if (s + 4 <= s_end
|
||||
&& (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
|
||||
&& (s[3] ^ 0x80) < 0x40
|
||||
&& (c >= 0xf1 || s[1] >= 0x90)
|
||||
#if 1
|
||||
&& (c < 0xf4 || (c == 0xf4 && s[1] < 0x90))
|
||||
#endif
|
||||
)
|
||||
{
|
||||
s += 4;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
else if (c < 0xfc)
|
||||
{
|
||||
if (s + 5 <= s_end
|
||||
&& (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
|
||||
&& (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40
|
||||
&& (c >= 0xf9 || s[1] >= 0x88))
|
||||
{
|
||||
s += 5;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (c < 0xfe)
|
||||
{
|
||||
if (s + 6 <= s_end
|
||||
&& (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
|
||||
&& (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40
|
||||
&& (s[5] ^ 0x80) < 0x40
|
||||
&& (c >= 0xfd || s[1] >= 0x84))
|
||||
{
|
||||
s += 6;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/* invalid or incomplete multibyte character */
|
||||
return s;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
+285
@@ -0,0 +1,285 @@
|
||||
/* Look at first character in UTF-8 string, returning an error code.
|
||||
Copyright (C) 1999-2002, 2006-2007, 2009-2015 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2001.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "unistr.h"
|
||||
|
||||
int
|
||||
u8_mbtoucr (ucs4_t *puc, const uint8_t *s, size_t n)
|
||||
{
|
||||
uint8_t c = *s;
|
||||
|
||||
if (c < 0x80)
|
||||
{
|
||||
*puc = c;
|
||||
return 1;
|
||||
}
|
||||
else if (c >= 0xc2)
|
||||
{
|
||||
if (c < 0xe0)
|
||||
{
|
||||
if (n >= 2)
|
||||
{
|
||||
if ((s[1] ^ 0x80) < 0x40)
|
||||
{
|
||||
*puc = ((unsigned int) (c & 0x1f) << 6)
|
||||
| (unsigned int) (s[1] ^ 0x80);
|
||||
return 2;
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else if (c < 0xf0)
|
||||
{
|
||||
if (n >= 2)
|
||||
{
|
||||
if ((s[1] ^ 0x80) < 0x40
|
||||
&& (c >= 0xe1 || s[1] >= 0xa0)
|
||||
&& (c != 0xed || s[1] < 0xa0))
|
||||
{
|
||||
if (n >= 3)
|
||||
{
|
||||
if ((s[2] ^ 0x80) < 0x40)
|
||||
{
|
||||
*puc = ((unsigned int) (c & 0x0f) << 12)
|
||||
| ((unsigned int) (s[1] ^ 0x80) << 6)
|
||||
| (unsigned int) (s[2] ^ 0x80);
|
||||
return 3;
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else if (c < 0xf8)
|
||||
{
|
||||
if (n >= 2)
|
||||
{
|
||||
if ((s[1] ^ 0x80) < 0x40
|
||||
&& (c >= 0xf1 || s[1] >= 0x90)
|
||||
#if 1
|
||||
&& (c < 0xf4 || (c == 0xf4 && s[1] < 0x90))
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if (n >= 3)
|
||||
{
|
||||
if ((s[2] ^ 0x80) < 0x40)
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
if ((s[3] ^ 0x80) < 0x40)
|
||||
{
|
||||
*puc = ((unsigned int) (c & 0x07) << 18)
|
||||
| ((unsigned int) (s[1] ^ 0x80) << 12)
|
||||
| ((unsigned int) (s[2] ^ 0x80) << 6)
|
||||
| (unsigned int) (s[3] ^ 0x80);
|
||||
return 4;
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
else if (c < 0xfc)
|
||||
{
|
||||
if (n >= 2)
|
||||
{
|
||||
if ((s[1] ^ 0x80) < 0x40
|
||||
&& (c >= 0xf9 || s[1] >= 0x88))
|
||||
{
|
||||
if (n >= 3)
|
||||
{
|
||||
if ((s[2] ^ 0x80) < 0x40)
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
if ((s[3] ^ 0x80) < 0x40)
|
||||
{
|
||||
if (n >= 5)
|
||||
{
|
||||
if ((s[4] ^ 0x80) < 0x40)
|
||||
{
|
||||
*puc = ((unsigned int) (c & 0x03) << 24)
|
||||
| ((unsigned int) (s[1] ^ 0x80) << 18)
|
||||
| ((unsigned int) (s[2] ^ 0x80) << 12)
|
||||
| ((unsigned int) (s[3] ^ 0x80) << 6)
|
||||
| (unsigned int) (s[4] ^ 0x80);
|
||||
return 5;
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else if (c < 0xfe)
|
||||
{
|
||||
if (n >= 2)
|
||||
{
|
||||
if ((s[1] ^ 0x80) < 0x40
|
||||
&& (c >= 0xfd || s[1] >= 0x84))
|
||||
{
|
||||
if (n >= 3)
|
||||
{
|
||||
if ((s[2] ^ 0x80) < 0x40)
|
||||
{
|
||||
if (n >= 4)
|
||||
{
|
||||
if ((s[3] ^ 0x80) < 0x40)
|
||||
{
|
||||
if (n >= 5)
|
||||
{
|
||||
if ((s[4] ^ 0x80) < 0x40)
|
||||
{
|
||||
if (n >= 6)
|
||||
{
|
||||
if ((s[5] ^ 0x80) < 0x40)
|
||||
{
|
||||
*puc = ((unsigned int) (c & 0x01) << 30)
|
||||
| ((unsigned int) (s[1] ^ 0x80) << 24)
|
||||
| ((unsigned int) (s[2] ^ 0x80) << 18)
|
||||
| ((unsigned int) (s[3] ^ 0x80) << 12)
|
||||
| ((unsigned int) (s[4] ^ 0x80) << 6)
|
||||
| (unsigned int) (s[5] ^ 0x80);
|
||||
return 6;
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* incomplete multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/* invalid multibyte character */
|
||||
*puc = 0xfffd;
|
||||
return -1;
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/* Conversion UCS-4 to UTF-8.
|
||||
Copyright (C) 2002, 2006-2007, 2009-2015 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2002.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "unistr.h"
|
||||
|
||||
int
|
||||
u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n)
|
||||
{
|
||||
int count;
|
||||
|
||||
if (uc < 0x80)
|
||||
/* The case n >= 1 is already handled by the caller. */
|
||||
return -2;
|
||||
else if (uc < 0x800)
|
||||
count = 2;
|
||||
else if (uc < 0x10000)
|
||||
{
|
||||
if (uc < 0xd800 || uc >= 0xe000)
|
||||
count = 3;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
#if 0
|
||||
else if (uc < 0x200000)
|
||||
count = 4;
|
||||
else if (uc < 0x4000000)
|
||||
count = 5;
|
||||
else if (uc <= 0x7fffffff)
|
||||
count = 6;
|
||||
#else
|
||||
else if (uc < 0x110000)
|
||||
count = 4;
|
||||
#endif
|
||||
else
|
||||
return -1;
|
||||
|
||||
if (n < count)
|
||||
return -2;
|
||||
|
||||
switch (count) /* note: code falls through cases! */
|
||||
{
|
||||
#if 0
|
||||
case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000;
|
||||
case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000;
|
||||
#endif
|
||||
case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000;
|
||||
case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800;
|
||||
case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0;
|
||||
/*case 1:*/ s[0] = uc;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/* Store a character in UTF-8 string.
|
||||
Copyright (C) 2002, 2005-2006, 2009-2015 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2002.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined IN_LIBUNISTRING
|
||||
/* Tell unistr.h to declare u8_uctomb as 'extern', not 'static inline'. */
|
||||
# include "unistring-notinline.h"
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#include "unistr.h"
|
||||
|
||||
#if !HAVE_INLINE
|
||||
|
||||
int
|
||||
u8_uctomb (uint8_t *s, ucs4_t uc, int n)
|
||||
{
|
||||
if (uc < 0x80)
|
||||
{
|
||||
if (n > 0)
|
||||
{
|
||||
s[0] = uc;
|
||||
return 1;
|
||||
}
|
||||
/* else return -2, below. */
|
||||
}
|
||||
else
|
||||
{
|
||||
int count;
|
||||
|
||||
if (uc < 0x800)
|
||||
count = 2;
|
||||
else if (uc < 0x10000)
|
||||
{
|
||||
if (uc < 0xd800 || uc >= 0xe000)
|
||||
count = 3;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
#if 0
|
||||
else if (uc < 0x200000)
|
||||
count = 4;
|
||||
else if (uc < 0x4000000)
|
||||
count = 5;
|
||||
else if (uc <= 0x7fffffff)
|
||||
count = 6;
|
||||
#else
|
||||
else if (uc < 0x110000)
|
||||
count = 4;
|
||||
#endif
|
||||
else
|
||||
return -1;
|
||||
|
||||
if (n >= count)
|
||||
{
|
||||
switch (count) /* note: code falls through cases! */
|
||||
{
|
||||
#if 0
|
||||
case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000;
|
||||
case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000;
|
||||
#endif
|
||||
case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000;
|
||||
case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800;
|
||||
case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0;
|
||||
/*case 1:*/ s[0] = uc;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
#endif
|
||||
Generated
+46
@@ -0,0 +1,46 @@
|
||||
/* Elementary types and macros for the GNU UniString library.
|
||||
Copyright (C) 2002, 2005-2006, 2009-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _UNITYPES_H
|
||||
#define _UNITYPES_H
|
||||
|
||||
/* Get uint8_t, uint16_t, uint32_t. */
|
||||
#include <stdint.h>
|
||||
|
||||
/* Type representing a Unicode character. */
|
||||
typedef uint32_t ucs4_t;
|
||||
|
||||
/* Attribute of a function whose result depends only on the arguments
|
||||
(not pointers!) and which has no side effects. */
|
||||
#ifndef _UC_ATTRIBUTE_CONST
|
||||
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
|
||||
# define _UC_ATTRIBUTE_CONST __attribute__ ((__const__))
|
||||
# else
|
||||
# define _UC_ATTRIBUTE_CONST
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Attribute of a function whose result depends only on the arguments
|
||||
(possibly pointers) and global memory, and which has no side effects. */
|
||||
#ifndef _UC_ATTRIBUTE_PURE
|
||||
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
|
||||
# define _UC_ATTRIBUTE_PURE __attribute__ ((__pure__))
|
||||
# else
|
||||
# define _UC_ATTRIBUTE_PURE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _UNITYPES_H */
|
||||
Generated
+46
@@ -0,0 +1,46 @@
|
||||
/* Elementary types and macros for the GNU UniString library.
|
||||
Copyright (C) 2002, 2005-2006, 2009-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _UNITYPES_H
|
||||
#define _UNITYPES_H
|
||||
|
||||
/* Get uint8_t, uint16_t, uint32_t. */
|
||||
#include <stdint.h>
|
||||
|
||||
/* Type representing a Unicode character. */
|
||||
typedef uint32_t ucs4_t;
|
||||
|
||||
/* Attribute of a function whose result depends only on the arguments
|
||||
(not pointers!) and which has no side effects. */
|
||||
#ifndef _UC_ATTRIBUTE_CONST
|
||||
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
|
||||
# define _UC_ATTRIBUTE_CONST __attribute__ ((__const__))
|
||||
# else
|
||||
# define _UC_ATTRIBUTE_CONST
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Attribute of a function whose result depends only on the arguments
|
||||
(possibly pointers) and global memory, and which has no side effects. */
|
||||
#ifndef _UC_ATTRIBUTE_PURE
|
||||
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
|
||||
# define _UC_ATTRIBUTE_PURE __attribute__ ((__pure__))
|
||||
# else
|
||||
# define _UC_ATTRIBUTE_PURE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _UNITYPES_H */
|
||||
Reference in new issue
Block a user