2 * Copyright (c) 2008, KJK::Hyperion
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * - Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * - Neither the name of the ReactOS Foundation nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
36 #include <unicode/uchar.h>
37 #include <unicode/uclean.h>
38 #include <unicode/umachine.h>
39 #include <unicode/uscript.h>
41 #define WIN32_LEAN_AND_MEAN
54 #include "data/idldata.cpp"
58 DownlevelGetLocaleScripts
65 void * lpFoundLocale
= bsearch
69 //~ ARRAYSIZE(IDNDL_Locales),
70 sizeof(IDNDL_Locales
) / sizeof(IDNDL_Locales
[0]),
71 sizeof(IDNDL_Locales
[0]),
72 (int (*)(const void *, const void *))_stricmp
75 if(lpFoundLocale
== NULL
)
77 SetLastError(ERROR_INVALID_PARAMETER
);
81 const IDNDL_ScriptSet
* pScriptSet
= IDNDL_ScriptSets
[static_cast<const wchar_t **>(lpFoundLocale
) - IDNDL_Locales
];
83 if(pScriptSet
->length
> cchScripts
)
84 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
86 memcpy(lpScripts
, pScriptSet
->scripts
, pScriptSet
->length
* sizeof(WCHAR
));
88 return pScriptSet
->length
;
91 static int IDNDL_CompareCharRange(const void * x
, const void * y
)
93 const IDNDL_CharRangeScript
* pRangeX
= static_cast<const IDNDL_CharRangeScript
*>(x
);
94 const IDNDL_CharRangeScript
* pRangeY
= static_cast<const IDNDL_CharRangeScript
*>(y
);
96 assert(pRangeX
->lbound
<= pRangeX
->ubound
);
97 assert(pRangeY
->lbound
<= pRangeY
->ubound
);
101 cmp
= pRangeX
->ubound
- pRangeY
->lbound
;
106 cmp
= pRangeX
->lbound
- pRangeY
->ubound
;
111 assert((pRangeX
->lbound
>= pRangeY
->lbound
&& pRangeX
->ubound
<= pRangeY
->ubound
) || (pRangeY
->lbound
>= pRangeX
->lbound
&& pRangeY
->ubound
<= pRangeX
->ubound
));
115 extern "C" bool SCRIPTS_GetCharScriptCode(UChar32 c
, int32_t * code
)
117 assert(c
>= UCHAR_MIN_VALUE
&& c
<= UCHAR_MAX_VALUE
);
119 IDNDL_CharRangeScript character
;
120 character
.lbound
= c
;
121 character
.ubound
= c
;
123 void * pRange
= bsearch
126 IDNDL_CharRangeScripts
,
127 //~ ARRAYSIZE(IDNDL_CharRangeScripts),
128 sizeof(IDNDL_CharRangeScripts
) / sizeof(IDNDL_CharRangeScripts
[0]),
129 sizeof(IDNDL_CharRangeScripts
[0]),
130 &IDNDL_CompareCharRange
134 *code
= USCRIPT_UNKNOWN
;
136 *code
= static_cast<IDNDL_CharRangeScript
*>(pRange
)->code
;
141 extern "C" bool SCRIPTS_GetScriptCode(const SCRIPTS_Script
* pScript
, int32_t * code
)
143 void * ppScript
= bsearch
147 //~ ARRAYSIZE(IDNDL_ScriptNames),
148 sizeof(IDNDL_ScriptNames
) / sizeof(IDNDL_ScriptNames
[0]),
149 sizeof(IDNDL_ScriptNames
[0]),
150 (int (*)(const void *, const void *))_stricmp
159 SetLastError(ERROR_INVALID_PARAMETER
);
163 *code
= static_cast<int32_t>(static_cast<const wchar_t **>(ppScript
) - IDNDL_ScriptNames
);
167 extern "C" void SCRIPTS_GetScriptName(int32_t code
, SCRIPTS_Script
* pScript
)
169 //~ assert(code >= 0 && static_cast<uint32_t>(code) < ARRAYSIZE(IDNDL_ScriptNames));
170 assert(code
>= 0 && static_cast<uint32_t>(code
) < (sizeof(IDNDL_ScriptNames
) / sizeof(IDNDL_ScriptNames
[0])));
171 memcpy(pScript
->ScriptName
, IDNDL_ScriptNames
[code
], sizeof(pScript
->ScriptName
));