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;
|
char quote = 0;
|
||||||
while (ch_ != -1) {
|
while (ch_ != -1) {
|
||||||
if (Character.isWhitespace(ch_)) { // whitespaces
|
if (ch_ == '\'' || ch_ == '"') { // quotes
|
||||||
if (quote == 0) {
|
if (quote == 0) { // begin quote
|
||||||
break;
|
|
||||||
}
|
|
||||||
buf_.append((char) ch_);
|
|
||||||
} else if (ch_ == '\'' || ch_ == '"') { // quotes
|
|
||||||
if (quote == 0) {
|
|
||||||
quote = (char) ch_;
|
quote = (char) ch_;
|
||||||
} else if (quote == ch_) {
|
} else if (quote == ch_) { // end quote
|
||||||
quote = 0;
|
quote = 0;
|
||||||
} else {
|
} else {
|
||||||
buf_.append((char) ch_);
|
buf_.append((char) ch_);
|
||||||
|
@ -184,21 +179,19 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
||||||
} else if (ch_ == '\\') { // escaped
|
} else if (ch_ == '\\') { // escaped
|
||||||
ch_ = input_.read();
|
ch_ = input_.read();
|
||||||
buf_.append(handleEscapeSequence());
|
buf_.append(handleEscapeSequence());
|
||||||
|
} else if (quote == 0 && Character.isWhitespace(ch_)) { // whitespaces
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
buf_.append((char) ch_);
|
buf_.append((char) ch_);
|
||||||
}
|
}
|
||||||
|
|
||||||
ch_ = input_.read();
|
ch_ = input_.read();
|
||||||
}
|
}
|
||||||
return buf_.toString();
|
return buf_.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private char handleEscapeSequence() {
|
private char handleEscapeSequence() {
|
||||||
if (ch_ == -1) {
|
|
||||||
return '\\';
|
|
||||||
}
|
|
||||||
|
|
||||||
return switch (ch_) {
|
return switch (ch_) {
|
||||||
|
case -1 -> '\\';
|
||||||
case 'n' -> '\n';
|
case 'n' -> '\n';
|
||||||
case 'r' -> '\r';
|
case 'r' -> '\r';
|
||||||
case 't' -> '\t';
|
case 't' -> '\t';
|
||||||
|
@ -207,7 +200,6 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void trimWhitespaceOrComments() throws IOException {
|
private void trimWhitespaceOrComments() throws IOException {
|
||||||
while (ch_ != -1) {
|
while (ch_ != -1) {
|
||||||
if (Character.isWhitespace(ch_)) { // Skip whitespaces
|
if (Character.isWhitespace(ch_)) { // Skip whitespaces
|
||||||
|
@ -218,7 +210,7 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
||||||
ch_ = input_.read();
|
ch_ = input_.read();
|
||||||
} while (ch_ != -1 && ch_ != '\n' && ch_ != '\r');
|
} while (ch_ != -1 && ch_ != '\n' && ch_ != '\r');
|
||||||
} else {
|
} else {
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class TestJlinkOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCmdFilesMulti() {
|
void testCmdFilesVersion() {
|
||||||
System.setOut(new PrintStream(outputStreamCaptor));
|
System.setOut(new PrintStream(outputStreamCaptor));
|
||||||
var jlink = new JlinkOperation().cmdFiles("src/test/resources/jlink/options_verbose.txt",
|
var jlink = new JlinkOperation().cmdFiles("src/test/resources/jlink/options_verbose.txt",
|
||||||
"src/test/resources/jlink/options_version.txt");
|
"src/test/resources/jlink/options_version.txt");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue