7 * ICalParser is a general purpose .Net parser for iCalendar format files (RFC 2445)
9 * Copyright (C) 2004 J. Tim Spurway
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 namespace Semaview
.Shared
.ICalParser
30 /// Summary description for ICalUtil.
41 * Lines of text SHOULD NOT be longer than 75 octets, excluding the line
42 * break. Long content lines SHOULD be split into a multiple line
43 * representations using a line "folding" technique. That is, a long
44 * line can be split between any two characters by inserting a CRLF
45 * immediately followed by a single linear white space character (i.e.,
46 * SPACE, US-ASCII decimal 32 or HTAB, US-ASCII decimal 9). Any sequence
47 * of CRLF followed immediately by a single linear white space character
48 * is ignored (i.e., removed) when processing the content type.
50 * For example the line:
52 * DESCRIPTION:This is a long description that exists on a long line.
54 * Can be represented as:
56 * DESCRIPTION:This is a lo
58 * that exists on a long line.
61 public static string FoldLines( StringBuilder iCal
)
63 StringReader reader
= new StringReader( iCal
.ToString() );
64 StringBuilder folded
= new StringBuilder();
65 string line
= reader
.ReadLine();
69 int len
= line
.Length
;
71 // I chose 72 instead of the max 75 cause I wanted to, so :P
74 // Indent if not first line
77 folded
.AppendFormat( "{0}\r\n", line
.Substring( start
, 72 ) );
81 // Indent if not first line
84 folded
.AppendFormat( "{0}\r\n", line
.Substring( start
, len
) );
85 line
= reader
.ReadLine();
87 return folded
.ToString();
91 /// Quotes newlines, tabs, commas, colons, semi-colons, double quotes and back slashes
93 /// <param name="str"></param>
94 /// <returns></returns>
95 public static string Quote( string str
)
97 string quoted
= str
.Replace( "\\", "\\\\" );
98 quoted
= quoted
.Replace( "\r\n", "\\n" );
99 quoted
= quoted
.Replace( "\n", "\\n" );
100 quoted
= quoted
.Replace( "\t", "\\t" );
101 quoted
= quoted
.Replace( ",", "\\," );
102 quoted
= quoted
.Replace( ":", "\\:" );
103 quoted
= quoted
.Replace( ";", "\\;" );
104 quoted
= quoted
.Replace( "\"", "\\\"" );
108 public static string Unquote( string str
)
110 string unquoted
= str
.Replace( "\\r\\n", "\r\n" );
111 unquoted
= unquoted
.Replace( "\\n", "\r\n" );
112 unquoted
= unquoted
.Replace( "\\t", "\t" );
113 unquoted
= unquoted
.Replace( "\\,", "," );
114 unquoted
= unquoted
.Replace( "\\:", ":" );
115 unquoted
= unquoted
.Replace( "\\;", ";" );
116 unquoted
= unquoted
.Replace( "\\\"", "\"" );
117 unquoted
= unquoted
.Replace( "\\\\", "\\" );
118 return unquoted
.ToString();