2 ======================================================================
3 FILE: icalderivedparameters.{c,h}
4 CREATOR: eric 09 May 1999
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 icalderivedparameters.{c,h}
26 Graham Davison (g.m.davison@computer.org)
28 ======================================================================*/
29 /*#line 29 "icalparameter.c.in"*/
35 #include "icalparameter.h"
36 #include "icalparameterimpl.h"
38 #include "icalproperty.h"
39 #include "icalerror.h"
40 #include "icalmemory.h"
42 #include <stdlib.h> /* for malloc() */
44 #include <string.h> /* for memset() */
46 icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value);
48 struct icalparameter_impl* icalparameter_new_impl(icalparameter_kind kind);
50 /* This map associates each of the parameters with the string
51 representation of the paramter's name */
52 struct icalparameter_kind_map {
53 icalparameter_kind kind;
58 static struct icalparameter_kind_map parameter_map[];
61 const char* icalparameter_kind_to_string(icalparameter_kind kind)
65 for (i=0; parameter_map[i].kind != ICAL_NO_PARAMETER; i++) {
66 if (parameter_map[i].kind == kind) {
67 return parameter_map[i].name;
75 icalparameter_kind icalparameter_string_to_kind(const char* string)
80 return ICAL_NO_PARAMETER;
83 for (i=0; parameter_map[i].kind != ICAL_NO_PARAMETER; i++) {
85 if (strcmp(parameter_map[i].name, string) == 0) {
86 return parameter_map[i].kind;
90 if(strncmp(string,"X-",2)==0){
91 return ICAL_X_PARAMETER;
94 return ICAL_NO_PARAMETER;
97 /* This map associates the enumerations for the VALUE parameter with
98 the kinds of VALUEs. */
100 struct icalparameter_value_kind_map {
101 icalparameter_value value;
105 static struct icalparameter_value_kind_map value_kind_map[];
108 icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value)
112 for (i=0; value_kind_map[i].kind != ICAL_NO_VALUE; i++) {
114 if (value_kind_map[i].value == value) {
115 return value_kind_map[i].kind;
119 return ICAL_NO_VALUE;
123 /* This map associates the parameter enumerations with a specific parameter and the string representation of the enumeration */
125 struct icalparameter_map {
126 icalparameter_kind kind;
132 static struct icalparameter_map icalparameter_map[];
135 const char* icalparameter_enum_to_string(int e)
139 icalerror_check_arg_rz(e >= ICALPARAMETER_FIRST_ENUM,"e");
140 icalerror_check_arg_rz(e <= ICALPARAMETER_LAST_ENUM,"e");
142 for (i=0; icalparameter_map[i].kind != ICAL_NO_PARAMETER; i++){
143 if(e == icalparameter_map[i].enumeration){
144 return icalparameter_map[i].str;
151 int icalparameter_string_to_enum(const char* str)
155 icalerror_check_arg_rz(str != 0,"str");
157 for (i=0; icalparameter_map[i].kind != ICAL_NO_PARAMETER; i++){
158 if(strcmp(str,icalparameter_map[i].str) == 0) {
159 return icalparameter_map[i].enumeration;
166 icalparameter* icalparameter_new_from_value_string(icalparameter_kind kind,const char* val)
169 struct icalparameter_impl* param=0;
173 icalerror_check_arg_rz((val!=0),"val");
175 /* Search through the parameter map to find a matching kind */
177 param = icalparameter_new_impl(kind);
179 for (i=0; icalparameter_map[i].kind != ICAL_NO_PARAMETER; i++){
180 if(kind == icalparameter_map[i].kind) {
181 char *raw_val = strdup(val);
182 char *value = raw_val;
184 if(value[0] == '\"' && value[strlen(value) - 1] == '\"') {
186 value[strlen(value) - 1] = '\0';
188 if(strcmp(value,icalparameter_map[i].str) == 0) {
190 param->data = (int)icalparameter_map[i].enumeration;
198 /* The kind was in the parameter map, but the string did not
199 match, so assume that it is an alternate value, like an
202 icalparameter_set_xvalue(param, val);
206 /* If the kind was not found, then it must be a string type */
208 ((struct icalparameter_impl*)param)->string = icalmemory_strdup(val);
218 /* Everything below this line is machine generated. Do not edit. */