forked from wyndow/fuzzywuzzy
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtils.php
More file actions
62 lines (54 loc) · 1.58 KB
/
Copy pathUtils.php
File metadata and controls
62 lines (54 loc) · 1.58 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
<?php
namespace k\util\fuzzy;
/**
* Utility methods for FuzzyWuzzy.
*
* @author Michael Crumm <mike@crumm.net>
*/
class Utils
{
/**
* Returns a correctly rounded integer.
*
* @param float $num Numeric value to round.
* @return int
*/
public static function intr($num)
{
return (int) round($num, 10, PHP_ROUND_HALF_DOWN);
}
/**
* Returns a string after processing.
*
* - Replaces an non-alphanumeric characters with whitespace.
* - Converts the string to lowercase.
* - Trims leading/trailing whitespace from the string.
*
* @param string $str String to process.
* @param boolean $forceAscii If true, string will be converted to ASCII before processing.
* @return string
*/
public static function fullProcess($str, $forceAscii = true)
{
if (empty ($str)) { return ''; }
# TODO: Force ascii, if true
# Keep only Letters and Numbers (see Unicode docs).
$stringOut = StringProcessor::nonAlnumToWhitespace($str);
# Force into lowercase.
$stringOut = StringProcessor::downcase($stringOut);
# Remove leading and trailing whitespaces.
$stringOut = StringProcessor::strip($stringOut);
return $stringOut;
}
/**
* Validates that a string is a string, and that it has a positive length.
*
* @param string $str String to validate.
* @return boolean
*/
public static function validateString($str)
{
if (!is_string($str)) { return false; }
return mb_strlen($str) > 0;
}
}