Skip to content

Commit

Permalink
bugfix for variables starting with a special char
Browse files Browse the repository at this point in the history
  • Loading branch information
wagner-netnexus committed Mar 2, 2020
1 parent 9bc5923 commit c58372f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/de/netnexus/CamelCasePlugin/Conversion.java
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Conversion {

@@ -24,11 +26,19 @@ static String transform(String text,
boolean useCamelCase,
boolean useLowerSnakeCase,
String[] conversionList) {
String newText;
String newText, appendText = "";
boolean repeat;
int iterations = 0;
String next = null;

Pattern p = Pattern.compile("^\\W+");
Matcher m = p.matcher(text);
if (m.find()) {
appendText = m.group(0);
}
//remove all special chars
text = text.replaceAll("^\\W+", "");

do {
newText = text;
boolean isLowerCase = text.equals(text.toLowerCase());
@@ -131,13 +141,13 @@ static String transform(String text,
text = newText;
} while (repeat);

return newText;
return appendText + newText;
}

/**
* Return next conversion (or wrap to first)
*
* @param conversion String
* @param conversion String
* @param conversions Array of strings
* @return next conversion
*/
@@ -150,6 +160,7 @@ private static String getNext(String conversion, String[] conversions) {
return conversions[0];
}
}

/**
* Convert a string (CamelCase) to snake_case
*

0 comments on commit c58372f

Please sign in to comment.