Skip to content

Commit a84ea60

Browse files
committed
fix regular expression for trans and transchoice to support more cases Haehnchen#377; also fix some whitespace issues
1 parent fc107e1 commit a84ea60

File tree

1 file changed

+6
-6
lines changed
  • src/fr/adrienbrault/idea/symfony2plugin/templating/util

1 file changed

+6
-6
lines changed

src/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,30 +180,30 @@ public static String getDomainTrans(PsiElement psiElement) {
180180
// search in twig project for regex
181181
// check for better solution; think of nesting
182182

183-
String domainName = null;
184-
185183
PsiElement parentPsiElement = psiElement.getParent();
186184
if(parentPsiElement == null) {
187-
return domainName;
185+
return null;
188186
}
189187

190188
String str = parentPsiElement.getText();
191189

192-
String regex = "\\|\\s?trans\\s?\\(\\{.*?\\},\\s?['\"](\\w+)['\"]\\s?\\)";
190+
// @TODO: in another life dont use regular expression to find twig parameter :)
191+
192+
String regex = "\\|\\s*trans\\s*\\(\\s*\\{.*?\\}\\s*,\\s*['\"]([\\w-]+)['\"]\\s*\\)";
193193
Matcher matcher = Pattern.compile(regex).matcher(str.replace("\r\n", " ").replace("\n", " "));
194194

195195
if (matcher.find()) {
196196
return matcher.group(1);
197197
}
198198

199-
regex = "\\|\\s?transchoice\\s?\\(\\d+\\s?,\\s?\\{.*?\\},\\s?['\"](\\w+)['\"]\\s?\\)";
199+
regex = "\\|\\s*transchoice\\s*\\(\\s*\\d+\\s*,\\s*\\{.*?\\}\\s*,\\s*['\"]([\\w-]+)['\"]\\s*\\)";
200200
matcher = Pattern.compile(regex).matcher(str.replace("\r\n", " ").replace("\n", " "));
201201

202202
if (matcher.find()) {
203203
return matcher.group(1);
204204
}
205205

206-
return domainName;
206+
return null;
207207
}
208208

209209
public static ArrayList<TwigMacro> getImportedMacros(PsiFile psiFile) {

0 commit comments

Comments
 (0)