ReactOS 0.4.16-dev-2279-gc890759
xsltlocale.h File Reference
#include <libxml/xmlstring.h>
#include "xsltexports.h"
Include dependency graph for xsltlocale.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef voidxsltLocale
 
typedef xmlChar xsltLocaleChar
 

Functions

XSLTPUBFUN void *XSLTCALL xsltNewLocale (const xmlChar *langName, int lowerFirst)
 
XSLTPUBFUN void XSLTCALL xsltFreeLocale (void *locale)
 
XSLTPUBFUN xmlChar *XSLTCALL xsltStrxfrm (void *locale, const xmlChar *string)
 
XSLTPUBFUN void XSLTCALL xsltFreeLocales (void)
 
XSLTPUBFUN int XSLTCALL xsltLocaleStrcmp (void *locale, const xmlChar *str1, const xmlChar *str2)
 

Typedef Documentation

◆ xsltLocale

typedef void* xsltLocale

Definition at line 33 of file xsltlocale.h.

◆ xsltLocaleChar

Definition at line 34 of file xsltlocale.h.

Function Documentation

◆ xsltFreeLocale()

XSLTPUBFUN void XSLTCALL xsltFreeLocale ( void locale)

xsltFreeLocale: @locale: the locale to free

Frees a locale created with xsltNewLocale

Definition at line 372 of file xsltlocale.c.

372 {
373#ifdef XSLT_LOCALE_POSIX
374 if (locale != NULL)
375 freelocale(locale);
376#else
377 (void) locale;
378#endif
379}
Definition: _locale.h:75
#define NULL
Definition: types.h:112

Referenced by xsltNewTransformContext().

◆ xsltFreeLocales()

XSLTPUBFUN void XSLTCALL xsltFreeLocales ( void  )

xsltFreeLocales:

Cleanup function for the locale support on shutdown

Definition at line 93 of file xsltlocale.c.

93 {
94#ifdef XSLT_LOCALE_WINAPI
95 xmlRMutexLock(xsltLocaleMutex);
96 xmlFree(xsltLocaleList);
97 xsltLocaleList = NULL;
98 xmlRMutexUnlock(xsltLocaleMutex);
99#endif
100}
XMLPUBFUN void xmlRMutexLock(xmlRMutexPtr tok)
Definition: threads.c:297
XMLPUBFUN void xmlRMutexUnlock(xmlRMutexPtr tok)
Definition: threads.c:333
xmlFreeFunc xmlFree
Definition: globals.c:184

Referenced by xsltCleanupGlobals().

◆ xsltLocaleStrcmp()

XSLTPUBFUN int XSLTCALL xsltLocaleStrcmp ( void locale,
const xmlChar str1,
const xmlChar str2 
)

xsltLocaleStrcmp: @locale: unused @str1: a string transformed with xsltStrxfrm @str2: a string transformed with xsltStrxfrm

DEPRECATED: Same as xmlStrcmp.

Compares two strings transformed with xsltStrxfrm.

Returns a value < 0 if str1 sorts before str2, a value > 0 if str1 sorts after str2, 0 if str1 and str2 are equal wrt sorting

Definition at line 482 of file xsltlocale.c.

482 {
483 (void)locale;
484 return(xmlStrcmp(str1, str2));
485}
XML_HIDDEN void xmlParserErrors const char const xmlChar const xmlChar * str2
Definition: parser.h:35
XML_HIDDEN void xmlParserErrors const char const xmlChar * str1
Definition: parser.h:35
XMLPUBFUN int xmlStrcmp(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:135

◆ xsltNewLocale()

XSLTPUBFUN void *XSLTCALL xsltNewLocale ( const xmlChar languageTag,
int lowerFirst  ATTRIBUTE_UNUSED 
)

xsltNewLocale: @languageTag: RFC 3066 language tag

Creates a new locale of an opaque system dependent type based on the language tag.

Returns the locale or NULL on error or if no matching locale was found

Definition at line 112 of file xsltlocale.c.

112 {
113#ifdef XSLT_LOCALE_POSIX
114 locale_t locale;
115 char localeName[XSLTMAX_LANGTAGLEN+7]; /* 7 chars for ".UTF-8\0" */
116 const xmlChar *p = languageTag;
117 const char *region = NULL;
118 char *q = localeName;
119 int i, llen;
120
121 /* Convert something like "pt-br" to "pt_BR.UTF-8" */
122
123 if (languageTag == NULL)
124 return(NULL);
125
126 for (i=0; i<XSLTMAX_ISO639LANGLEN && ISALPHA(*p); ++i)
127 *q++ = TOLOWER(*p++);
128
129 if (i == 0)
130 return(NULL);
131
132 llen = i;
133
134 if (*p) {
135 if (*p++ != '-')
136 return(NULL);
137 *q++ = '_';
138
139 for (i=0; i<XSLTMAX_ISO3166CNTRYLEN && ISALPHA(*p); ++i)
140 *q++ = TOUPPER(*p++);
141
142 if (i == 0 || *p)
143 return(NULL);
144
145 memcpy(q, ".UTF-8", 7);
146 locale = newlocale(LC_ALL_MASK, localeName, NULL);
147 if (locale != NULL)
148 return(locale);
149
150 /* Continue without using country code */
151
152 q = localeName + llen;
153 }
154
155 /* Try locale without territory, e.g. for Esperanto (eo) */
156
157 memcpy(q, ".UTF-8", 7);
158 locale = newlocale(LC_ALL_MASK, localeName, NULL);
159 if (locale != NULL)
160 return(locale);
161
162 /* Try to find most common country for language */
163
164 if (llen != 2)
165 return(NULL);
166
167 region = (char *)xsltDefaultRegion((xmlChar *)localeName);
168 if (region == NULL)
169 return(NULL);
170
171 q = localeName + llen;
172 *q++ = '_';
173 *q++ = region[0];
174 *q++ = region[1];
175 memcpy(q, ".UTF-8", 7);
176 locale = newlocale(LC_ALL_MASK, localeName, NULL);
177
178 return(locale);
179#endif
180
181#ifdef XSLT_LOCALE_WINAPI
182{
183 void *locale = NULL;
184 xmlChar localeName[XSLTMAX_LANGTAGLEN+1];
185 xmlChar *q = localeName;
186 const xmlChar *p = languageTag;
187 int i, llen;
188 const xmlChar *region = NULL;
189
190 if (languageTag == NULL) goto end;
191
192 xsltEnumSupportedLocales();
193
194 for (i=0; i<XSLTMAX_ISO639LANGLEN && ISALPHA(*p); ++i)
195 *q++ = TOLOWER(*p++);
196 if (i == 0) goto end;
197
198 llen = i;
199 *q++ = '-';
200 if (*p) { /*if country tag is given*/
201 if (*p++ != '-') goto end;
202
203 for (i=0; i<XSLTMAX_ISO3166CNTRYLEN && ISALPHA(*p); ++i)
204 *q++ = TOUPPER(*p++);
205 if (i == 0 || *p) goto end;
206
207 *q = '\0';
208 locale = xslt_locale_WINAPI(localeName);
209 if (locale != (xsltLocale)0) goto end;
210 }
211 /* Try to find most common country for language */
212 region = xsltDefaultRegion(localeName);
213 if (region == NULL) goto end;
214
215 strcpy((char *) localeName + llen + 1, (char *) region);
216 locale = xslt_locale_WINAPI(localeName);
217end:
218 return(locale);
219}
220#endif
221
222#ifdef XSLT_LOCALE_NONE
223 return(NULL);
224#endif
225}
GLuint GLuint end
Definition: gl.h:1545
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
strcpy
Definition: string.h:131
unsigned char xmlChar
Definition: xmlstring.h:28
static const xmlChar * xsltDefaultRegion(const xmlChar *localeName)
Definition: xsltlocale.c:228
#define XSLTMAX_LANGTAGLEN
Definition: xsltlocale.c:55
#define XSLTMAX_ISO3166CNTRYLEN
Definition: xsltlocale.c:53
#define XSLTMAX_ISO639LANGLEN
Definition: xsltlocale.c:52
#define TOUPPER(c)
Definition: xsltlocale.c:47
#define TOLOWER(c)
Definition: xsltlocale.c:48
#define ISALPHA(c)
Definition: xsltlocale.c:49

Referenced by xsltNewTransformContext().

◆ xsltStrxfrm()

XSLTPUBFUN xmlChar *XSLTCALL xsltStrxfrm ( void vlocale,
const xmlChar string 
)

xsltStrxfrm: @locale: locale created with xsltNewLocale @string: UTF-8 string to transform

Transforms a string according to locale. The transformed string must be freed with xmlFree.

Returns the transformed string or NULL on error

Definition at line 392 of file xsltlocale.c.

393{
394#ifdef XSLT_LOCALE_NONE
395 return(NULL);
396#else
397 xmlChar *xstr;
398
399#ifdef XSLT_LOCALE_POSIX
400 size_t xstrlen, r;
401
402 xstrlen = strxfrm_l(NULL, (const char *)string, 0, vlocale) + 1;
403 xstr = (xmlChar *) xmlMalloc(xstrlen);
404 if (xstr == NULL) {
406 "xsltStrxfrm : out of memory error\n");
407 return(NULL);
408 }
409
410 r = strxfrm_l((char *)xstr, (const char *)string, xstrlen, vlocale);
411
412 if (r >= xstrlen) {
413 xsltTransformError(NULL, NULL, NULL, "xsltStrxfrm : strxfrm failed\n");
414 xmlFree(xstr);
415 return(NULL);
416 }
417#endif
418
419#ifdef XSLT_LOCALE_WINAPI
420 int wstrlen, xstrlen, r;
421 wchar_t *wstr;
422 LCID *lcid = vlocale;
423
424 wstrlen = MultiByteToWideChar(CP_UTF8, 0, (char *) string, -1, NULL, 0);
425 if (wstrlen == 0) {
426 xsltTransformError(NULL, NULL, NULL, "xsltStrxfrm : MultiByteToWideChar check failed\n");
427 return(NULL);
428 }
429 wstr = (wchar_t *) xmlMalloc(wstrlen * sizeof(wchar_t));
430 if (wstr == NULL) {
431 xsltTransformError(NULL, NULL, NULL, "xsltStrxfrm : out of memory\n");
432 return(NULL);
433 }
434 r = MultiByteToWideChar(CP_UTF8, 0, (char *) string, -1, wstr, wstrlen);
435 if (r == 0) {
436 xsltTransformError(NULL, NULL, NULL, "xsltStrxfrm : MultiByteToWideChar failed\n");
437 xmlFree(wstr);
438 return(NULL);
439 }
440 /* This returns the size in bytes. */
441 xstrlen = LCMapStringW(*lcid, LCMAP_SORTKEY, wstr, wstrlen, NULL, 0);
442 if (xstrlen == 0) {
443 xsltTransformError(NULL, NULL, NULL, "xsltStrxfrm : LCMapStringW failed\n");
444 xmlFree(wstr);
445 return(NULL);
446 }
447 xstr = (xmlChar*) xmlMalloc(xstrlen);
448 if (xstr == NULL) {
449 xsltTransformError(NULL, NULL, NULL, "xsltStrxfrm : out of memory\n");
450 xmlFree(wstr);
451 return(NULL);
452 }
453 r = LCMapStringW(*lcid, LCMAP_SORTKEY, wstr, wstrlen, (wchar_t *) xstr,
454 xstrlen);
455 xmlFree(wstr);
456 if (r == 0) {
457 xsltTransformError(NULL, NULL, NULL, "xsltStrxfrm : LCMapStringW failed\n");
458 xmlFree(xstr);
459 return(NULL);
460 }
461#endif /* XSLT_LOCALE_WINAPI */
462
463 return(xstr);
464#endif /* XSLT_LOCALE_NONE */
465}
#define MultiByteToWideChar
Definition: compat.h:110
INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen)
Definition: locale.c:3808
LCID lcid
Definition: locale.c:5656
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
DWORD LCID
Definition: nls.h:13
#define CP_UTF8
Definition: nls.h:20
xmlMallocFunc xmlMalloc
Definition: globals.c:193
#define LCMAP_SORTKEY
Definition: winnls.h:199
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:762

Referenced by xsltNewTransformContext().