3 /*======================================================================
4 FILE: icalderivedproperty.c
5 CREATOR: eric 15 Feb 2001
7 $Id: icalderivedproperty.c.in,v 1.15 2008-01-28 22:34:37 artcancro Exp $
10 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of either:
15 The LGPL as published by the Free Software Foundation, version
16 2.1, available at: http://www.fsf.org/copyleft/lesser.html
20 The Mozilla Public License Version 1.0. You may obtain a copy of
21 the License at http://www.mozilla.org/MPL/
23 The original code is icalproperty.c
25 ======================================================================*/
31 #include "icalproperty.h"
32 #include "icalcomponent.h"
34 #include "icalenums.h"
35 #include "icalerror.h"
36 #include "icalmemory.h"
37 #include "icalparser.h"
38 #include "icaltimezone.h"
40 #include <string.h> /* For icalmemory_strdup, rindex */
44 #include <stdio.h> /* for printf */
45 #include <stdarg.h> /* for va_list, va_start, etc. */
48 #define strcasecmp stricmp
51 struct icalproperty_impl*
52 icalproperty_new_impl (icalproperty_kind kind);
53 void icalproperty_add_parameters(struct icalproperty_impl *prop,va_list args);
55 /* This map associates the property kinds with the string
56 representation of the property name and the kind of VALUE that the
57 property uses as a default */
59 struct icalproperty_map {
60 icalproperty_kind kind;
66 /* This map associates the property enumerations with the king of
67 property that they are used in and the string representation of the
70 struct icalproperty_enum_map {
71 icalproperty_kind prop;
79 int icalproperty_kind_is_valid(const icalproperty_kind kind)
83 if (property_map[i].kind == kind)
85 } while (property_map[i++].kind != ICAL_NO_PROPERTY);
90 const char* icalproperty_kind_to_string(icalproperty_kind kind)
94 for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
95 if (property_map[i].kind == kind) {
96 return property_map[i].name;
105 icalproperty_kind icalproperty_string_to_kind(const char* string)
110 return ICAL_NO_PROPERTY;
114 for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
115 if (strcasecmp(property_map[i].name, string) == 0) {
116 return property_map[i].kind;
120 if(strncmp(string,"X-",2)==0){
121 return ICAL_X_PROPERTY;
125 return ICAL_NO_PROPERTY;
129 icalproperty_kind icalproperty_value_kind_to_kind(icalvalue_kind kind)
133 for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
134 if ( property_map[i].value == kind ) {
135 return property_map[i].kind;
139 return ICAL_NO_PROPERTY;
144 icalvalue_kind icalproperty_kind_to_value_kind(icalproperty_kind kind)
148 for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
149 if ( property_map[i].kind == kind ) {
150 return property_map[i].value;
154 return ICAL_NO_VALUE;
158 const char* icalproperty_enum_to_string(int e)
160 icalerror_check_arg_rz(e >= ICALPROPERTY_FIRST_ENUM,"e");
161 icalerror_check_arg_rz(e <= ICALPROPERTY_LAST_ENUM,"e");
163 return enum_map[e-ICALPROPERTY_FIRST_ENUM].str;
167 char *icalproperty_enum_to_string_r(int e)
169 return icalmemory_strdup(icalproperty_enum_to_string(e));
173 int icalproperty_kind_and_string_to_enum(const int kind, const char* str)
175 icalproperty_kind pkind;
178 icalerror_check_arg_rz(str!=0,"str")
180 if ((pkind = icalproperty_value_kind_to_kind(kind)) == ICAL_NO_PROPERTY)
187 for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
188 if (enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == pkind)
191 if (i == ICALPROPERTY_LAST_ENUM)
194 for (; i != ICALPROPERTY_LAST_ENUM; i++) {
195 if(enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == pkind &&
196 strcasecmp(enum_map[i-ICALPROPERTY_FIRST_ENUM].str, str) == 0) {
197 return enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum;
204 /** @deprecated please use icalproperty_kind_and_string_to_enum instead */
205 int icalproperty_string_to_enum(const char* str)
209 icalerror_check_arg_rz(str!=0,"str")
215 for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
216 if ( strcasecmp(enum_map[i-ICALPROPERTY_FIRST_ENUM].str, str) == 0) {
217 return enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum;
224 int icalproperty_enum_belongs_to_property(icalproperty_kind kind, int e)
229 for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
230 if(enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum == e &&
231 enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == kind ){
240 const char* icalproperty_method_to_string(icalproperty_method method)
242 icalerror_check_arg_rz(method >= ICAL_METHOD_X,"method");
243 icalerror_check_arg_rz(method <= ICAL_METHOD_NONE,"method");
245 return enum_map[method-ICALPROPERTY_FIRST_ENUM].str;
248 icalproperty_method icalproperty_string_to_method(const char* str)
252 icalerror_check_arg_rx(str!=0,"str",ICAL_METHOD_NONE)
258 for (i=ICAL_METHOD_X-ICALPROPERTY_FIRST_ENUM;
259 i != ICAL_METHOD_NONE-ICALPROPERTY_FIRST_ENUM;
261 if ( strcasecmp(enum_map[i].str, str) == 0) {
262 return (icalproperty_method)enum_map[i].prop_enum;
266 return ICAL_METHOD_NONE;
270 const char* icalenum_status_to_string(icalproperty_status status)
272 icalerror_check_arg_rz(status >= ICAL_STATUS_X,"status");
273 icalerror_check_arg_rz(status <= ICAL_STATUS_NONE,"status");
275 return enum_map[status-ICALPROPERTY_FIRST_ENUM].str;
278 icalproperty_status icalenum_string_to_status(const char* str)
282 icalerror_check_arg_rx(str!=0,"str",ICAL_STATUS_NONE)
288 for (i=ICAL_STATUS_X-ICALPROPERTY_FIRST_ENUM;
289 i != ICAL_STATUS_NONE-ICALPROPERTY_FIRST_ENUM;
291 if ( strcasecmp(enum_map[i].str, str) == 0) {
292 return (icalproperty_status)enum_map[i].prop_enum;
296 return ICAL_STATUS_NONE;