• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /********************************************************************
2  * COPYRIGHT:
3  * Copyright (c) 2007, International Business Machines Corporation and
4  * others. All Rights Reserved.
5  ********************************************************************/
6 
7 #include "unicode/udbgutil.h"
8 
9 
10 
11 struct Field {
12         int32_t prefix; /* how many characters to remove - i.e. UCHAR_ = 5 */
13 	const char *str;
14 	int32_t num;
15 };
16 
17 #define DBG_ARRAY_COUNT(x) (sizeof(x)/sizeof(x[0]))
18 
19 
20 // The fields
21 
22 #if !UCONFIG_NO_FORMATTING
23 
24 #include "unicode/ucal.h"
25 // Calendar
26 
27 
28 // 'UCAL_' = 5
29 #define FIELD_NAME_STR(y,x)  { y, #x, x }
30 
31 #define LEN_UCAL 5 /* UCAL_ */
32 
33 static const int32_t count_UCalendarDateFields = UCAL_FIELD_COUNT;
34 
35 static const Field names_UCalendarDateFields[] =
36 {
37     FIELD_NAME_STR( LEN_UCAL, UCAL_ERA ),
38     FIELD_NAME_STR( LEN_UCAL, UCAL_YEAR ),
39     FIELD_NAME_STR( LEN_UCAL, UCAL_MONTH ),
40     FIELD_NAME_STR( LEN_UCAL, UCAL_WEEK_OF_YEAR ),
41     FIELD_NAME_STR( LEN_UCAL, UCAL_WEEK_OF_MONTH ),
42     FIELD_NAME_STR( LEN_UCAL, UCAL_DATE ),
43     FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_YEAR ),
44     FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_WEEK ),
45     FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_WEEK_IN_MONTH ),
46     FIELD_NAME_STR( LEN_UCAL, UCAL_AM_PM ),
47     FIELD_NAME_STR( LEN_UCAL, UCAL_HOUR ),
48     FIELD_NAME_STR( LEN_UCAL, UCAL_HOUR_OF_DAY ),
49     FIELD_NAME_STR( LEN_UCAL, UCAL_MINUTE ),
50     FIELD_NAME_STR( LEN_UCAL, UCAL_SECOND ),
51     FIELD_NAME_STR( LEN_UCAL, UCAL_MILLISECOND ),
52     FIELD_NAME_STR( LEN_UCAL, UCAL_ZONE_OFFSET ),
53     FIELD_NAME_STR( LEN_UCAL, UCAL_DST_OFFSET ),
54     FIELD_NAME_STR( LEN_UCAL, UCAL_YEAR_WOY ),
55     FIELD_NAME_STR( LEN_UCAL, UCAL_DOW_LOCAL ),
56     FIELD_NAME_STR( LEN_UCAL, UCAL_EXTENDED_YEAR ),
57     FIELD_NAME_STR( LEN_UCAL, UCAL_JULIAN_DAY ),
58     FIELD_NAME_STR( LEN_UCAL, UCAL_MILLISECONDS_IN_DAY ),
59 };
60 
61 
62 static const int32_t count_UCalendarMonths = UCAL_UNDECIMBER+1;
63 
64 static const Field names_UCalendarMonths[] =
65 {
66   FIELD_NAME_STR( LEN_UCAL, UCAL_JANUARY ),
67   FIELD_NAME_STR( LEN_UCAL, UCAL_FEBRUARY ),
68   FIELD_NAME_STR( LEN_UCAL, UCAL_MARCH ),
69   FIELD_NAME_STR( LEN_UCAL, UCAL_APRIL ),
70   FIELD_NAME_STR( LEN_UCAL, UCAL_MAY ),
71   FIELD_NAME_STR( LEN_UCAL, UCAL_JUNE ),
72   FIELD_NAME_STR( LEN_UCAL, UCAL_JULY ),
73   FIELD_NAME_STR( LEN_UCAL, UCAL_AUGUST ),
74   FIELD_NAME_STR( LEN_UCAL, UCAL_SEPTEMBER ),
75   FIELD_NAME_STR( LEN_UCAL, UCAL_OCTOBER ),
76   FIELD_NAME_STR( LEN_UCAL, UCAL_NOVEMBER ),
77   FIELD_NAME_STR( LEN_UCAL, UCAL_DECEMBER ),
78   FIELD_NAME_STR( LEN_UCAL, UCAL_UNDECIMBER)
79 };
80 
81 #include "unicode/udat.h"
82 
83 #define LEN_UDAT 5 /* "UDAT_" */
84 
85 static const int32_t count_UDateFormatStyle = UDAT_SHORT+1;
86 
87 static const Field names_UDateFormatStyle[] =
88 {
89         FIELD_NAME_STR( LEN_UDAT, UDAT_FULL ),
90         FIELD_NAME_STR( LEN_UDAT, UDAT_LONG ),
91         FIELD_NAME_STR( LEN_UDAT, UDAT_MEDIUM ),
92         FIELD_NAME_STR( LEN_UDAT, UDAT_SHORT ),
93         /* end regular */
94     /*
95      *  negative enums.. leave out for now.
96         FIELD_NAME_STR( LEN_UDAT, UDAT_NONE ),
97         FIELD_NAME_STR( LEN_UDAT, UDAT_IGNORE ),
98      */
99 };
100 
101 
102 
103 #define LEN_UDBG 5 /* "UDBG_" */
104 
105 static const int32_t count_UDebugEnumType = UDBG_ENUM_COUNT;
106 
107 static const Field names_UDebugEnumType[] =
108 {
109     FIELD_NAME_STR( LEN_UDBG, UDBG_UDebugEnumType ),
110     FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarDateFields ),
111     FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarMonths ),
112     FIELD_NAME_STR( LEN_UDBG, UDBG_UDateFormatStyle ),
113 };
114 
115 
116 #define COUNT_CASE(x)  case UDBG_##x: return (actual?count_##x:DBG_ARRAY_COUNT(names_##x));
117 #define COUNT_FAIL_CASE(x) case UDBG_##x: return -1;
118 
119 #define FIELD_CASE(x)  case UDBG_##x: return names_##x;
120 #define FIELD_FAIL_CASE(x) case UDBG_##x: return NULL;
121 
122 #else
123 
124 #define COUNT_CASE(x)
125 #define COUNT_FAIL_CASE(x)
126 
127 #define FIELD_CASE(X)
128 #define FIELD_FAIL_CASE(x)
129 
130 #endif
131 
132 // low level
133 
134 /**
135  * @param type type of item
136  * @param actual TRUE: for the actual enum's type (UCAL_FIELD_COUNT, etc), or FALSE for the string count
137  */
_udbg_enumCount(UDebugEnumType type,UBool actual)138 static int32_t _udbg_enumCount(UDebugEnumType type, UBool actual) {
139 	switch(type) {
140 		COUNT_CASE(UDebugEnumType)
141 		COUNT_CASE(UCalendarDateFields)
142 		COUNT_CASE(UCalendarMonths)
143 		COUNT_CASE(UDateFormatStyle)
144 		// COUNT_FAIL_CASE(UNonExistentEnum)
145 	default:
146 		return -1;
147 	}
148 }
149 
_udbg_enumFields(UDebugEnumType type)150 static const Field* _udbg_enumFields(UDebugEnumType type) {
151 	switch(type) {
152 		FIELD_CASE(UDebugEnumType)
153 		FIELD_CASE(UCalendarDateFields)
154 		FIELD_CASE(UCalendarMonths)
155 		FIELD_CASE(UDateFormatStyle)
156 		// FIELD_FAIL_CASE(UNonExistentEnum)
157 	default:
158 		return NULL;
159 	}
160 }
161 
162 // implementation
163 
udbg_enumCount(UDebugEnumType type)164 int32_t  udbg_enumCount(UDebugEnumType type) {
165 	return _udbg_enumCount(type, FALSE);
166 }
167 
udbg_enumExpectedCount(UDebugEnumType type)168 int32_t  udbg_enumExpectedCount(UDebugEnumType type) {
169 	return _udbg_enumCount(type, TRUE);
170 }
171 
udbg_enumName(UDebugEnumType type,int32_t field)172 const char *  udbg_enumName(UDebugEnumType type, int32_t field) {
173 	if(field<0 ||
174 				field>=_udbg_enumCount(type,FALSE)) { // also will catch unsupported items
175 		return NULL;
176 	} else {
177 		const Field *fields = _udbg_enumFields(type);
178 		if(fields == NULL) {
179 			return NULL;
180 		} else {
181 			return fields[field].str + fields[field].prefix;
182 		}
183 	}
184 }
185 
udbg_enumArrayValue(UDebugEnumType type,int32_t field)186 int32_t  udbg_enumArrayValue(UDebugEnumType type, int32_t field) {
187 	if(field<0 ||
188 				field>=_udbg_enumCount(type,FALSE)) { // also will catch unsupported items
189 		return -1;
190 	} else {
191 		const Field *fields = _udbg_enumFields(type);
192 		if(fields == NULL) {
193 			return -1;
194 		} else {
195 			return fields[field].num;
196 		}
197 	}
198 }
199