source: UsbWattMeter/trunk/curl-7.47.1/lib/idn_win32.c@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 3.5 KB
Line 
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ***************************************************************************/
22
23 /*
24 * IDN conversions using Windows kernel32 and normaliz libraries.
25 */
26
27#include "curl_setup.h"
28
29#ifdef USE_WIN32_IDN
30
31#include "curl_multibyte.h"
32
33#include "curl_memory.h"
34/* The last #include file should be: */
35#include "memdebug.h"
36
37#ifdef WANT_IDN_PROTOTYPES
38# if defined(_SAL_VERSION)
39WINNORMALIZEAPI int WINAPI
40IdnToAscii(_In_ DWORD dwFlags,
41 _In_reads_(cchUnicodeChar) LPCWSTR lpUnicodeCharStr,
42 _In_ int cchUnicodeChar,
43 _Out_writes_opt_(cchASCIIChar) LPWSTR lpASCIICharStr,
44 _In_ int cchASCIIChar);
45WINNORMALIZEAPI int WINAPI
46IdnToUnicode(_In_ DWORD dwFlags,
47 _In_reads_(cchASCIIChar) LPCWSTR lpASCIICharStr,
48 _In_ int cchASCIIChar,
49 _Out_writes_opt_(cchUnicodeChar) LPWSTR lpUnicodeCharStr,
50 _In_ int cchUnicodeChar);
51# else
52WINBASEAPI int WINAPI IdnToAscii(DWORD dwFlags,
53 const WCHAR *lpUnicodeCharStr,
54 int cchUnicodeChar,
55 WCHAR *lpASCIICharStr,
56 int cchASCIIChar);
57WINBASEAPI int WINAPI IdnToUnicode(DWORD dwFlags,
58 const WCHAR *lpASCIICharStr,
59 int cchASCIIChar,
60 WCHAR *lpUnicodeCharStr,
61 int cchUnicodeChar);
62# endif
63#endif
64
65#define IDN_MAX_LENGTH 255
66
67int curl_win32_idn_to_ascii(const char *in, char **out);
68int curl_win32_ascii_to_idn(const char *in, char **out);
69
70int curl_win32_idn_to_ascii(const char *in, char **out)
71{
72 int ret = 0;
73 wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
74 if(in_w) {
75 wchar_t punycode[IDN_MAX_LENGTH];
76 int chars = IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH);
77 free(in_w);
78 if(chars) {
79 *out = Curl_convert_wchar_to_UTF8(punycode);
80 if(*out)
81 ret = 1; /* success */
82 }
83 }
84 return ret;
85}
86
87int curl_win32_ascii_to_idn(const char *in, char **out)
88{
89 int ret = 0;
90 wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
91 if(in_w) {
92 wchar_t unicode[IDN_MAX_LENGTH];
93 int chars = IdnToUnicode(0, in_w, wcslen(in_w)+1, unicode, IDN_MAX_LENGTH);
94 free(in_w);
95 if(chars) {
96 *out = Curl_convert_wchar_to_UTF8(unicode);
97 if(*out)
98 ret = 1; /* success */
99 }
100 }
101 return ret;
102}
103
104#endif /* USE_WIN32_IDN */
Note: See TracBrowser for help on using the repository browser.