mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 08:17:11 -07:00
Improved command line tokenizer
This commit is contained in:
parent
c59d61f8c1
commit
3bd17e224b
2 changed files with 8 additions and 16 deletions
|
@ -168,15 +168,10 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
|||
|
||||
char quote = 0;
|
||||
while (ch_ != -1) {
|
||||
if (Character.isWhitespace(ch_)) { // whitespaces
|
||||
if (quote == 0) {
|
||||
break;
|
||||
}
|
||||
buf_.append((char) ch_);
|
||||
} else if (ch_ == '\'' || ch_ == '"') { // quotes
|
||||
if (quote == 0) {
|
||||
if (ch_ == '\'' || ch_ == '"') { // quotes
|
||||
if (quote == 0) { // begin quote
|
||||
quote = (char) ch_;
|
||||
} else if (quote == ch_) {
|
||||
} else if (quote == ch_) { // end quote
|
||||
quote = 0;
|
||||
} else {
|
||||
buf_.append((char) ch_);
|
||||
|
@ -184,21 +179,19 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
|||
} else if (ch_ == '\\') { // escaped
|
||||
ch_ = input_.read();
|
||||
buf_.append(handleEscapeSequence());
|
||||
} else if (quote == 0 && Character.isWhitespace(ch_)) { // whitespaces
|
||||
break;
|
||||
} else {
|
||||
buf_.append((char) ch_);
|
||||
}
|
||||
|
||||
ch_ = input_.read();
|
||||
}
|
||||
return buf_.toString();
|
||||
}
|
||||
|
||||
private char handleEscapeSequence() {
|
||||
if (ch_ == -1) {
|
||||
return '\\';
|
||||
}
|
||||
|
||||
return switch (ch_) {
|
||||
case -1 -> '\\';
|
||||
case 'n' -> '\n';
|
||||
case 'r' -> '\r';
|
||||
case 't' -> '\t';
|
||||
|
@ -207,7 +200,6 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
private void trimWhitespaceOrComments() throws IOException {
|
||||
while (ch_ != -1) {
|
||||
if (Character.isWhitespace(ch_)) { // Skip whitespaces
|
||||
|
@ -218,7 +210,7 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
|||
ch_ = input_.read();
|
||||
} while (ch_ != -1 && ch_ != '\n' && ch_ != '\r');
|
||||
} else {
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class TestJlinkOperation {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testCmdFilesMulti() {
|
||||
void testCmdFilesVersion() {
|
||||
System.setOut(new PrintStream(outputStreamCaptor));
|
||||
var jlink = new JlinkOperation().cmdFiles("src/test/resources/jlink/options_verbose.txt",
|
||||
"src/test/resources/jlink/options_version.txt");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue