ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilICalWriter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected const LINEBREAK = "\r\n";
24
25 // minus one to fix multi line breaks.
26 protected const LINE_SIZE = 74;
27 protected const BEGIN_LINE_WHITESPACE = ' ';
28 protected const EMPTY = '';
29
30
34 protected array $lines;
35
36 public function __construct()
37 {
38 $this->lines = [];
39 }
40
41 public static function escapeText(string $a_text): string
42 {
43 $a_text = str_replace("\r\n", '\\n', $a_text);
44
45 return preg_replace(
46 array(
47 '/\\\/',
48 '/;/',
49 '/,/',
50 ),
51 array(
52 '\\',
53 '\;',
54 '\,',
55 ),
56 $a_text
57 );
58 }
59
60 public function addLine(string $a_line): void
61 {
62 // use multibyte split
63 $chunks = [];
64 $len = ilStr::strLen($a_line);
65 while ($len) {
66 $chunks[] = ilStr::subStr($a_line, 0, self::LINE_SIZE);
67 $a_line = ilStr::subStr($a_line, self::LINE_SIZE, $len);
68 $len = ilStr::strLen($a_line);
69 }
70
71 for ($i = 0; $i < count($chunks); $i++) {
72 $line = ($i > 0) ? self::BEGIN_LINE_WHITESPACE : self::EMPTY;
73 $line .= $chunks[$i];
74 $line .= (isset($chunks[$i + 1]) || ($i + 1) === count($chunks)) ? self::LINEBREAK : self::EMPTY;
75 $this->lines[] = $line;
76 }
77 }
78
79 public function byteCount(): int
80 {
81 return strlen($this->__toString());
82 }
83
84 public function clear(): void
85 {
86 $this->lines = [];
87 }
88
89 public function append(ilICalWriter $other): void
90 {
91 $this->lines = array_merge($this->lines, $other->lines);
92 }
93
94 public function __toString(): string
95 {
96 return implode('', $this->lines);
97 }
98}
static escapeText(string $a_text)
addLine(string $a_line)
append(ilICalWriter $other)
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:21
static strLen(string $a_string)
Definition: class.ilStr.php:60