Completed
Push — master ( 361a80...57c765 )
by Atanas
07:10
created

Delimiter::unquote()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Carbon_Fields\Helper;
4
5
/**
6
 * Delimiter functions
7
 */
8
class Delimiter {
9
	/**
10
	 * Character to escape delimiters with
11
	 * We're using an uncommon escape character as to not clash with stripslashes
12
	 *
13
	 * @var string
14
	 */
15
	protected static $escape_character = '!';
16
17
	/**
18
	 * Quote a delimiter in the passed value
19
	 *
20
	 * @param  string $value
21
	 * @param  string $delimiter
22
	 * @return string
23
	 */
24
	public static function quote( $value, $delimiter ) {
25
		return str_replace( $delimiter, static::$escape_character . $delimiter, $value );
26
	}
27
28
	/**
29
	 * Unquote a delimiter in the passed value
30
	 *
31
	 * @param  string $value
32
	 * @param  string $delimiter
33
	 * @return string
34
	 */
35
	public static function unquote( $value, $delimiter ) {
36
		return str_replace( static::$escape_character . $delimiter, $delimiter, $value );
37
	}
38
39
	/**
40
	 * Split the passed value by a delimiter
41
	 *
42
	 * @param  string $value
43
	 * @param  string $delimiter
44
	 * @return array
45
	 */
46
	public static function split( $value, $delimiter ) {
47
		return preg_split( '~(?<!' . preg_quote( static::$escape_character, '~' ) . ')' . preg_quote( $delimiter, '~' ) . '~', $value );
48
	}
49
}
50