This repository was archived by the owner on Jan 30, 2020. It is now read-only.
File tree 3 files changed +40
-5
lines changed
3 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -26,10 +26,18 @@ public function filter($value)
26
26
}
27
27
28
28
if (StringUtils::hasPcreUnicodeSupport ()) {
29
- $ pattern = ['#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})# ' , '#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})# ' ];
30
- $ replacement = [$ this ->separator . '\1 ' , $ this ->separator . '\1 ' ];
29
+ /**
30
+ * First: Match right after a lowercase letter or digit following a capital letter or
31
+ * before a capital letter with a lowercese letter on it's right.
32
+ *
33
+ * Second: Match right after a lowercase letter following zero or more digits
34
+ * or a capital letter
35
+ */
36
+ $ pattern = ['#(?<=\p{Ll}|\p{Nd})(?=\p{Lu})|(?<=\p{Lu})(?=\p{Lu}\p{Ll})# ' , '#(?<=(?:\p{Ll}))(\p{Lu}|(\p{Nd}+))# ' ];
37
+ $ replacement = [ $ this ->separator . '\1 ' , $ this ->separator . '\1 ' ,
38
+ ];
31
39
} else {
32
- $ pattern = ['#(?<=(?: [A-Z]))( [A-Z]+)( [A-Z][a-z])# ' , '#(?<=(?:[a-z0-9 ]))([A-Z])# ' ];
40
+ $ pattern = [ '#(?<=[a-z0-9])(?= [A-Z])|(?<= [A-Z])(?= [A-Z][a-z])# ' , '#(?<=(?:[a-z ]))([A-Z]|([0-9]+))# ' ];
33
41
$ replacement = ['\1 ' . $ this ->separator . '\2 ' , $ this ->separator . '\1 ' ];
34
42
}
35
43
Original file line number Diff line number Diff line change @@ -23,4 +23,31 @@ public function testFilterSeparatesCamelCasedWordsWithDashes()
23
23
$ this ->assertNotEquals ($ string , $ filtered );
24
24
$ this ->assertEquals ('Camel-Cased-Words ' , $ filtered );
25
25
}
26
+
27
+ /**
28
+ * @dataProvider camelizedStrings
29
+ */
30
+ public function testFilterSeparatesCamelCasedWordsContainingNumbersWithDashes ($ camel , $ dashed )
31
+ {
32
+ $ filter = new CamelCaseToDashFilter ();
33
+ $ filtered = $ filter ($ camel );
34
+ $ this ->assertNotEquals ($ camel , $ filtered );
35
+ $ this ->assertEquals ($ dashed , $ filtered );
36
+ }
37
+
38
+ /**
39
+ * Provides CamelizedStrings to test
40
+ *
41
+ * @return array
42
+ */
43
+ public function camelizedStrings ()
44
+ {
45
+ return [
46
+ [ 'CamelCasedWith2016Numbers ' , 'Camel-Cased-With-2016-Numbers ' ],
47
+ [ '10NumbersAsPrefix ' , '10-Numbers-As-Prefix ' ],
48
+ [ 'NumberSuffix42 ' , 'Number-Suffix-42 ' ],
49
+ [ 'lower50Upper ' , 'lower-50-Upper ' ],
50
+ [ 'dashed-2016Bar ' , 'dashed-2016-Bar ' ],
51
+ ];
52
+ }
26
53
}
Original file line number Diff line number Diff line change @@ -38,13 +38,13 @@ public function testFilterSeperatingNumbersToUnterscore()
38
38
$ filtered = $ filter ($ string );
39
39
40
40
$ this ->assertNotEquals ($ string , $ filtered );
41
- $ this ->assertEquals ('Pa2_Title ' , $ filtered );
41
+ $ this ->assertEquals ('Pa_2_Title ' , $ filtered );
42
42
43
43
$ string = 'Pa2aTitle ' ;
44
44
$ filter = new CamelCaseToUnderscoreFilter ();
45
45
$ filtered = $ filter ($ string );
46
46
47
47
$ this ->assertNotEquals ($ string , $ filtered );
48
- $ this ->assertEquals ('Pa2a_Title ' , $ filtered );
48
+ $ this ->assertEquals ('Pa_2a_Title ' , $ filtered );
49
49
}
50
50
}
You can’t perform that action at this time.
0 commit comments