w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

udatpg.cpp
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 * Copyright (C) 2009-2015, International Business Machines
7 * Corporation and others. All Rights Reserved.
8 *
9 *******************************************************************************
10 * file name: udatpg.cpp
11 * encoding: UTF-8
12 * tab size: 8 (not used)
13 * indentation:4
14 *
15 * created on: 2007jul30
16 * created by: Markus W. Scherer
17 */
18 
19 #include "unicode/utypes.h"
20 
21 #if !UCONFIG_NO_FORMATTING
22 
23 #include "unicode/udatpg.h"
24 #include "unicode/uenum.h"
25 #include "unicode/strenum.h"
26 #include "unicode/dtptngen.h"
27 #include "ustrenum.h"
28 
30 
32 udatpg_open(const char *locale, UErrorCode *pErrorCode) {
33  if(locale==NULL) {
34  return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(*pErrorCode);
35  } else {
36  return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(Locale(locale), *pErrorCode);
37  }
38 }
39 
42  return (UDateTimePatternGenerator *)DateTimePatternGenerator::createEmptyInstance(*pErrorCode);
43 }
44 
45 U_CAPI void U_EXPORT2
47  delete (DateTimePatternGenerator *)dtpg;
48 }
49 
52  if(U_FAILURE(*pErrorCode)) {
53  return NULL;
54  }
55  return (UDateTimePatternGenerator *)(((const DateTimePatternGenerator *)dtpg)->clone());
56 }
57 
60  const UChar *skeleton, int32_t length,
61  UChar *bestPattern, int32_t capacity,
62  UErrorCode *pErrorCode) {
63  return udatpg_getBestPatternWithOptions(dtpg, skeleton, length,
65  bestPattern, capacity, pErrorCode);
66 }
67 
70  const UChar *skeleton, int32_t length,
72  UChar *bestPattern, int32_t capacity,
73  UErrorCode *pErrorCode) {
74  if(U_FAILURE(*pErrorCode)) {
75  return 0;
76  }
77  if(skeleton==NULL && length!=0) {
78  *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
79  return 0;
80  }
81  UnicodeString skeletonString((UBool)(length<0), skeleton, length);
82  UnicodeString result=((DateTimePatternGenerator *)dtpg)->getBestPattern(skeletonString, options, *pErrorCode);
83  return result.extract(bestPattern, capacity, *pErrorCode);
84 }
85 
88  const UChar *pattern, int32_t length,
89  UChar *skeleton, int32_t capacity,
90  UErrorCode *pErrorCode) {
91  if(U_FAILURE(*pErrorCode)) {
92  return 0;
93  }
94  if(pattern==NULL && length!=0) {
95  *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
96  return 0;
97  }
98  UnicodeString patternString((UBool)(length<0), pattern, length);
99  UnicodeString result=DateTimePatternGenerator::staticGetSkeleton(
100  patternString, *pErrorCode);
101  return result.extract(skeleton, capacity, *pErrorCode);
102 }
103 
106  const UChar *pattern, int32_t length,
107  UChar *skeleton, int32_t capacity,
108  UErrorCode *pErrorCode) {
109  if(U_FAILURE(*pErrorCode)) {
110  return 0;
111  }
112  if(pattern==NULL && length!=0) {
113  *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
114  return 0;
115  }
116  UnicodeString patternString((UBool)(length<0), pattern, length);
117  UnicodeString result=DateTimePatternGenerator::staticGetBaseSkeleton(
118  patternString, *pErrorCode);
119  return result.extract(skeleton, capacity, *pErrorCode);
120 }
121 
125  UBool override,
126  UChar *conflictingPattern, int32_t capacity, int32_t *pLength,
127  UErrorCode *pErrorCode) {
128  if(U_FAILURE(*pErrorCode)) {
129  return UDATPG_NO_CONFLICT;
130  }
131  if(pattern==NULL && patternLength!=0) {
132  *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
133  return UDATPG_NO_CONFLICT;
134  }
135  UnicodeString patternString((UBool)(patternLength<0), pattern, patternLength);
136  UnicodeString conflictingPatternString;
137  UDateTimePatternConflict result=((DateTimePatternGenerator *)dtpg)->
138  addPattern(patternString, override, conflictingPatternString, *pErrorCode);
139  int32_t length=conflictingPatternString.extract(conflictingPattern, capacity, *pErrorCode);
140  if(pLength!=NULL) {
141  *pLength=length;
142  }
143  return result;
144 }
145 
146 U_CAPI void U_EXPORT2
149  const UChar *value, int32_t length) {
150  UnicodeString valueString((UBool)(length<0), value, length);
151  ((DateTimePatternGenerator *)dtpg)->setAppendItemFormat(field, valueString);
152 }
153 
154 U_CAPI const UChar * U_EXPORT2
157  int32_t *pLength) {
158  const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getAppendItemFormat(field);
159  if(pLength!=NULL) {
160  *pLength=result.length();
161  }
162  return result.getBuffer();
163 }
164 
165 U_CAPI void U_EXPORT2
168  const UChar *value, int32_t length) {
169  UnicodeString valueString((UBool)(length<0), value, length);
170  ((DateTimePatternGenerator *)dtpg)->setAppendItemName(field, valueString);
171 }
172 
173 U_CAPI const UChar * U_EXPORT2
176  int32_t *pLength) {
177  const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getAppendItemName(field);
178  if(pLength!=NULL) {
179  *pLength=result.length();
180  }
181  return result.getBuffer();
182 }
183 
188  UChar *fieldName, int32_t capacity,
189  UErrorCode *pErrorCode) {
190  if (U_FAILURE(*pErrorCode))
191  return -1;
192  if (fieldName == NULL ? capacity != 0 : capacity < 0) {
193  *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
194  return -1;
195  }
196  UnicodeString result = ((const DateTimePatternGenerator *)dtpg)->getFieldDisplayName(field,width);
197  if (fieldName == NULL) {
198  return result.length();
199  }
200  return result.extract(fieldName, capacity, *pErrorCode);
201 }
202 
203 U_CAPI void U_EXPORT2
205  const UChar *dtFormat, int32_t length) {
206  UnicodeString dtFormatString((UBool)(length<0), dtFormat, length);
207  ((DateTimePatternGenerator *)dtpg)->setDateTimeFormat(dtFormatString);
208 }
209 
210 U_CAPI const UChar * U_EXPORT2
212  int32_t *pLength) {
213  const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getDateTimeFormat();
214  if(pLength!=NULL) {
215  *pLength=result.length();
216  }
217  return result.getBuffer();
218 }
219 
220 U_CAPI void U_EXPORT2
222  const UChar *decimal, int32_t length) {
223  UnicodeString decimalString((UBool)(length<0), decimal, length);
224  ((DateTimePatternGenerator *)dtpg)->setDecimal(decimalString);
225 }
226 
227 U_CAPI const UChar * U_EXPORT2
229  int32_t *pLength) {
230  const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getDecimal();
231  if(pLength!=NULL) {
232  *pLength=result.length();
233  }
234  return result.getBuffer();
235 }
236 
240  const UChar *skeleton, int32_t skeletonLength,
241  UChar *dest, int32_t destCapacity,
242  UErrorCode *pErrorCode) {
243  return udatpg_replaceFieldTypesWithOptions(dtpg, pattern, patternLength, skeleton, skeletonLength,
245  dest, destCapacity, pErrorCode);
246 }
247 
251  const UChar *skeleton, int32_t skeletonLength,
253  UChar *dest, int32_t destCapacity,
254  UErrorCode *pErrorCode) {
255  if(U_FAILURE(*pErrorCode)) {
256  return 0;
257  }
258  if((pattern==NULL && patternLength!=0) || (skeleton==NULL && skeletonLength!=0)) {
259  *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
260  return 0;
261  }
262  UnicodeString patternString((UBool)(patternLength<0), pattern, patternLength);
263  UnicodeString skeletonString((UBool)(skeletonLength<0), skeleton, skeletonLength);
264  UnicodeString result=((DateTimePatternGenerator *)dtpg)->replaceFieldTypes(patternString, skeletonString, options, *pErrorCode);
265  return result.extract(dest, destCapacity, *pErrorCode);
266 }
267 
271  ((DateTimePatternGenerator *)dtpg)->getSkeletons(*pErrorCode),
272  pErrorCode);
273 }
274 
278  ((DateTimePatternGenerator *)dtpg)->getBaseSkeletons(*pErrorCode),
279  pErrorCode);
280 }
281 
282 U_CAPI const UChar * U_EXPORT2
284  const UChar *skeleton, int32_t skeletonLength,
285  int32_t *pLength) {
286  UnicodeString skeletonString((UBool)(skeletonLength<0), skeleton, skeletonLength);
287  const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getPatternForSkeleton(skeletonString);
288  if(pLength!=NULL) {
289  *pLength=result.length();
290  }
291  return result.getBuffer();
292 }
293 
296  return ((const DateTimePatternGenerator *)dtpg)->getDefaultHourCycle(*pErrorCode);
297 }
298 
299 #endif
#define patternLength
#define width(a)
Definition: aptex-macros.h:198
FcObject field
Definition: fcdefault.c:32
unsigned char UChar
Definition: bzip2.c:163
#define NULL
Definition: ftobjs.h:61
signed int int32_t
Definition: stdint.h:77
int capacity
Definition: pdfcolor.c:1335
#define length(c)
Definition: ctangleboot.c:65
#define dest
#define U_EXPORT2
Definition: platform.h:844
int decimal(char *s)
UDateFormatHourCycle
Definition: udat.h:984
C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
UDateTimePGDisplayWidth
Definition: udatpg.h:108
void * UDateTimePatternGenerator
Definition: udatpg.h:51
UDateTimePatternConflict
Definition: udatpg.h:143
@ UDATPG_NO_CONFLICT
Definition: udatpg.h:145
UDateTimePatternMatchOptions
Definition: udatpg.h:124
@ UDATPG_MATCH_NO_OPTIONS
Definition: udatpg.h:126
UDateTimePatternField
Definition: udatpg.h:59
C API: String Enumeration.
int8_t UBool
Definition: umachine.h:269
#define U_CAPI
Definition: umachine.h:110
Definition: obx.h:51
#define udatpg_openEmpty
Definition: urename.h:906
#define udatpg_getBaseSkeleton
Definition: urename.h:895
#define udatpg_setDecimal
Definition: urename.h:913
#define udatpg_getDateTimeFormat
Definition: urename.h:898
#define udatpg_openSkeletons
Definition: urename.h:907
#define udatpg_open
Definition: urename.h:904
#define udatpg_getPatternForSkeleton
Definition: urename.h:902
#define udatpg_getSkeleton
Definition: urename.h:903
#define udatpg_getFieldDisplayName
Definition: urename.h:901
#define udatpg_getDecimal
Definition: urename.h:899
#define udatpg_clone
Definition: urename.h:891
#define udatpg_setAppendItemName
Definition: urename.h:911
#define udatpg_replaceFieldTypesWithOptions
Definition: urename.h:909
#define uenum_openFromStringEnumeration
Definition: urename.h:930
#define udatpg_getBestPattern
Definition: urename.h:896
#define udatpg_openBaseSkeletons
Definition: urename.h:905
#define udatpg_addPattern
Definition: urename.h:890
#define udatpg_close
Definition: urename.h:892
#define udatpg_getAppendItemName
Definition: urename.h:894
#define udatpg_getAppendItemFormat
Definition: urename.h:893
#define udatpg_getBestPatternWithOptions
Definition: urename.h:897
#define udatpg_setAppendItemFormat
Definition: urename.h:910
#define udatpg_getDefaultHourCycle
Definition: urename.h:900
#define udatpg_replaceFieldTypes
Definition: urename.h:908
#define udatpg_setDateTimeFormat
Definition: urename.h:912
static const char * locale
Definition: uresb.c:52
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Definition: utypes.h:431
@ U_ILLEGAL_ARGUMENT_ERROR
Definition: utypes.h:467
#define U_FAILURE(x)
Definition: utypes.h:735