Skip to content

Commit

Permalink
Added a text area which displays the most recent comment found in the…
Browse files Browse the repository at this point in the history
… gcode.
  • Loading branch information
winder committed Dec 11, 2012
1 parent 6cea9a2 commit 38e66fb
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 173 deletions.
21 changes: 20 additions & 1 deletion src/com/willwinder/universalgcodesender/CommUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static String overrideSpeed(String command, Integer speed) {
/**
* Removes any comments within parentheses or beginning with a semi-colon.
*/
static String removeComments(String command) {
static String removeComment(String command) {
String newCommand = command;

// Remove any comments within ( parentheses ) with regex "\([^\(]*\)"
Expand All @@ -175,4 +175,23 @@ static String removeComments(String command) {

return newCommand;
}

/**
* Searches for a comment in the input string and returns the first match.
*/
static String parseComment(String command) {
String comment = "";

// REGEX: Find any comment, includes the comment characters:
// "(?<=\()[^\(\)]*|(?<=\;)[^;]*"
// "(?<=\\()[^\\(\\)]*|(?<=\\;)[^;]*"

Pattern pattern = Pattern.compile("(?<=\\()[^\\(\\)]*|(?<=\\;)[^;]*");
Matcher matcher = pattern.matcher(command);
if (matcher.find()){
comment = matcher.group(0);
}

return comment;
}
}
Loading

0 comments on commit 38e66fb

Please sign in to comment.