-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added experimental skip pattern generator
- Loading branch information
Showing
4 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
modules/spin-tools/src-tests/com/maccasoft/propeller/internal/UtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2021-24 Marco Maccaferri and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Marco Maccaferri - initial API and implementation | ||
*/ | ||
|
||
package com.maccasoft.propeller.internal; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class UtilsTest { | ||
|
||
@Test | ||
void testSimplePattern() { | ||
String subject = "" + | ||
"a\n" + | ||
"a\n" + | ||
"|\n" + | ||
"a\n" + | ||
" \n" + | ||
"|\n" + | ||
"a\n" + | ||
""; | ||
Assertions.assertEquals("%01_0100", Utils.makeSkipPattern(subject)); | ||
} | ||
|
||
@Test | ||
void testSkipMultipleSpaces() { | ||
String subject = "" + | ||
"a\n" + | ||
"a\n" + | ||
"|\n" + | ||
"a\n" + | ||
" \n" + | ||
" \n" + | ||
" \n" + | ||
"|\n" + | ||
"a\n" + | ||
""; | ||
Assertions.assertEquals("%01_0100", Utils.makeSkipPattern(subject)); | ||
} | ||
|
||
@Test | ||
void testSkipLeadingAndTrailingSpaces() { | ||
String subject = "" + | ||
" \n" + | ||
" \n" + | ||
"a\n" + | ||
"a\n" + | ||
"|\n" + | ||
"a\n" + | ||
" \n" + | ||
"|\n" + | ||
"a\n" + | ||
" \n" + | ||
" \n" + | ||
""; | ||
Assertions.assertEquals("%01_0100", Utils.makeSkipPattern(subject)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
modules/spin-tools/src/com/maccasoft/propeller/internal/Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2021-24 Marco Maccaferri and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Marco Maccaferri - initial API and implementation | ||
*/ | ||
|
||
package com.maccasoft.propeller.internal; | ||
|
||
public class Utils { | ||
|
||
public static String makeSkipPattern(String text) { | ||
StringBuilder pattern = new StringBuilder(); | ||
|
||
String[] s = text.split(FileUtils.EOL_PATTERN); | ||
|
||
char target = 0; | ||
for (int i = 0; i < s.length; i++) { | ||
if (s[i].length() < 1) { | ||
if (pattern.length() == 0 || pattern.charAt(0) != '_') { | ||
pattern.insert(0, '_'); | ||
} | ||
continue; | ||
} | ||
char ch = s[i].charAt(0); | ||
if (ch == '-' || ch == '_') { | ||
pattern.insert(0, ch); | ||
} | ||
else if (ch == '|') { | ||
pattern.insert(0, '1'); | ||
} | ||
else { | ||
if (target == 0) { | ||
if (ch == ' ') { | ||
continue; | ||
} | ||
target = ch; | ||
} | ||
if (ch == target) { | ||
pattern.insert(0, '0'); | ||
} | ||
else { | ||
if (pattern.length() == 0 || pattern.charAt(0) != '_') { | ||
pattern.insert(0, '_'); | ||
} | ||
} | ||
} | ||
} | ||
|
||
while (pattern.length() >= 1 && pattern.charAt(0) == '_') { | ||
pattern.deleteCharAt(0); | ||
} | ||
|
||
if (pattern.length() > 0) { | ||
pattern.insert(0, '%'); | ||
} | ||
|
||
return pattern.toString(); | ||
} | ||
|
||
} |