2 ======================================================================
3 FILE: icalderivedparameters.{c,h}
4 CREATOR: eric 09 May 1999
6 $Id: icalderivedparameter.c.in,v 1.9 2008-01-15 23:17:40 dothebart 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 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"
41 #include "icaltypes.h"
43 #include <stdlib.h> /* for malloc() */
45 #include <string.h> /* for memset() */
48 #define strcasecmp stricmp
51 icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value);
53 struct icalparameter_impl* icalparameter_new_impl(icalparameter_kind kind);
55 /* This map associates each of the parameters with the string
56 representation of the parameter's name */
57 struct icalparameter_kind_map {
58 icalparameter_kind kind;
63 /* This map associates the enumerations for the VALUE parameter with
64 the kinds of VALUEs. */
66 struct icalparameter_value_kind_map {
67 icalparameter_value value;
71 /* This map associates the parameter enumerations with a specific parameter and the string representation of the enumeration */
73 struct icalparameter_map {
74 icalparameter_kind kind;
83 const char* icalparameter_kind_to_string(icalparameter_kind kind)
87 for (i=0; parameter_map[i].kind != ICAL_NO_PARAMETER; i++) {
88 if (parameter_map[i].kind == kind) {
89 return parameter_map[i].name;
97 icalparameter_kind icalparameter_string_to_kind(const char* string)
102 return ICAL_NO_PARAMETER;
105 for (i=0; parameter_map[i].kind != ICAL_NO_PARAMETER; i++) {
107 if (strcasecmp(parameter_map[i].name, string) == 0) {
108 return parameter_map[i].kind;
112 if(strncmp(string,"X-",2)==0){
113 return ICAL_X_PARAMETER;
116 if (ical_get_unknown_token_handling_setting() == ICAL_TREAT_AS_ERROR) {
117 return ICAL_NO_PARAMETER;
119 return ICAL_IANA_PARAMETER;
124 icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value)
128 for (i=0; value_kind_map[i].kind != ICAL_NO_VALUE; i++) {
130 if (value_kind_map[i].value == value) {
131 return value_kind_map[i].kind;
135 return ICAL_NO_VALUE;
139 const char* icalparameter_enum_to_string(int e)
143 icalerror_check_arg_rz(e >= ICALPARAMETER_FIRST_ENUM,"e");
144 icalerror_check_arg_rz(e <= ICALPARAMETER_LAST_ENUM,"e");
146 for (i=0; icalparameter_map[i].kind != ICAL_NO_PARAMETER; i++){
147 if(e == icalparameter_map[i].enumeration){
148 return icalparameter_map[i].str;
155 int icalparameter_string_to_enum(const char* str)
159 icalerror_check_arg_rz(str != 0,"str");
161 for (i=0; icalparameter_map[i].kind != ICAL_NO_PARAMETER; i++){
162 if(strcasecmp(str,icalparameter_map[i].str) == 0) {
163 return icalparameter_map[i].enumeration;
170 icalparameter* icalparameter_new_from_value_string(icalparameter_kind kind,const char* val)
173 struct icalparameter_impl* param=0;
177 icalerror_check_arg_rz((val!=0),"val");
179 /* Search through the parameter map to find a matching kind */
181 param = icalparameter_new_impl(kind);
185 for (i=0; icalparameter_map[i].kind != ICAL_NO_PARAMETER; i++){
186 if(kind == icalparameter_map[i].kind) {
188 if(strcasecmp(val,icalparameter_map[i].str) == 0) {
190 param->data = (int)icalparameter_map[i].enumeration;
197 /* The kind was in the parameter map, but the string did not
198 match, so assume that it is an alternate value, like an
201 icalparameter_set_xvalue(param, val);
205 /* If the kind was not found, then it must be a string type */
207 ((struct icalparameter_impl*)param)->string = icalmemory_strdup(val);