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 @@ -27,4 +27,31 @@ public function testFilterSeparatesCamelCasedWordsWithDashes()
27
27
$ this ->assertNotEquals ($ string , $ filtered );
28
28
$ this ->assertEquals ('Camel-Cased-Words ' , $ filtered );
29
29
}
30
+
31
+ /**
32
+ * @dataProvider camelizedStrings
33
+ */
34
+ public function testFilterSeparatesCamelCasedWordsContainingNumbersWithDashes ($ camel , $ dashed )
35
+ {
36
+ $ filter = new CamelCaseToDashFilter ();
37
+ $ filtered = $ filter ($ camel );
38
+ $ this ->assertNotEquals ($ camel , $ filtered );
39
+ $ this ->assertEquals ($ dashed , $ filtered );
40
+ }
41
+
42
+ /**
43
+ * Provides CamelizedStrings to test
44
+ *
45
+ * @return array
46
+ */
47
+ public function camelizedStrings ()
48
+ {
49
+ return [
50
+ [ 'CamelCasedWith2016Numbers ' , 'Camel-Cased-With-2016-Numbers ' ],
51
+ [ '10NumbersAsPrefix ' , '10-Numbers-As-Prefix ' ],
52
+ [ 'NumberSuffix42 ' , 'Number-Suffix-42 ' ],
53
+ [ 'lower50Upper ' , 'lower-50-Upper ' ],
54
+ [ 'dashed-2016Bar ' , 'dashed-2016-Bar ' ],
55
+ ];
56
+ }
30
57
}
Original file line number Diff line number Diff line change @@ -42,13 +42,13 @@ public function testFilterSeperatingNumbersToUnterscore()
42
42
$ filtered = $ filter ($ string );
43
43
44
44
$ this ->assertNotEquals ($ string , $ filtered );
45
- $ this ->assertEquals ('Pa2_Title ' , $ filtered );
45
+ $ this ->assertEquals ('Pa_2_Title ' , $ filtered );
46
46
47
47
$ string = 'Pa2aTitle ' ;
48
48
$ filter = new CamelCaseToUnderscoreFilter ();
49
49
$ filtered = $ filter ($ string );
50
50
51
51
$ this ->assertNotEquals ($ string , $ filtered );
52
- $ this ->assertEquals ('Pa2a_Title ' , $ filtered );
52
+ $ this ->assertEquals ('Pa_2a_Title ' , $ filtered );
53
53
}
54
54
}
You can’t perform that action at this time.
0 commit comments