Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrote squeeze to avoid commons-lang dependency #1992

Merged
merged 8 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,6 @@
<artifactId>commons-math</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency> <!-- used by the compression uri feature-->
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
Expand Down
7 changes: 0 additions & 7 deletions src/org/rascalmpl/library/Prelude.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import java.util.function.Consumer;
import java.util.regex.Pattern;

import org.apache.commons.lang.CharSetUtils;
import org.rascalmpl.debug.IRascalMonitor;
import org.rascalmpl.exceptions.JavaCompilation;
import org.rascalmpl.exceptions.RuntimeExceptionFactory;
Expand Down Expand Up @@ -3041,12 +3040,6 @@ public IString trim(IString s) {
return values.string(s.getValue().trim());
}

public IString squeeze(IString src, IString charSet) {
//@{http://commons.apache.org/lang/api-2.6/index.html?org/apache/commons/lang/text/package-summary.html}
String s = CharSetUtils.squeeze(src.getValue(), charSet.getValue());
return values.string(s);
}

public IString capitalize(IString src) {
StringBuilder result = new StringBuilder(src.length());
boolean lastWhitespace= true;
Expand Down
10 changes: 8 additions & 2 deletions src/org/rascalmpl/library/String.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,14 @@ import String;
squeeze("hello", "el");
```
}
@javaClass{org.rascalmpl.library.Prelude}
public java str squeeze(str src, str charSet);
public str squeeze(str src, str charSet) {
if (charSet == "") {
return src;
}
return visit(src) {
case /<c:[<charSet>]><c>+/ => c
DavyLandman marked this conversation as resolved.
Show resolved Hide resolved
}
}



Expand Down
11 changes: 11 additions & 0 deletions src/org/rascalmpl/library/lang/rascal/tests/basic/Strings1.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module lang::rascal::tests::basic::Strings1
import String;
import List;
import util::Math;
import IO;

test bool subscription(str S){
R = "";
Expand Down Expand Up @@ -248,6 +249,16 @@ test bool tstSplit(str S1, str S2) = areOverlapping(S1,S2) || isEmpty(S1) || isE

// squeeze

test bool tstSqueeze1(str S) = /<c:[a-zA-Z]><c>/ !:= squeeze(S, "a-zA-Z");
test bool tstSqueeze2(str S) = squeeze(S, "") == S;
test bool tstSqueeze3(str S) {
if (/<c:[a-zA-Z]><c>/ := S) {
return /<c><c>/ := squeeze(S, "0-9");
}
return true;
}


test bool tstStartsWith(str S1, str S2) = startsWith(S1+S2, S1);

test bool tstSubstring1(str S){
Expand Down
Loading