ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilICalWriter.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
25{
26 protected const LINEBREAK = "\r\n";
27 // minus one to fix multi line breaks.
28 protected const LINE_SIZE = 74;
29 protected const BEGIN_LINE_WHITESPACE = ' ';
30 protected const EMPTY = '';
31
35 protected $lines;
36
37 public function __construct()
38 {
39 $this->lines = [];
40 }
41
42 public static function escapeText($a_text)
43 {
44 $a_text = str_replace("\r\n", '\\n', $a_text);
45
46 return preg_replace(
47 array(
48 '/\\\/',
49 '/;/',
50 '/,/',
51 ),
52 array(
53 '\\',
54 '\;',
55 '\,',
56 ),
57 $a_text
58 );
59 }
60
61 public function addLine(string $a_line) : void
62 {
63 //$chunks = str_split($a_line, self::LINE_SIZE);
64
65 include_once './Services/Utilities/classes/class.ilStr.php';
66
67 // use multibyte split
68 $chunks = [];
69 $len = ilStr::strLen($a_line);
70 while ($len) {
71 $chunks[] = ilStr::subStr($a_line, 0, self::LINE_SIZE);
72 $a_line = ilStr::subStr($a_line, self::LINE_SIZE, $len);
73 $len = ilStr::strLen($a_line);
74 }
75
76 for ($i = 0; $i < count($chunks); $i++) {
77 $line = ($i > 0) ? self::BEGIN_LINE_WHITESPACE : self::EMPTY;
78 $line .= $chunks[$i];
79 $line .= (isset($chunks[$i + 1]) || ($i + 1) === count($chunks)) ? self::LINEBREAK : self::EMPTY;
80 $this->lines[] = $line;
81 }
82 }
83
84 public function byteCount() : int
85 {
86 return strlen($this->__toString());
87 }
88
89 public function clear() : void
90 {
91 $this->lines = [];
92 }
93
94 public function append(ilICalWriter $other) : void
95 {
96 $this->lines = array_merge($this->lines, $other->lines);
97 }
98
99 public function __toString() : string
100 {
101 return implode('', $this->lines);
102 }
103}
An exception for terminatinating execution or to throw for unit testing.
static escapeText($a_text)
addLine(string $a_line)
append(ilICalWriter $other)
static subStr($a_str, $a_start, $a_length=null)
Definition: class.ilStr.php:15
static strLen($a_string)
Definition: class.ilStr.php:78
$i
Definition: metadata.php:24