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
52 #include "data/idldata.cpp"
56 DownlevelGetLocaleScripts
63 void * lpFoundLocale
= bsearch
67 //~ ARRAYSIZE(IDNDL_Locales),
68 sizeof(IDNDL_Locales
) / sizeof(IDNDL_Locales
[0]),
69 sizeof(IDNDL_Locales
[0]),
70 (int (*)(const void *, const void *))_stricmp
73 if(lpFoundLocale
== NULL
)
75 SetLastError(ERROR_INVALID_PARAMETER
);
79 const IDNDL_ScriptSet
* pScriptSet
= IDNDL_ScriptSets
[static_cast<const wchar_t **>(lpFoundLocale
) - IDNDL_Locales
];
81 if(pScriptSet
->length
> cchScripts
)
82 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
84 memcpy(lpScripts
, pScriptSet
->scripts
, pScriptSet
->length
* sizeof(WCHAR
));
86 return pScriptSet
->length
;
89 static int IDNDL_CompareCharRange(const void * x
, const void * y
)
91 const IDNDL_CharRangeScript
* pRangeX
= static_cast<const IDNDL_CharRangeScript
*>(x
);
92 const IDNDL_CharRangeScript
* pRangeY
= static_cast<const IDNDL_CharRangeScript
*>(y
);
94 assert(pRangeX
->lbound
<= pRangeX
->ubound
);
95 assert(pRangeY
->lbound
<= pRangeY
->ubound
);
99 cmp
= pRangeX
->ubound
- pRangeY
->lbound
;
104 cmp
= pRangeX
->lbound
- pRangeY
->ubound
;
109 assert((pRangeX
->lbound
>= pRangeY
->lbound
&& pRangeX
->ubound
<= pRangeY
->ubound
) || (pRangeY
->lbound
>= pRangeX
->lbound
&& pRangeY
->ubound
<= pRangeX
->ubound
));
113 extern "C" bool SCRIPTS_GetCharScriptCode(UChar32 c
, int32_t * code
)
115 assert(c
>= UCHAR_MIN_VALUE
&& c
<= UCHAR_MAX_VALUE
);
117 IDNDL_CharRangeScript character
;
118 character
.lbound
= c
;
119 character
.ubound
= c
;
121 void * pRange
= bsearch
124 IDNDL_CharRangeScripts
,
125 //~ ARRAYSIZE(IDNDL_CharRangeScripts),
126 sizeof(IDNDL_CharRangeScripts
) / sizeof(IDNDL_CharRangeScripts
[0]),
127 sizeof(IDNDL_CharRangeScripts
[0]),
128 &IDNDL_CompareCharRange
132 *code
= USCRIPT_UNKNOWN
;
134 *code
= static_cast<IDNDL_CharRangeScript
*>(pRange
)->code
;
139 extern "C" bool SCRIPTS_GetScriptCode(const SCRIPTS_Script
* pScript
, int32_t * code
)
141 void * ppScript
= bsearch
145 //~ ARRAYSIZE(IDNDL_ScriptNames),
146 sizeof(IDNDL_ScriptNames
) / sizeof(IDNDL_ScriptNames
[0]),
147 sizeof(IDNDL_ScriptNames
[0]),
148 (int (*)(const void *, const void *))_stricmp
157 SetLastError(ERROR_INVALID_PARAMETER
);
161 *code
= static_cast<int32_t>(static_cast<const wchar_t **>(ppScript
) - IDNDL_ScriptNames
);
165 extern "C" void SCRIPTS_GetScriptName(int32_t code
, SCRIPTS_Script
* pScript
)
167 //~ assert(code >= 0 && static_cast<uint32_t>(code) < ARRAYSIZE(IDNDL_ScriptNames));
168 assert(code
>= 0 && static_cast<uint32_t>(code
) < (sizeof(IDNDL_ScriptNames
) / sizeof(IDNDL_ScriptNames
[0])));
169 memcpy(pScript
->ScriptName
, IDNDL_ScriptNames
[code
], sizeof(pScript
->ScriptName
));