Skip to content

Commit

Permalink
Feat: Label update
Browse files Browse the repository at this point in the history
Update the function "toValidLabel" of file "com.cburch.logisim.circuit.Analyze.java"

Now when do analyze of circuit the pin that contain also only number, don't invert character and number, don't remove space.

Merge commit 98f7718 from pull request Logisim-Ita#37 Matt345Fire/Logisim-Locale
  • Loading branch information
Matt345Fire authored and LucaCaruso-dev committed Nov 20, 2024
1 parent c5a500e commit 926d2a0
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions Logisim-Fork/src/main/java/com/cburch/logisim/circuit/Analyze.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.regex.Pattern;

import com.cburch.logisim.analyze.model.AnalyzerModel;
import com.cburch.logisim.analyze.model.Entry;
Expand All @@ -21,6 +22,7 @@
import com.cburch.logisim.instance.StdAttr;
import com.cburch.logisim.proj.Project;
import com.cburch.logisim.std.wiring.Pin;
import com.cburch.logisim.util.StringUtil;

public class Analyze {

Expand Down Expand Up @@ -298,43 +300,21 @@ public int compare(Instance ac, Instance bc) {
* throw new AnalyzeException.Conflict(); } } expressionMap.put(p2, e); } } } }
*/

// This function check label name
private static String toValidLabel(String label) {
if (label == null)
return null;
StringBuilder end = null;
StringBuilder ret = new StringBuilder();
boolean afterWhitespace = false;
for (int i = 0; i < label.length(); i++) {
StringBuilder buildLabel = new StringBuilder(); //StringBuilder for hold string in building
for(int i = 0; i < label.length(); i++) {
char c = label.charAt(i);
if (Character.isJavaIdentifierStart(c)) {
if (afterWhitespace) {
// capitalize words after the first one
c = Character.toTitleCase(c);
afterWhitespace = false;
}
ret.append(c);
} else if (Character.isJavaIdentifierPart(c)) {
// If we can't place it at the start, we'll dump it
// onto the end.
if (ret.length() > 0) {
ret.append(c);
} else {
if (end == null)
end = new StringBuilder();
end.append(c);
}
afterWhitespace = false;
} else if (Character.isWhitespace(c)) {
afterWhitespace = true;
} else {
; // just ignore any other characters
int unicode = label.codePointAt(i); // Get character unicode
if((unicode < 8192 || unicode > 8207) && (unicode < 8234 || unicode > 8239) && (unicode < 8298 || unicode > 8303)) { // Check that it is not a prohibited Unicode
buildLabel.append(c); // Add character on final string
}
}
if (end != null && ret.length() > 0)
ret.append(end.toString());
if (ret.length() == 0)
String newLabel = buildLabel.toString().trim();
if(newLabel.length() > 0) // If is find a character or number
return newLabel; // Return a final string
else
return null;
return ret.toString();
}

private Analyze() {
Expand Down

0 comments on commit 926d2a0

Please sign in to comment.