2017-08-12 14:56:14 -04:00
|
|
|
/*
|
|
|
|
__ __ _
|
|
|
|
___\ \/ /_ __ __ _| |_
|
|
|
|
/ _ \\ /| '_ \ / _` | __|
|
|
|
|
| __// \| |_) | (_| | |_
|
|
|
|
\___/_/\_\ .__/ \__,_|\__|
|
|
|
|
|_| XML parser
|
|
|
|
|
|
|
|
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
|
|
|
|
Copyright (c) 2000-2017 Expat development team
|
|
|
|
Licensed under the MIT license:
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
a copy of this software and associated documentation files (the
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
persons to whom the Software is furnished to do so, subject to the
|
|
|
|
following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2000-04-21 00:20:31 -04:00
|
|
|
*/
|
1998-06-01 08:12:51 -04:00
|
|
|
|
|
|
|
#include "codepage.h"
|
2016-05-07 10:45:58 -04:00
|
|
|
#include "internal.h" /* for UNUSED_P only */
|
1998-06-01 08:12:51 -04:00
|
|
|
|
2017-05-25 09:06:28 -04:00
|
|
|
#if defined(_WIN32)
|
1998-11-24 04:31:04 -05:00
|
|
|
#define STRICT 1
|
|
|
|
#define WIN32_LEAN_AND_MEAN 1
|
|
|
|
|
1998-06-01 08:12:51 -04:00
|
|
|
#include <windows.h>
|
|
|
|
|
2002-07-01 11:13:02 -04:00
|
|
|
int
|
|
|
|
codepageMap(int cp, int *map)
|
1998-06-01 08:12:51 -04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CPINFO info;
|
1998-06-02 04:57:14 -04:00
|
|
|
if (!GetCPInfo(cp, &info) || info.MaxCharSize > 2)
|
1998-06-01 08:12:51 -04:00
|
|
|
return 0;
|
1998-06-02 04:57:14 -04:00
|
|
|
for (i = 0; i < 256; i++)
|
1998-06-03 03:52:49 -04:00
|
|
|
map[i] = -1;
|
1998-06-02 04:57:14 -04:00
|
|
|
if (info.MaxCharSize > 1) {
|
2005-04-19 14:25:08 -04:00
|
|
|
for (i = 0; i < MAX_LEADBYTES; i+=2) {
|
1998-06-02 04:57:14 -04:00
|
|
|
int j, lim;
|
|
|
|
if (info.LeadByte[i] == 0 && info.LeadByte[i + 1] == 0)
|
|
|
|
break;
|
|
|
|
lim = info.LeadByte[i + 1];
|
2005-04-19 14:25:08 -04:00
|
|
|
for (j = info.LeadByte[i]; j <= lim; j++)
|
2002-07-01 11:13:02 -04:00
|
|
|
map[j] = -2;
|
1998-06-02 04:57:14 -04:00
|
|
|
}
|
|
|
|
}
|
1998-06-01 08:12:51 -04:00
|
|
|
for (i = 0; i < 256; i++) {
|
1998-06-03 03:52:49 -04:00
|
|
|
if (map[i] == -1) {
|
2002-05-15 11:57:22 -04:00
|
|
|
char c = (char)i;
|
1998-06-03 03:52:49 -04:00
|
|
|
unsigned short n;
|
1998-06-02 04:57:14 -04:00
|
|
|
if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
|
2002-07-01 11:13:02 -04:00
|
|
|
&c, 1, &n, 1) == 1)
|
1998-06-03 03:52:49 -04:00
|
|
|
map[i] = n;
|
1998-06-02 04:57:14 -04:00
|
|
|
}
|
1998-06-01 08:12:51 -04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-07-01 11:13:02 -04:00
|
|
|
int
|
|
|
|
codepageConvert(int cp, const char *p)
|
1998-06-02 04:57:14 -04:00
|
|
|
{
|
|
|
|
unsigned short c;
|
|
|
|
if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
|
2002-07-01 11:13:02 -04:00
|
|
|
p, 2, &c, 1) == 1)
|
1998-06-02 04:57:14 -04:00
|
|
|
return c;
|
1998-06-03 03:52:49 -04:00
|
|
|
return -1;
|
1998-06-02 04:57:14 -04:00
|
|
|
}
|
|
|
|
|
2017-05-25 09:06:28 -04:00
|
|
|
#else /* not _WIN32 */
|
1998-06-01 08:12:51 -04:00
|
|
|
|
2002-07-01 11:13:02 -04:00
|
|
|
int
|
2016-05-07 10:45:58 -04:00
|
|
|
codepageMap(int UNUSED_P(cp), int *UNUSED_P(map))
|
1998-06-02 04:57:14 -04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-01 11:13:02 -04:00
|
|
|
int
|
2016-05-07 10:45:58 -04:00
|
|
|
codepageConvert(int UNUSED_P(cp), const char *UNUSED_P(p))
|
1998-06-01 08:12:51 -04:00
|
|
|
{
|
1998-06-03 03:52:49 -04:00
|
|
|
return -1;
|
1998-06-01 08:12:51 -04:00
|
|
|
}
|
|
|
|
|
2017-05-25 09:06:28 -04:00
|
|
|
#endif /* not _WIN32 */
|