Skip to content

Commit e15f842

Browse files
committed
[#263]_update code fix missing first letter
1 parent 39f6586 commit e15f842

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/com/magento/idea/magento2plugin/util/CamelCaseToHyphen.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,40 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.util;
67

8+
import java.util.regex.Matcher;
9+
import java.util.regex.Pattern;
10+
711
public class CamelCaseToHyphen {
812
private static CamelCaseToHyphen INSTANCE = null;
13+
14+
/**
15+
* getInstance.
16+
* @return CamelCaseToHyphen
17+
*/
918
public static CamelCaseToHyphen getInstance() {
10-
if (null == INSTANCE) INSTANCE = new CamelCaseToHyphen();
19+
if (null == INSTANCE) {
20+
INSTANCE = new CamelCaseToHyphen();
21+
}
1122
return INSTANCE;
1223
}
1324

25+
/**
26+
* convert.
27+
* @param string the origin string.
28+
* @return string
29+
*/
1430
public String convert(String string) {
15-
return string.toLowerCase();
31+
String regex = "(?=[A-Z][a-z])";
32+
String subst = "-";
33+
Pattern pattern = Pattern.compile(regex);
34+
Matcher matcher = pattern.matcher(string);
35+
String result = matcher.replaceAll(subst).toLowerCase();
36+
if (result.charAt(0) == '-') {
37+
return result.substring(1);
38+
}
39+
return result;
1640
}
1741
}

0 commit comments

Comments
 (0)