Libical API Documentation 4.0 UNRELEASED Go to the stable 3.0 documentation
Loading...
Searching...
No Matches
icalperiod.c
Go to the documentation of this file.
1/*======================================================================
2 FILE: icalperiod.c
3 CREATOR: eric 02 June 2000
4
5 SPDX-FileCopyrightText: 2000, Eric Busboom <eric@civicknowledge.com>
6 SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
7
8 The Original Code is eric. The Initial Developer of the Original
9 Code is Eric Busboom
10======================================================================*/
11
16
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include "icalperiod.h"
22#include "icalerror_p.h"
23#include "icalmemory.h"
24
26{
27 struct icalperiodtype p, null_p;
28 char *s = icalmemory_strdup(str);
29 const char *start;
30 char *end;
32
33 /* Errors are normally generated in the following code, so save
34 the error state for resoration later */
35
37
40
41 null_p = p;
42
43 if (s == 0) {
44 goto error;
45 }
46
47 start = s;
48 end = strchr(s, '/');
49
50 if (end == 0) {
51 goto error;
52 }
53
54 *end = 0;
55 end++;
56
58
60 goto error;
61 }
62
65
67
69
72
74 goto error;
75 }
76 }
77
78 icalerrno = e;
80 return p;
81
82error:
85 return null_p;
86}
87
89{
90 char *buf;
91
94 return buf;
95}
96
98{
99 const char *start;
100 const char *end;
101
102 char *buf;
103 size_t buf_size = 40;
104 char *buf_ptr = 0;
105
106 buf = (char *)icalmemory_new_buffer(buf_size);
107 buf_ptr = buf;
108
110 icalmemory_append_string(&buf, &buf_ptr, &buf_size, start);
112
113 if (!icaltime_is_null_time(p.end)) {
115 } else {
117 }
118
119 icalmemory_append_char(&buf, &buf_ptr, &buf_size, '/');
120
121 icalmemory_append_string(&buf, &buf_ptr, &buf_size, end);
123
124 return buf;
125}
126
128{
129 struct icalperiodtype p;
130
134
135 return p;
136}
137
139{
142 return true;
143 } else {
144 return false;
145 }
146}
147
149{
152 return true;
153 }
154
155 return false;
156}
char * icaldurationtype_as_ical_string_r(struct icaldurationtype d)
struct icaldurationtype icaldurationtype_from_string(const char *str)
Creates a new icaldurationtype from a duration given as a string.
bool icaldurationtype_is_null_duration(struct icaldurationtype d)
Checks if a duration is a null duration.
struct icaldurationtype icaldurationtype_null_duration(void)
Creates a duration with zero length.
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
Definition icalerror.c:90
icalerrorstate
Determine if an error is fatal or non-fatal.
Definition icalerror.h:86
@ ICAL_ERROR_NONFATAL
Definition icalerror.h:91
icalerrorstate icalerror_get_error_state(icalerrorenum error)
Gets the error state (severity) for a given error.
icalerrorenum
Represents the different types of errors that can be triggered in libical.
Definition icalerror.h:42
@ ICAL_MALFORMEDDATA_ERROR
Definition icalerror.h:56
void icalerror_set_error_state(icalerrorenum error, icalerrorstate state)
Sets the icalerrorstate for a given icalerrorenum error.
#define icalerrno
Access the current icalerrno value.
Definition icalerror.h:130
void icalmemory_free_buffer(void *buf)
Releases a buffer.
Definition icalmemory.c:353
char * icalmemory_strdup(const char *s)
Creates a duplicate of a string.
Definition icalmemory.c:240
void icalmemory_append_string(char **buf, char **pos, size_t *buf_size, const char *string)
Appends a string to a buffer.
Definition icalmemory.c:363
void * icalmemory_new_buffer(size_t size)
Creates new buffer with the specified size.
Definition icalmemory.c:313
void icalmemory_append_char(char **buf, char **pos, size_t *buf_size, char ch)
Appends a character to a buffer.
Definition icalmemory.c:404
void icalmemory_add_tmp_buffer(void *buf)
Adds an externally allocated buffer to the ring.
Definition icalmemory.c:156
Common memory management routines.
const char * icalperiodtype_as_ical_string(struct icalperiodtype p)
Converts an icalperiodtype into an iCal-formatted string.
Definition icalperiod.c:88
char * icalperiodtype_as_ical_string_r(struct icalperiodtype p)
Converts an icalperiodtype into an iCal-formatted string.
Definition icalperiod.c:97
bool icalperiodtype_is_null_period(struct icalperiodtype p)
Definition icalperiod.c:138
struct icalperiodtype icalperiodtype_null_period(void)
Definition icalperiod.c:127
struct icalperiodtype icalperiodtype_from_string(const char *str)
Constructs a new icalperiodtype from str.
Definition icalperiod.c:25
bool icalperiodtype_is_valid_period(struct icalperiodtype p)
Definition icalperiod.c:148
Defines data structures for working with iCal periods (of time).
struct icaltimetype icaltime_from_string(const char *str)
Definition icaltime.c:374
bool icaltime_is_valid_time(const struct icaltimetype t)
Definition icaltime.c:603
bool icaltime_is_null_time(const struct icaltimetype t)
Definition icaltime.c:626
struct icaltimetype icaltime_null_time(void)
Definition icaltime.c:575
char * icaltime_as_ical_string_r(const struct icaltimetype tt)
Definition icaltime.c:341
struct icaldurationtype duration
Definition icalperiod.h:36
struct icaltimetype end
Definition icalperiod.h:34
struct icaltimetype start
Definition icalperiod.h:31