This repository was archived by the owner on May 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathStringUtilities.php
More file actions
executable file
·106 lines (95 loc) · 2.87 KB
/
StringUtilities.php
File metadata and controls
executable file
·106 lines (95 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* OWASP Enterprise Security API (ESAPI)
*
* This file is part of the Open Web Application Security Project (OWASP)
* Enterprise Security API (ESAPI) project.
*
* PHP version 5.2
*
* LICENSE: This source file is subject to the New BSD license. You should read
* and accept the LICENSE before you use, modify, and/or redistribute this
* software.
*
* @category OWASP
* @package ESAPI
* @author Andrew van der Stock <vanderaj@owasp.org>
* @author Mike Boberski <boberski_michael@bah.com>
* @copyright 2009-2010 The OWASP Foundation
* @license http://www.opensource.org/licenses/bsd-license.php New BSD license
* @version SVN: $Id$
* @link http://www.owasp.org/index.php/ESAPI
*/
/**
* Use this ESAPI security control to assist with manipulating strings
* in other ESAPI security controls.
*
* The idea behind this interface is to define a set of helper
* functions related to manipulating strings.
*
* @category OWASP
* @package ESAPI
* @author Andrew van der Stock <vanderaj@owasp.org>
* @author Mike Boberski <boberski_michael@bah.com>
* @copyright 2009-2010 The OWASP Foundation
* @license http://www.opensource.org/licenses/bsd-license.php New BSD license
* @version Release: @package_version@
* @link http://www.owasp.org/index.php/ESAPI
*/
class StringUtilities
{
/**
* Removes all unprintable characters from a string
* and replaces with a space for use in an HTTP header
*
* @param string $input a string that may have unprintable characters
*
* @return string the stripped header
*/
public static function stripControls( $input )
{
if (empty($input)) {
return '';
}
$i = str_split($input);
$sb = '';
foreach ( $i as $c ) {
if ( $c > chr(32) && $c < chr(127) ) {
$sb .= $c;
} else {
$sb .= ' ';
}
}
return $sb;
}
/**
* Union two character arrays.
*
* @param string $c1 the first character array
* @param string $c2 the second character array
*
* @return array the union of the two character arrays
*/
public static function union($c1, $c2)
{
if (empty($c1) && empty($c2)) {
return null;
}
return sort(array_unique(array_merge($c1, $c2)));
}
/**
* Returns true if the character is contained in the provided StringBuffer.
*
* @param string $haystack the string to search
* @param string $c the character to search for in the string
*
* @return bool TRUE, if the character is found, false otherwise
*/
public static function contains($haystack, $c)
{
if ( empty($haystack) || empty($c) ) {
return false;
}
return ( strpos($haystack, $c) !== false ) ? true : false;
}
}