3 /*======================================================================
4 FILE: icalderivedproperty.c
5 CREATOR: eric 15 Feb 2001
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"
39 #include <string.h> /* For icalmemory_strdup, rindex */
43 #include <stdio.h> /* for printf */
44 #include <stdarg.h> /* for va_list, va_start, etc. */
46 #define TMP_BUF_SIZE 1024
48 struct icalproperty_impl*
49 icalproperty_new_impl (icalproperty_kind kind);
51 /* This map associates the property kinds with the string
52 representation of the property name and the kind of VALUE that the
53 property uses as a default */
55 struct icalproperty_map {
56 icalproperty_kind kind;
62 static struct icalproperty_map property_map[];
64 const char* icalproperty_kind_to_string(icalproperty_kind kind)
68 for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
69 if (property_map[i].kind == kind) {
70 return property_map[i].name;
79 icalproperty_kind icalproperty_string_to_kind(const char* string)
84 return ICAL_NO_PROPERTY;
88 for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
89 if (strcmp(property_map[i].name, string) == 0) {
90 return property_map[i].kind;
94 if(strncmp(string,"X-",2)==0){
95 return ICAL_X_PROPERTY;
99 return ICAL_NO_PROPERTY;
103 icalvalue_kind icalproperty_value_kind_to_kind(icalvalue_kind kind)
107 for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
108 if ( property_map[i].value == kind ) {
109 return property_map[i].kind;
113 return ICAL_NO_VALUE;
118 icalvalue_kind icalproperty_kind_to_value_kind(icalproperty_kind kind)
122 for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
123 if ( property_map[i].kind == kind ) {
124 return property_map[i].value;
128 return ICAL_NO_VALUE;
132 /* This map associates the property enumerations with the king of
133 property that they are used in and the string representation of the
136 struct icalproperty_enum_map {
137 icalproperty_kind prop;
142 static struct icalproperty_enum_map enum_map[];
145 const char* icalproperty_enum_to_string(int e)
147 icalerror_check_arg_rz(e >= ICALPROPERTY_FIRST_ENUM,"e");
148 icalerror_check_arg_rz(e <= ICALPROPERTY_LAST_ENUM,"e");
150 return enum_map[e-ICALPROPERTY_FIRST_ENUM].str;
153 int icalproperty_string_to_enum(const char* str)
157 icalerror_check_arg_rz(str!=0,"str")
163 for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
164 if ( strcmp(enum_map[i-ICALPROPERTY_FIRST_ENUM].str, str) == 0) {
165 return enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum;
172 int icalproperty_enum_belongs_to_property(icalproperty_kind kind, int e)
177 for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
178 if(enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum == e &&
179 enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == kind ){
188 const char* icalproperty_method_to_string(icalproperty_method method)
190 icalerror_check_arg_rz(method >= ICAL_METHOD_X,"method");
191 icalerror_check_arg_rz(method <= ICAL_METHOD_NONE,"method");
193 return enum_map[method-ICALPROPERTY_FIRST_ENUM].str;
196 icalproperty_method icalproperty_string_to_method(const char* str)
200 icalerror_check_arg_rx(str!=0,"str",ICAL_METHOD_NONE)
206 for (i=ICAL_METHOD_X-ICALPROPERTY_FIRST_ENUM;
207 i != ICAL_METHOD_NONE-ICALPROPERTY_FIRST_ENUM;
209 if ( strcmp(enum_map[i].str, str) == 0) {
210 return (icalproperty_method)enum_map[i].prop_enum;
214 return ICAL_METHOD_NONE;
218 const char* icalenum_status_to_string(icalproperty_status status)
220 icalerror_check_arg_rz(status >= ICAL_STATUS_X,"status");
221 icalerror_check_arg_rz(status <= ICAL_STATUS_NONE,"status");
223 return enum_map[status-ICALPROPERTY_FIRST_ENUM].str;
226 icalproperty_status icalenum_string_to_status(const char* str)
230 icalerror_check_arg_rx(str!=0,"str",ICAL_STATUS_NONE)
236 for (i=ICAL_STATUS_X-ICALPROPERTY_FIRST_ENUM;
237 i != ICAL_STATUS_NONE-ICALPROPERTY_FIRST_ENUM;
239 if ( strcmp(enum_map[i].str, str) == 0) {
240 return (icalproperty_method)enum_map[i].prop_enum;
244 return ICAL_STATUS_NONE;
250 /* Everything below this line is machine generated. Do not edit. */